import fiona import requests import utm from geopy.geocoders import Nominatim import time import json import firebase_admin from firebase_admin import credentials from firebase_admin import firestore import threading import os filepath = 'Downloads/mapping file.json' mainObj = {} polygonNum = 0 rr = 1 cred = credentials.Certificate('servicekey.json') try: firebase_admin.initialize_app(cred, {'databaseURL': 'https://farmbase-b2f7e-31c0c.firebaseio.com/'}) except: print('fire running') db = firestore.client() with open(filepath) as f: data = json.load(f) allFarmersObj = data["35000 active data"] for farmerObj in allFarmersObj: try: #print(farmerObj) #print('yyyyeyeye') farmerCode = farmerObj["FarmerCode"] farmerName = farmerObj["FarmerName"] farmerCrop = farmerObj["Crop"] farmerZone = farmerObj["Zone"] farmerAMRO = farmerObj["AMRO"] farmerStore = farmerObj["Store"] farmerCropVariety = farmerObj["Variety"] farmerArea = farmerObj["Area"] farmerMobile = farmerObj["Mobile"] farmerPointsObj = farmerObj["Coordinate"] try: farmerCode = farmerCode.lower() except: farmerCode = "" try: farmerName = farmerName.lower() except: farmerName = "" try: farmerCrop = farmerCrop.lower() except: farmerCrop = "" try: farmerZone = farmerZone.lower() except: farmerZone = "" try: farmerAMRO = farmerAMRO.lower() except: farmerAMRO = "" try: farmerStore = farmerStore.lower() except: farmerStore = "" try: farmerCropVariety = farmerCropVariety.lower() except: farmerCropVariety = "" farmerArea = float(farmerArea)*4000 tempObj = {} tempObj["Area"] = farmerArea tempObj["farmerCode"] = farmerCode tempObj["Name"] = farmerName tempObj["cropToBeGrown"] = farmerCrop tempObj["zone"] = farmerZone tempObj["amro"] = farmerAMRO tempObj["store"] = farmerStore tempObj["cropVariety"] = farmerCropVariety tempObj["Area"] = farmerArea tempObj["PhoneNumber"] = farmerMobile pointNum = 0 allPointsObj = {} allowed = 1 farmerPointsObj = farmerPointsObj.split(",") #print(farmerPointsObj) lats = [] lngs = [] for k in farmerPointsObj: singlePointobj = k singlePointobj = singlePointobj.split(" ") print(singlePointobj) #print(singlePointobj) try: singlePointLat = float(singlePointobj[0]) singlePointLong = float(singlePointobj[1]) lats.append(singlePointLat) lngs.append(singlePointLong) tempPoint = {} tempPoint["Latitude"] = singlePointLat tempPoint["Longitude"] = singlePointLong allPointsObj[("P_"+str(pointNum))] = tempPoint pointNum = pointNum+1 except: aqqa = 1 tempObj["Coordinates"] = allPointsObj tempObj["UID"] = "snQYQZqQx3SmVbRztmEqYn5Mkcz2" polygonNum = polygonNum + 1 print(tempObj) if (max(lats) - min(lats) < 0.02) and (max(lngs)-min(lngs)<0.02): r = requests.post('https://us-central1-farmbase-b2f7e.cloudfunctions.net/findHNIVillage', json = tempObj) time.sleep(2) except: wqwq = 1