from tempfile import tempdir import firebase_admin from firebase_admin import credentials from firebase_admin import db from find_s1_image2 import find_img_value import pandas as pd import statsmodels.api as sm import seaborn as sns sns.set() import time import json import numpy as np from sklearn.cluster import KMeans from find_study_area_values import find_study_area_values from make_area_estimate_image import make_area_estimate_image import json cred = credentials.Certificate('servicekey.json') import firebase_admin from firebase_admin import credentials from firebase_admin import firestore import requests try: firebase_admin.initialize_app(cred, {'databaseURL': 'https://farmbase-b2f7e-31c0c.firebaseio.com/'}) except: print('fire running') gt_fields_dir = 'mahindra.json' # { # "UID" : "6nZRDEmdq7ajeZLJB2K19RhzVPu1", # "FieldID" : [1685601405014], # "FromDate":"20230601", # "ToDate":"20230815" # } fields_obj = db.reference("PaidMonitoredFields").child("PMF").child("6nZRDEmdq7ajeZLJB2K19RhzVPu1").get(False, True) for (field_id, temp) in fields_obj.items(): main_obj = {} main_obj["UID"] = "6nZRDEmdq7ajeZLJB2K19RhzVPu1" main_obj["FieldID"] = [int(field_id)] main_obj["FromDate"] = "20230601" main_obj["ToDate"] = "20230815" print(main_obj) API_ENDPOINT = 'https://us-central1-farmbase-b2f7e.cloudfunctions.net/requestBulkHistoricalSatelliteData' r = requests.post(url=API_ENDPOINT, json=main_obj) time.sleep(2) # with open(gt_fields_dir) as f: # gt_fields = json.load(f) # for single_farm in gt_fields: # try: # farm_id = single_farm["id"] # farm_village = single_farm["village"] # farm_name = str(farm_village) + "_" + str(farm_id) # farm_geolocation = single_farm["geo_location"] # farm_points = json.loads(farm_geolocation) # new_farm_points =[] # for single_point in farm_points: # new_point = [single_point[1], single_point[0]] # new_farm_points.append(new_point) # main_obj = {} # main_obj["UID"] = "6nZRDEmdq7ajeZLJB2K19RhzVPu1" # main_obj["CropCode"] = "1r" # main_obj["PaymentType"] = "6" # main_obj["FieldName"] = farm_name # main_obj["Points"] = [new_farm_points] # print(main_obj) # time.sleep(2) # API_ENDPOINT = 'https://us-central1-farmbase-b2f7e.cloudfunctions.net/submitField' # r = requests.post(url=API_ENDPOINT, json=main_obj) # except Exception as e: # print(e)