import requests import utm from geopy.geocoders import Nominatim import time import json import pandas as pd 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 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') amrofilepath = 'amro.xls' workbook_amrofarms = xlrd.open_workbook(amrofilepath) sheet_amrofarms = workbook_amrofarms.sheet_by_index(0) mur_fields = db.reference('PaidPolygonsByPolygonID').child('PMF').child('snQYQZqQx3SmVbRztmEqYn5Mkcz2').get() def try_lower(temp_str): try: temp_str = temp_str.lower() except: wew = 1 return temp_str amro_obj = {} for i in range(1,sheet_amrofarms.nrows): farmer_code = sheet_amrofarms.cell_value(i,4) farmer_code = try_lower(farmer_code) farmer_crop = sheet_amrofarms.cell(i,16) farmer_crop = try_lower(farmer_crop) try: amro_obj[farmer_code] = farmer_crop except: aws = 1 for (polygonID, polygonObj) in mur_fields.items(): try: polyInfoObj = polygonObj["FarmerInfoData"] try: plant = amro_obj[polyInfoObj["FarmerCode"]] plant = str(plant) plant = plant.replace("text:","") except: plant = '-' polyInfoObj["Crop"] = plant polygonObj["FarmerInfoData"] = polyInfoObj fieldid = polygonObj["fieldID"] db.reference('PaidPolygonsByPolygonID').child('PMF').child('snQYQZqQx3SmVbRztmEqYn5Mkcz2').child(polygonID).child('crop').set(plant) db.reference('PaidMonitoredFields').child('PMF').child('snQYQZqQx3SmVbRztmEqYn5Mkcz2').child(fieldid).child('Polygons').child(polygonID).child('crop').set(plant) print(str((fieldid) + ', ' + str(polygonID))) # #print(polygonObj) # r = requests.post('https://us-central1-farmbase-b2f7e.cloudfunctions.net/submitAdminPolygon2022', json = polygonObj) # #print(r) time.sleep(0.25) #break except Exception as e: print(e)