import os from google.cloud import storage import firebase_admin from firebase_admin import credentials from firebase_admin import db # import seaborn as sns # sns.set() bucket_name = "farmbase-b2f7e.appspot.com" def initFire(): cred = credentials.Certificate("servicekey.json") try: firebase_admin.initialize_app( cred, {"databaseURL": "https://farmbase-b2f7e-31c0c.firebaseio.com/"} ) except: print("fire running") def getAllFields(uid): # initi firebase initFire() all_fields_obj = ( db.reference("PaidMonitoredFields").child("PMF").child(uid).get(False, True) ) i = 0 # print(all_fields_obj) for fieldID, r_obj in all_fields_obj.items(): latest_day_obj = ( db.reference("PaidMonitoredFields") .child("PMF") .child(uid) .child(fieldID) .child("SensedDays") .get() ) health = ( db.reference("PaidMonitoredFields") .child("PMF") .child(uid) .child(fieldID) .child("Health") .get() ) all_fields_obj[fieldID] = {"SensedDays": latest_day_obj, "Health": health} # if i == 0: # break # val = all_fields_obj[fieldID] # print(val) i += 1 return all_fields_obj def isCloudyErrTest(): uid = "ENLgcB9pl2fH7MjsEH7oc72YBRh2" etci = "%s/ETCI.png" % uid ndvi = "%s/ndvi.png" % uid # isCloudy = isCloudyImg(etci, ndvi) # print(isCloudy) def downloadImg(uid, fieldid, single_date, image_name): storage_client = storage.Client() bucket = storage_client.get_bucket(bucket_name) blob_name = ( "PaidMonitoredFields/" + uid + "/" + fieldid + "/" + single_date + "/" + image_name ) blob = bucket.blob(blob_name) file_name = getTestFileName(uid, image_name) blob.download_to_filename(file_name) def getTestFileName(uid, img): file_name = "test/" + img + ".png" return file_name def updateData(pathFromUID, data): # print(pathFromUID, data) db.reference("PaidMonitoredFields").child("PMF").child(pathFromUID).set(data) #uid = "M53J9SImW9My4vghlCaaWLYxsc22" #getAllFields(uid) def tmuxTest(): os.system('tmux send-keys -t test50 "ls ../" Enter') #os.system('rm test2.py') #tmuxTest()