tested new way to present left to haul data.
This commit is contained in:
parent
8aa61a109e
commit
3415b38e4e
65
main.py
65
main.py
|
|
@ -81,6 +81,16 @@ async def getInternalCarrierState():
|
||||||
response = await getFromSheet(gsheetToken, "carrier")
|
response = await getFromSheet(gsheetToken, "carrier")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
###creates a nice progress bar from two values
|
||||||
|
async def createProgressBar(a,b):
|
||||||
|
print(a, b)
|
||||||
|
ratio = floor(((b-a)/b) * 10)
|
||||||
|
|
||||||
|
print(ratio)
|
||||||
|
|
||||||
|
progressBar = f"{'⣿'* ratio}{'.'*(10-ratio)} ({ratio*10}%)"
|
||||||
|
|
||||||
|
return progressBar
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -232,7 +242,7 @@ async def misc(ctx,
|
||||||
data = {
|
data = {
|
||||||
"postType":"delivery",
|
"postType":"delivery",
|
||||||
"username":author,
|
"username":author,
|
||||||
"commodity": commodity,
|
"commodity": "Misc",
|
||||||
"quantity": quantity,
|
"quantity": quantity,
|
||||||
"target": target
|
"target": target
|
||||||
}
|
}
|
||||||
|
|
@ -431,37 +441,56 @@ async def lefttohaul(ctx):
|
||||||
@tasks.loop(seconds=60)
|
@tasks.loop(seconds=60)
|
||||||
async def writeToWhatsLeftToHaul():
|
async def writeToWhatsLeftToHaul():
|
||||||
response = await getFromSheet(gsheetToken, "commodity")
|
response = await getFromSheet(gsheetToken, "commodity")
|
||||||
print("test")
|
|
||||||
text = "```"
|
|
||||||
|
|
||||||
commodity, values = response.split("|")
|
|
||||||
|
commodity, values, initial = response.split("|")
|
||||||
|
|
||||||
commodity = commodity.split(",")
|
commodity = commodity.split(",")
|
||||||
values = values.split(",")
|
values = values.split(",")
|
||||||
|
initial = initial.split(",")
|
||||||
|
|
||||||
|
values = [int(i) for i in values]
|
||||||
|
initial = [int (i) for i in initial]
|
||||||
|
|
||||||
|
print(values, initial)
|
||||||
|
|
||||||
finalDict = {}
|
finalDict = {}
|
||||||
|
progressDict = {}
|
||||||
|
|
||||||
for i in range(len(commodity)):
|
for i in range(len(commodity)):
|
||||||
finalDict[commodity[i]] = int(values[i])
|
finalDict[commodity[i]] = values[i]
|
||||||
|
if initial[i] > 0:
|
||||||
|
progressDict[commodity[i]] = await createProgressBar(values[i],initial[i])
|
||||||
|
else:
|
||||||
|
progressDict[commodity[i]] = await createProgressBar(1,1)
|
||||||
|
|
||||||
finalDict = dict(sorted(finalDict.items(), key=lambda item: item[1], reverse=True))
|
#finalDict = dict(sorted(finalDict.items(), key=lambda item: item[1], reverse=True))
|
||||||
|
|
||||||
|
print(progressDict)
|
||||||
for key in finalDict:
|
|
||||||
if finalDict[key] > 0:
|
|
||||||
text += f"{key} : {finalDict[key]}\n"
|
|
||||||
|
|
||||||
channel = bot.get_channel(1519457137234022460)
|
channel = bot.get_channel(1519457137234022460)
|
||||||
# await channel.purge(limit=1)
|
# await channel.purge(limit=1)
|
||||||
|
|
||||||
text += "```"
|
|
||||||
|
|
||||||
embed = discord.Embed(title="Estimated remaining amounts and where to get them",
|
|
||||||
colour=discord.Colour(0x29ac08),
|
embed = discord.Embed(title="Estimated remaining amounts",
|
||||||
description=text,
|
colour=discord.Colour(0x29ac08),
|
||||||
timestamp=datetime.now())
|
timestamp=datetime.now())
|
||||||
embed.set_thumbnail(url="https://cdn.discordapp.com/emojis/536647643367997492.png")
|
embed.set_thumbnail(url="https://cdn.discordapp.com/emojis/536647643367997492.png")
|
||||||
|
|
||||||
embed.set_footer(text="This message updates every 60 seconds(ish). Last updated at")
|
embed2 = discord.Embed(title="Current progress",
|
||||||
|
colour=discord.Colour(0x29ac08),
|
||||||
|
timestamp=datetime.now())
|
||||||
|
embed2.set_thumbnail(url="https://cdn.discordapp.com/emojis/536647643367997492.png")
|
||||||
|
|
||||||
|
|
||||||
|
for key in finalDict:
|
||||||
|
if finalDict[key] > 0:
|
||||||
|
embed.add_field(name=key, value=finalDict[key], inline=True)
|
||||||
|
embed2.add_field(name=key, value=str(progressDict[key]), inline=True)
|
||||||
|
|
||||||
|
|
||||||
|
embed.set_footer(text="This message updates every 60 seconds(ish). Last updated")
|
||||||
# if 'station_name' in config.config and 'station_link' in config.config:
|
# if 'station_name' in config.config and 'station_link' in config.config:
|
||||||
# embed.set_author(name=u'\U0001F517 ' + config.config['station_name'] + u' \U0001F517',
|
# embed.set_author(name=u'\U0001F517 ' + config.config['station_name'] + u' \U0001F517',
|
||||||
# url=config.config['station_link'])
|
# url=config.config['station_link'])
|
||||||
|
|
@ -472,10 +501,10 @@ async def writeToWhatsLeftToHaul():
|
||||||
async for oldmsg in channel.history(limit=2):
|
async for oldmsg in channel.history(limit=2):
|
||||||
if oldmsg.author == bot.user:
|
if oldmsg.author == bot.user:
|
||||||
found = True
|
found = True
|
||||||
await oldmsg.edit(embed=embed)
|
await oldmsg.edit(embeds=[embed, embed2])
|
||||||
break
|
break
|
||||||
if not found:
|
if not found:
|
||||||
await channel.send(embed=embed)
|
await channel.send(embeds=[embed, embed2])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user