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 traceback 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 numpy as np import datetime import os from numba import jit, cuda from firebase_admin import firestore from make_on_the_go_farm_image import make_on_the_go_farm_image from sentinelhub import WebFeatureService, BBox, CRS, DataSource, MimeType, CRS, BBox, WmsRequest,DataCollection from get_polygon_mask import get_polygon_mask import traceback from google.cloud import storage import os from google.oauth2 import service_account import datetime from datetime import date import csv storage_client = storage.Client.from_service_account_json("servicekey.json"); bucket_name = 'farmbase-b2f7e.appspot.com' cred = service_account.Credentials.from_service_account_file('servicekey.json') #cred = credentials.Certificate('servicekey.json') bucket = storage_client.bucket(bucket_name) try: firebase_admin.initialize_app(credentials.Certificate('servicekey.json'), {'databaseURL': 'https://farmbase-b2f7e-31c0c.firebaseio.com/'}) except: print('fire running') akhiyanafarms = 'Downloads/malkaram.xls' akhiyana_geojson = 'Downloads/Malkaram2.geojson' workbook_kmlfarms = xlrd.open_workbook(akhiyanafarms) sheet_kmlfarms = workbook_kmlfarms.sheet_by_index(0) uid = "uCFaFUhHGfNLRpJ4WsAgnUFo4RV2" arr = [] uids = ['BIGvoYtMsvYxNG3P8bUtZstRIW62','YkJIYa63SLhOZdmo4hRKZ17z4lq2','Jh71NGn1A4VSu3WOYwXhRiia0Cu1','AvlbNpsuI7P1sva1NWMBUN4Fmbg1','fLwCtzdi7GRqrV12bI1ULGGcwDo2'] for uid in uids: fields = db.reference('PaidMonitoredFields').child('PMF').child(uid).get() for(fieldid, fieldobj) in fields.items(): fieldi = str(fieldid) db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Paused').set('yes') time.sleep(0.5) # field_address = fieldobj["FieldAddress"] # area_sqm = fieldobj["FieldArea"] # area_ac = round(0.000247105*area_sqm,2) # area_ha = round(area_sqm/10000, 2) # arr.append([('https://farmonaut.com/web-app?UID='+uid + '&FieldID='+fieldid),fieldid, field_address, area_sqm, area_ac, area_ha]) # print(arr) # with open('tsoilfed.csv', 'w') as f: # # using csv.writer method from CSV package # print('starting') # write = csv.writer(f) # write.writerow(['See Farm on Map','Field ID', 'Village Name - Survey No.', 'Area (sq. m.)', 'Area (Acres)', 'Area (Hectares)']) # write.writerows(arr) # print('done') # #np.savetxt("tsoilfed_new.csv", arr, delimiter = ",") # time.sleep(100000) # with open(akhiyana_geojson) as f: # akhiyana_json = json.load(f) # akhiyana_farms = akhiyana_json["features"] # survey_obj = {} # for i in akhiyana_farms: # single_farm = i # single_farm_points = single_farm["geometry"]["coordinates"] # single_farm_survey_no = single_farm["properties"]["Khasra_No"] # try: # single_farm_survey_no = single_farm_survey_no # survey_obj[single_farm_survey_no] = i # except: # print(single_farm_survey_no) # print(traceback.format_exc()) # total_area =0 # num = 0 # for (survey_no,single_farm) in survey_obj.items(): # single_farm_points = single_farm["geometry"]["coordinates"] # main_obj = single_farm # try: # farm_area = single_farm["properties"]["Area_Ac"] # farm_area = int(float(farm_area)*4047) # except: # print(traceback.format_exc()) # try: # #main_obj = survey_obj[survey_no] # total_area = total_area + farm_area # num = num + 1 # #print(main_obj) # polygonPoints = main_obj["geometry"]["coordinates"] # lats, lngs = [],[] # allPointsObj = {} # tempObj = {} # pointNum = 0 # for aa in polygonPoints: # aa = aa[0] # print(aa) # for k in aa: # singlePointobj = k # #print(singlePointobj) # singlePointLat = singlePointobj[1] # singlePointLong = singlePointobj[0] # if (singlePointLat in lats) and (singlePointLong in lngs): # trwr = 1 # else: # lats.append(singlePointLat) # lngs.append(singlePointLong) # #utmToLatLon = utm.to_latlon(singlePointLong, singlePointLat, 44, 'N') # utmToLatLon = [singlePointLat, singlePointLong] # tempPoint = {} # tempPoint["Latitude"] = utmToLatLon[0] # tempPoint["Longitude"] = utmToLatLon[1] # if pointNum > 0: # allPointsObj[("P_"+str(pointNum))] = tempPoint # else: # allPointsObj["a"] = tempPoint # temp_field_address = "Malkaram - Survey No: " + str(survey_no) # tempObj["FullAddress"] = temp_field_address # tempObj["FieldAddress"] = temp_field_address # pointNum = pointNum+1 # tempObj["Points"] = allPointsObj # tempObj["UID"] = uid # tempObj["PaymentType"] = 1 # tempObj["CropCode"] = 999 # tempObj["Village"] = temp_field_address # tempObj["City"] = temp_field_address # tempObj["Area"] = farm_area # print(tempObj) # #r = requests.post('https://us-central1-farmbase-b2f7e.cloudfunctions.net/submitFieldTemp2', json = tempObj) # time.sleep(1) # except Exception as e: # print(e) # print((total_area/10000)) # print(num)