from google.cloud import storage import time import firebase_admin from firebase_admin import credentials from firebase_admin import db import traceback import sys import time from firebase_admin import firestore from create_interactive_html_report import make_interactive_html_report session_type = 0 try: session_type = sys.argv[1] except: print(traceback.format_exc()) cred = credentials.Certificate("servicekey.json") # os.system("rm -rf AwsData") try: firebase_admin.initialize_app( cred, {"databaseURL": "https://farmbase-b2f7e-31c0c.firebaseio.com/"} ) except: qysy = 1 dbF = firestore.client() storage_client = storage.Client(project='farmbase-b2f7e') bucket_name = "farmbase-b2f7e.appspot.com" db_firestore = firestore.client() disabledUIDs = [ "snQYQZqQx3SmVbRztmEqYn5Mkcz2", "KZQ7TZIYXnXN0b07OtrL1hlyYij1", "CeMGYvLXrGR5ZThxZ46iV7vY8sa2", "TCXcp5VIsfhHZrh0nm2VsgBtcGy2", "mFFHQdEtiSbn2hbYQAwwoIdYVi02" ] def upload_report(uid): bucket = storage_client.get_bucket(bucket_name) blob = bucket.blob(("PaidMonitoredFields/" + uid + "/interactive_report.html")) blob.upload_from_filename((uid + "/interactive_report.html")) def instant_session(): #todo a = 1 while a ==1: report_requests_obj = db_firestore.collection(u'InteractiveReportRequests').where('Processed','==',0).get() try: for temp_d in report_requests_obj: time_stamp = temp_d.id time_stamp = str(time_stamp) print(temp_d.id) print(temp_d.to_dict()) temp_main_obj = temp_d.to_dict() uid = temp_main_obj.get("UID", None) make_interactive_html_report(uid) temp_main_obj["Processed"] = 1 db_firestore.collection(u'InteractiveReportRequests').document(uid).set(temp_main_obj) upload_report(uid) except: print(traceback.format_exc()) time.sleep(60) def daily_session(): while True: uid_list = db.reference('PaidMonitoredFields').child('PMF').get(False, True) for uid, val in uid_list.items(): if uid not in disabledUIDs: try: make_interactive_html_report(uid) upload_report(uid) except: print(traceback.format_exc()) time.sleep((5*86400)) print(session_type) if session_type == 0: instant_session() elif session_type == 1: daily_session() else: a = 1