Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
hfapi
Browse files
app.py
CHANGED
@@ -36,7 +36,7 @@ with open(file_path, 'w') as json_file:
|
|
36 |
json.dump(service_account, json_file)
|
37 |
gspread_bot = gspread.service_account(filename='service_account.json')
|
38 |
#worksheet = gspread_bot.open("levelbot").sheet1
|
39 |
-
|
40 |
""""""
|
41 |
bot_ids = [1136614989411655780, 1166392942387265536, 1158038249835610123, 1130774761031610388, 1155489509518098565, 1155169841276260546, 1152238037355474964, 1154395078735953930]
|
42 |
""""""
|
@@ -60,6 +60,43 @@ def calculate_xp(level):
|
|
60 |
|
61 |
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
"""
|
65 |
async def search_csv(file_path, column_index, search_value):
|
@@ -215,7 +252,7 @@ async def on_message(message):
|
|
215 |
if message.author.id not in bot_ids:
|
216 |
print(f"adding exp from message {message.author}")
|
217 |
await add_exp(message.author.id)
|
218 |
-
|
219 |
await bot.process_commands(message)
|
220 |
except Exception as e:
|
221 |
print(f"on_message Error: {e}")
|
|
|
36 |
json.dump(service_account, json_file)
|
37 |
gspread_bot = gspread.service_account(filename='service_account.json')
|
38 |
#worksheet = gspread_bot.open("levelbot").sheet1
|
39 |
+
worksheet2 = gspread_bot.open("hf_discord_verified_users_test").sheet1
|
40 |
""""""
|
41 |
bot_ids = [1136614989411655780, 1166392942387265536, 1158038249835610123, 1130774761031610388, 1155489509518098565, 1155169841276260546, 1152238037355474964, 1154395078735953930]
|
42 |
""""""
|
|
|
60 |
|
61 |
|
62 |
|
63 |
+
processed_users = set()
|
64 |
+
|
65 |
+
async def periodic_api_test():
|
66 |
+
try:
|
67 |
+
column_values_3 = worksheet2.col_values(3)
|
68 |
+
column_values_8 = worksheet2.col_values(8)
|
69 |
+
|
70 |
+
for i, user in enumerate(column_values_3):
|
71 |
+
if user in processed_users:
|
72 |
+
continue
|
73 |
+
|
74 |
+
url = f"https://huggingface.co/api/users/{user}/overview"
|
75 |
+
response = requests.get(url)
|
76 |
+
|
77 |
+
if response.status_code == 200:
|
78 |
+
data = response.json()
|
79 |
+
|
80 |
+
likes = data["numLikes"]
|
81 |
+
models = data["numModels"]
|
82 |
+
datasets = data["numDatasets"]
|
83 |
+
spaces = data["numSpaces"]
|
84 |
+
discussions = data["numDiscussions"]
|
85 |
+
papers = data["numPapers"]
|
86 |
+
upvotes = data["numUpvotes"]
|
87 |
+
|
88 |
+
worksheet2.update(values=[[likes, models, datasets, spaces, discussions, papers, upvotes]],
|
89 |
+
range_name=f'G{i+1}:M{i+1}')
|
90 |
+
|
91 |
+
processed_users.add(user)
|
92 |
+
else:
|
93 |
+
print(f"Failed to retrieve data for user {user}. Status code: {response.status_code}")
|
94 |
+
|
95 |
+
except Exception as e:
|
96 |
+
print(f"periodic_api_test Error: {e}")
|
97 |
+
|
98 |
+
|
99 |
+
|
100 |
|
101 |
"""
|
102 |
async def search_csv(file_path, column_index, search_value):
|
|
|
252 |
if message.author.id not in bot_ids:
|
253 |
print(f"adding exp from message {message.author}")
|
254 |
await add_exp(message.author.id)
|
255 |
+
await periodic_api_test() # run this ~1 per day otherwise will lead to issues
|
256 |
await bot.process_commands(message)
|
257 |
except Exception as e:
|
258 |
print(f"on_message Error: {e}")
|