from xxlimited import new import fiona import requests import utm from geopy.geocoders import Nominatim import time import json import pandas as pd from fastkml import kml import xlrd from statistics import median import math import firebase_admin from firebase_admin import credentials from firebase_admin import db from firebase_admin import messaging import threading import xlsxwriter import os from numba import jit, cuda cred = credentials.Certificate('servicekey.json') try: firebase_admin.initialize_app(cred, {'databaseURL': 'https://farmbase-b2f7e-31c0c.firebaseio.com/'}) except: print('fire running') kmlfarms = 'farms.xlsx' amrofilepath = 'amro.xlsx' def try_lower(temp_str): try: temp_str = temp_str.lower() except: wew = 1 return temp_str workbook_kmlfarms = xlrd.open_workbook(kmlfarms) sheet_kmlfarms = workbook_kmlfarms.sheet_by_index(0) workbook_amrofarms = xlrd.open_workbook(amrofilepath) sheet_amrofarms = workbook_amrofarms.sheet_by_index(0) amro_obj = {} plot_num =0 err_num = 0 uid = 'snQYQZqQx3SmVbRztmEqYn5Mkcz2' mur_fields = db.reference('PaidMonitoredFields').child('PMF').child(uid).get() for i in range(1,sheet_amrofarms.nrows): farmer_code = sheet_amrofarms.cell_value(i,4) farmer_declared_area = sheet_amrofarms.cell_value(i,23) farmer_variety = sheet_amrofarms.cell_value(i,17) farmer_variety = try_lower(farmer_variety) farmer_code = try_lower(farmer_code) tempObj = {} tempObj["Area"] = farmer_declared_area tempObj["Variety"] = farmer_variety amro_obj[farmer_code] = tempObj for (field, fieldobj) in mur_fields.items(): try: allPolygonsObj = fieldobj["Polygons"] for (polygonid, polygonobj) in allPolygonsObj.items(): try: farmerInfoDataObj = polygonobj["FarmerInfoData"] try: farmer_code = farmerInfoDataObj["farmerCode"] farmerInfoDataObj["variety"] = amro_obj[farmer_code]["Variety"] farmerInfoDataObj["declaredArea"] = amro_obj[farmer_code]["Area"] print(farmerInfoDataObj) except Exception as e: print(e) except Exception as e: try: farmer_code = polygonobj["farmerCode"] farmerInfoDataObj["variety"] = amro_obj[farmer_code]["Variety"] farmerInfoDataObj["declaredArea"] = amro_obj[farmer_code]["Area"] print(farmerInfoDataObj) except Exception as e: print(e) except Exception as e: awa = 1