Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
cleaning up csv start
Browse files
app.py
CHANGED
|
@@ -343,85 +343,84 @@ async def xp_help(ctx):
|
|
| 343 |
|
| 344 |
|
| 345 |
@bot.command()
|
| 346 |
-
async def
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
csv_writer.writerows(values)
|
| 357 |
|
| 358 |
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
|
| 381 |
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
target_user = await bot.fetch_user(int(target_id))
|
| 390 |
|
| 391 |
-
|
|
|
|
|
|
|
|
|
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
-
|
| 396 |
|
| 397 |
-
|
| 398 |
|
| 399 |
-
|
| 400 |
|
| 401 |
-
|
| 402 |
|
| 403 |
|
| 404 |
@bot.command()
|
| 405 |
async def read_csv(ctx):
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
else:
|
| 424 |
-
await ctx.send("No attachments found in the latest message.")
|
| 425 |
|
| 426 |
|
| 427 |
"""
|
|
|
|
| 343 |
|
| 344 |
|
| 345 |
@bot.command()
|
| 346 |
+
async def write_csv(ctx):
|
| 347 |
+
worksheet = gspread_bot.open("levelbot").sheet1
|
| 348 |
+
values = worksheet.get_all_values()
|
| 349 |
+
target_id = '811235357663297546'
|
| 350 |
+
variable_xp = 0
|
| 351 |
+
|
| 352 |
+
csv_file_path = 'test.csv'
|
| 353 |
+
with open(csv_file_path, 'w', newline='') as csv_file:
|
| 354 |
+
csv_writer = csv.writer(csv_file)
|
| 355 |
+
csv_writer.writerows(values)
|
|
|
|
| 356 |
|
| 357 |
|
| 358 |
+
# modifying csv data
|
| 359 |
+
with open(csv_file_path, 'r') as csv_file:
|
| 360 |
+
csv_reader = csv.reader(csv_file)
|
| 361 |
+
rows = list(csv_reader)
|
| 362 |
+
|
| 363 |
+
for row in rows:
|
| 364 |
+
print(row)
|
| 365 |
+
if target_id in row:
|
| 366 |
+
index_of_target = row.index(target_id)
|
| 367 |
+
|
| 368 |
+
# 2 to right
|
| 369 |
+
cell_to_increment_index = index_of_target + 2
|
| 370 |
+
|
| 371 |
+
# +10
|
| 372 |
+
try:
|
| 373 |
+
row[cell_to_increment_index] = str(int(row[cell_to_increment_index]) + variable_xp)
|
| 374 |
+
print(row[cell_to_increment_index])
|
| 375 |
+
except (IndexError, ValueError):
|
| 376 |
+
print(f"Error: Unable to increment cell at index {cell_to_increment_index}")
|
| 377 |
+
|
| 378 |
+
break
|
| 379 |
|
| 380 |
|
| 381 |
+
# write modified data and send in discord
|
| 382 |
+
with open(csv_file_path, 'w', newline='') as csv_file:
|
| 383 |
+
csv_writer = csv.writer(csv_file)
|
| 384 |
+
csv_writer.writerows(rows)
|
| 385 |
|
| 386 |
+
csv_data_str = '\n'.join(','.join(row) for row in rows)
|
| 387 |
+
csv_file = discord.File(csv_file_path)
|
|
|
|
| 388 |
|
| 389 |
+
await ctx.channel.send(content="csv", file=csv_file)
|
| 390 |
+
|
| 391 |
+
#target_user = await bot.fetch_user(int(target_id))
|
| 392 |
+
#await target_user.send(content="csv", file=csv_file)
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
+
|
| 397 |
|
| 398 |
+
# do simple operation on file (change one value)
|
| 399 |
|
| 400 |
+
# post current version to discord
|
| 401 |
|
| 402 |
+
# recover csv from discord channel, read into memory
|
| 403 |
|
| 404 |
|
| 405 |
@bot.command()
|
| 406 |
async def read_csv(ctx):
|
| 407 |
+
async for message in ctx.channel.history(limit=10):
|
| 408 |
+
if message.attachments:
|
| 409 |
+
attachment = message.attachments[0]
|
| 410 |
+
if attachment.filename.endswith('.csv'):
|
| 411 |
+
csv_content = await attachment.read()
|
| 412 |
+
csv_data = []
|
| 413 |
+
csv_lines = csv_content.decode('utf-8').splitlines()
|
| 414 |
+
csv_reader = csv.reader(csv_lines)
|
| 415 |
+
for row in csv_reader:
|
| 416 |
+
csv_data.append(row)
|
| 417 |
+
print(csv_data)
|
| 418 |
+
|
| 419 |
+
await ctx.send("discord -> read -> updated HF Hub")
|
| 420 |
+
# react to the given message, helps with explainability
|
| 421 |
+
await message.add_reaction('✅')
|
| 422 |
+
break
|
| 423 |
+
|
|
|
|
|
|
|
| 424 |
|
| 425 |
|
| 426 |
"""
|