Add support of different platforms

This commit is contained in:
yagudin 2021-06-01 18:59:04 +03:00
parent 16807774f0
commit 339ea544ac

View File

@ -12,7 +12,9 @@ db = firestore.Client(credentials=credentials, project="gjo-calibration")
def get_forecasts(uid, questions, platform_url, headers, cookies):
db_forecasts = db.collection("users").document(uid).get().to_dict()
platform = "gjo" if platform_url == "https://www.gjopen.com" else "cset"
db_forecasts = db.collection(f"users_{platform}").document(uid).get().to_dict()
db_forecasts = dict() if db_forecasts is None else db_forecasts
missing_forecasts_qs = list(set(questions) - set(db_forecasts))
@ -22,14 +24,16 @@ def get_forecasts(uid, questions, platform_url, headers, cookies):
if missing_forecasts:
if not db_forecasts:
db.collection("users").add({}, uid)
db.collection("users").document(uid).update(missing_forecasts)
db.collection(f"users_{platform}").add({}, uid)
db.collection(f"users_{platform}").document(uid).update(missing_forecasts)
return {key: value for key, value in {**db_forecasts, **missing_forecasts}.items() if key in questions}
def get_resolutions(questions, platform_url, headers, cookies):
db_resolutions = db.collection("questions").document("resolutions").get().to_dict()
platform = "gjo" if platform_url == "https://www.gjopen.com" else "cset"
db_resolutions = db.collection(f"questions_{platform}").document("resolutions").get().to_dict()
db_resolutions = dict() if db_resolutions is None else db_resolutions
relevant_resolutions = {
key: value for key, value in db_resolutions.items() if key in set(questions)
@ -41,6 +45,6 @@ def get_resolutions(questions, platform_url, headers, cookies):
)
if missing_resolutions:
db.collection("questions").document("resolutions").update(missing_resolutions)
db.collection(f"questions_{platform}").document("resolutions").update(missing_resolutions)
return {**relevant_resolutions, **missing_resolutions}