Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -31,7 +31,7 @@ bot = commands.Bot(command_prefix='!', intents=intents)
|
|
31 |
|
32 |
#logger = logging.getLogger(__name__)
|
33 |
#logging.basicConfig(level=logging.DEBUG)
|
34 |
-
|
35 |
|
36 |
""""""
|
37 |
XP_PER_MESSAGE = 10 # 100k messages = 1M exp = lvl 100
|
@@ -51,7 +51,7 @@ api = HfApi()
|
|
51 |
#csv_file = 'data.csv'
|
52 |
global_df = pd.DataFrame()
|
53 |
print(type(global_df))
|
54 |
-
|
55 |
|
56 |
@bot.event
|
57 |
async def on_ready():
|
@@ -61,7 +61,7 @@ async def on_ready():
|
|
61 |
# testing sheet -> read -> paste sheet
|
62 |
|
63 |
"""import data from google sheets -> HF Space .csv (doesn't make API call this way, as it's read-only)"""
|
64 |
-
|
65 |
data['discord_user_id'] = data['discord_user_id'].astype(str)
|
66 |
global_df = data
|
67 |
print(f"csv successfully retrieved: {global_df}")
|
@@ -132,12 +132,9 @@ async def periodic_api_test(): # needs rewrite, can do same thing and interact w
|
|
132 |
async def add_exp(member_id):
|
133 |
try:
|
134 |
global global_df
|
135 |
-
|
136 |
-
print(int(member_id))
|
137 |
-
print(str(member_id))
|
138 |
guild = bot.get_guild(879548962464493619)
|
139 |
-
member = guild.get_member(
|
140 |
-
print(member)
|
141 |
lvl1 = guild.get_role(1171861537699397733)
|
142 |
lvl2 = guild.get_role(1171861595115245699)
|
143 |
lvl3 = guild.get_role(1171861626715115591)
|
@@ -178,8 +175,7 @@ async def add_exp(member_id):
|
|
178 |
|
179 |
member_found = False
|
180 |
for index, cell_value in global_df.iloc[:, 0].items():
|
181 |
-
|
182 |
-
if str(cell_value) == str(member_id):
|
183 |
# if found, update that row...
|
184 |
member_found = True
|
185 |
print(f"Record for {member} found at row {index + 1}, column 1")
|
@@ -211,7 +207,7 @@ async def add_exp(member_id):
|
|
211 |
# if not, create new record
|
212 |
print(f"creating new record for {member}")
|
213 |
#string_member_id = str(member.id)
|
214 |
-
|
215 |
xp = 10 # define somewhere else?
|
216 |
current_level = calculate_level(xp)
|
217 |
member_name = member.name
|
@@ -367,7 +363,7 @@ with demo:
|
|
367 |
column_values_unique = sorted(dataframe1.iloc[:, 3].unique())
|
368 |
dataframe2 = pd.DataFrame({'Levels': column_values_unique})
|
369 |
counts = {}
|
370 |
-
for value in
|
371 |
counts[value] = counts.get(value, 0) + 1
|
372 |
dataframe2['Members'] = dataframe2['Levels'].map(counts)
|
373 |
|
|
|
31 |
|
32 |
#logger = logging.getLogger(__name__)
|
33 |
#logging.basicConfig(level=logging.DEBUG)
|
34 |
+
|
35 |
|
36 |
""""""
|
37 |
XP_PER_MESSAGE = 10 # 100k messages = 1M exp = lvl 100
|
|
|
51 |
#csv_file = 'data.csv'
|
52 |
global_df = pd.DataFrame()
|
53 |
print(type(global_df))
|
54 |
+
data = pd.read_csv("https://docs.google.com/spreadsheets/d/1hQSsIg1Y9WdBF_CdNM1L1rUUREoxKqRTe3_ILo-WK8w/export?format=csv&gid=0")
|
55 |
|
56 |
@bot.event
|
57 |
async def on_ready():
|
|
|
61 |
# testing sheet -> read -> paste sheet
|
62 |
|
63 |
"""import data from google sheets -> HF Space .csv (doesn't make API call this way, as it's read-only)"""
|
64 |
+
|
65 |
data['discord_user_id'] = data['discord_user_id'].astype(str)
|
66 |
global_df = data
|
67 |
print(f"csv successfully retrieved: {global_df}")
|
|
|
132 |
async def add_exp(member_id):
|
133 |
try:
|
134 |
global global_df
|
135 |
+
|
|
|
|
|
136 |
guild = bot.get_guild(879548962464493619)
|
137 |
+
member = guild.get_member(member_id)
|
|
|
138 |
lvl1 = guild.get_role(1171861537699397733)
|
139 |
lvl2 = guild.get_role(1171861595115245699)
|
140 |
lvl3 = guild.get_role(1171861626715115591)
|
|
|
175 |
|
176 |
member_found = False
|
177 |
for index, cell_value in global_df.iloc[:, 0].items():
|
178 |
+
if cell_value == str(member_id):
|
|
|
179 |
# if found, update that row...
|
180 |
member_found = True
|
181 |
print(f"Record for {member} found at row {index + 1}, column 1")
|
|
|
207 |
# if not, create new record
|
208 |
print(f"creating new record for {member}")
|
209 |
#string_member_id = str(member.id)
|
210 |
+
|
211 |
xp = 10 # define somewhere else?
|
212 |
current_level = calculate_level(xp)
|
213 |
member_name = member.name
|
|
|
363 |
column_values_unique = sorted(dataframe1.iloc[:, 3].unique())
|
364 |
dataframe2 = pd.DataFrame({'Levels': column_values_unique})
|
365 |
counts = {}
|
366 |
+
for value in data.iloc[:, 3]:
|
367 |
counts[value] = counts.get(value, 0) + 1
|
368 |
dataframe2['Members'] = dataframe2['Levels'].map(counts)
|
369 |
|