Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
|
@@ -106,9 +106,15 @@ def update_google_sheet():
|
|
| 106 |
})
|
| 107 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 108 |
print(f"Google sheet {name} successfully updated at {timestamp}! \n{global_df}")
|
| 109 |
-
|
|
|
|
|
|
|
| 110 |
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
worksheet2.format(f"E1:E{len(worksheet2_df.index)+1}", {
|
| 113 |
"numberFormat": {
|
| 114 |
"type": 'TEXT',
|
|
@@ -119,6 +125,7 @@ def update_google_sheet():
|
|
| 119 |
"type": 'TEXT',
|
| 120 |
},
|
| 121 |
})
|
|
|
|
| 122 |
name2 = "hf_discord_verified_users_test"
|
| 123 |
# could just do this / format
|
| 124 |
worksheet2['discord_user_id'] = worksheet2['discord_user_id'].astype(str)
|
|
@@ -126,18 +133,16 @@ def update_google_sheet():
|
|
| 126 |
print(worksheet2_df.dtypes)
|
| 127 |
set_with_dataframe(worksheet2, worksheet2_df)
|
| 128 |
# very important, otherwise gspread will force format IDs in scientific notation by default (making them unusable)
|
| 129 |
-
|
| 130 |
-
|
| 131 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 132 |
print(f"Google sheet {name2} successfully updated at {timestamp}!")
|
| 133 |
-
print(f"------------------------------------------------------------------------")
|
| 134 |
except Exception as e:
|
| 135 |
print(f"on_message Error: {e}")
|
| 136 |
-
|
| 137 |
|
| 138 |
executor = ThreadPoolExecutor(max_workers=1)
|
| 139 |
scheduler = BackgroundScheduler(executors={'default': executor})
|
| 140 |
scheduler.add_job(update_google_sheet, trigger='interval', minutes=1, max_instances=1)
|
|
|
|
| 141 |
scheduler.start()
|
| 142 |
|
| 143 |
|
|
@@ -159,7 +164,7 @@ async def periodic_api_test(): # needs rewrite, can do same thing and interact w
|
|
| 159 |
for index, user in enumerate(worksheet2_df['hf_user_name']):
|
| 160 |
if user in processed_users:
|
| 161 |
continue
|
| 162 |
-
await asyncio.sleep(0.
|
| 163 |
url = f"https://huggingface.co/api/users/{user}/overview"
|
| 164 |
response = requests.get(url)
|
| 165 |
|
|
|
|
| 106 |
})
|
| 107 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 108 |
print(f"Google sheet {name} successfully updated at {timestamp}! \n{global_df}")
|
| 109 |
+
print(f"------------------------------------------------------------------------")
|
| 110 |
+
except Exception as e:
|
| 111 |
+
print(f"on_message Error: {e}")
|
| 112 |
|
| 113 |
|
| 114 |
+
def update_google_sheet2():
|
| 115 |
+
"""save data from HF Space -> google sheets (makes 2 API calls)"""
|
| 116 |
+
try:
|
| 117 |
+
"""
|
| 118 |
worksheet2.format(f"E1:E{len(worksheet2_df.index)+1}", {
|
| 119 |
"numberFormat": {
|
| 120 |
"type": 'TEXT',
|
|
|
|
| 125 |
"type": 'TEXT',
|
| 126 |
},
|
| 127 |
})
|
| 128 |
+
"""
|
| 129 |
name2 = "hf_discord_verified_users_test"
|
| 130 |
# could just do this / format
|
| 131 |
worksheet2['discord_user_id'] = worksheet2['discord_user_id'].astype(str)
|
|
|
|
| 133 |
print(worksheet2_df.dtypes)
|
| 134 |
set_with_dataframe(worksheet2, worksheet2_df)
|
| 135 |
# very important, otherwise gspread will force format IDs in scientific notation by default (making them unusable)
|
|
|
|
|
|
|
| 136 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 137 |
print(f"Google sheet {name2} successfully updated at {timestamp}!")
|
|
|
|
| 138 |
except Exception as e:
|
| 139 |
print(f"on_message Error: {e}")
|
| 140 |
+
|
| 141 |
|
| 142 |
executor = ThreadPoolExecutor(max_workers=1)
|
| 143 |
scheduler = BackgroundScheduler(executors={'default': executor})
|
| 144 |
scheduler.add_job(update_google_sheet, trigger='interval', minutes=1, max_instances=1)
|
| 145 |
+
scheduler.add_job(update_google_sheet2, trigger='interval', minutes=1, max_instances=1)
|
| 146 |
scheduler.start()
|
| 147 |
|
| 148 |
|
|
|
|
| 164 |
for index, user in enumerate(worksheet2_df['hf_user_name']):
|
| 165 |
if user in processed_users:
|
| 166 |
continue
|
| 167 |
+
await asyncio.sleep(0.5)
|
| 168 |
url = f"https://huggingface.co/api/users/{user}/overview"
|
| 169 |
response = requests.get(url)
|
| 170 |
|