changed requests, now uses aiohttp, hopefully fixes shit
This commit is contained in:
parent
4f6a0017d3
commit
224c0517ae
17
main.py
17
main.py
|
|
@ -3,6 +3,7 @@ from discord.ext import commands
|
|||
import requests
|
||||
import json
|
||||
from datetime import datetime as dt
|
||||
import aiohttp
|
||||
|
||||
|
||||
### reads token files
|
||||
|
|
@ -11,6 +12,16 @@ def readToken(filePath):
|
|||
return f.readline()
|
||||
|
||||
|
||||
|
||||
|
||||
### takes a json, returns a http code
|
||||
async def postToSheet(data, gsheetToken):
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.post(gsheetToken, json=data) as response:
|
||||
print("Status:", response.status)
|
||||
return response.status
|
||||
|
||||
|
||||
bot = commands.Bot()
|
||||
|
||||
# various tokens
|
||||
|
|
@ -72,12 +83,12 @@ async def delivery(ctx,
|
|||
}
|
||||
|
||||
try:
|
||||
response = requests.post(gsheetToken, json.dumps(data), headers={"Content-Type": "application/json"})
|
||||
if response.status_code == 200:
|
||||
response = await postToSheet(data, gsheetToken)
|
||||
if response == 200:
|
||||
await ctx.followup.send(f"your delivery of {quantity} of {commodity} to a {target} has been added to the sheet!")
|
||||
print(f"[{dt.isoformat(dt.now())}]{author} delivery of {quantity} of {commodity} to a {target}")
|
||||
else:
|
||||
await ctx.followup.send(f"Failed to log delivery (HTTP {response.status_code}). Please contact the yellow people if that keeps happening")
|
||||
await ctx.followup.send(f"Failed to log delivery (HTTP {response}). Please contact the yellow people if that keeps happening")
|
||||
except Exception as e:
|
||||
await ctx.followup.send(f"help : Error: {e}")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user