Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
automated sheets fill
Browse files
app.py
CHANGED
@@ -79,32 +79,48 @@ async def add_exp_hub(ctx):
|
|
79 |
print(f"add_exp_hub Error: {e}")
|
80 |
|
81 |
|
|
|
|
|
|
|
82 |
@bot.command(name='api_test')
|
83 |
async def api_test(ctx):
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
response = requests.get(url)
|
94 |
-
if response.status_code == 200:
|
95 |
-
data = response.json()
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
|
110 |
@bot.command(name='get_cell_value')
|
|
|
79 |
print(f"add_exp_hub Error: {e}")
|
80 |
|
81 |
|
82 |
+
processed_users = set()
|
83 |
+
|
84 |
+
|
85 |
@bot.command(name='api_test')
|
86 |
async def api_test(ctx):
|
87 |
+
while True:
|
88 |
+
await periodic_api_test()
|
89 |
+
await asyncio.sleep(60) # Sleep for 60 seconds
|
90 |
+
|
91 |
+
|
92 |
+
async def periodic_api_test():
|
93 |
+
try:
|
94 |
+
column_values_3 = worksheet2.col_values(3)
|
95 |
+
column_values_8 = worksheet2.col_values(8)
|
|
|
|
|
|
|
96 |
|
97 |
+
for i, user in enumerate(column_values_3):
|
98 |
+
if user in processed_users:
|
99 |
+
continue
|
100 |
+
|
101 |
+
url = f"https://huggingface.co/api/users/{user}/overview"
|
102 |
+
response = requests.get(url)
|
103 |
+
|
104 |
+
if response.status_code == 200:
|
105 |
+
data = response.json()
|
106 |
+
|
107 |
+
likes = data["numLikes"]
|
108 |
+
models = data["numModels"]
|
109 |
+
datasets = data["numDatasets"]
|
110 |
+
spaces = data["numSpaces"]
|
111 |
+
discussions = data["numDiscussions"]
|
112 |
+
papers = data["numPapers"]
|
113 |
+
upvotes = data["numUpvotes"]
|
114 |
+
|
115 |
+
worksheet2.update(values=[[likes, models, datasets, spaces, discussions, papers, upvotes]],
|
116 |
+
range_name=f'G{i+1}:M{i+1}')
|
117 |
+
|
118 |
+
processed_users.add(user)
|
119 |
+
else:
|
120 |
+
print(f"Failed to retrieve data for user {user}. Status code: {response.status_code}")
|
121 |
+
|
122 |
+
except Exception as e:
|
123 |
+
print(f"periodic_api_test Error: {e}")
|
124 |
|
125 |
|
126 |
@bot.command(name='get_cell_value')
|