Adding trackday functionality
This commit is contained in:
parent
35078e7f02
commit
fead0a1e5d
24
app/bot.py
24
app/bot.py
@ -273,6 +273,19 @@ async def wallpaper(ctx):
|
||||
import wallpaper
|
||||
await ctx.send(embed=generate_embed(embed_url=wallpaper.fcking_homepage()))
|
||||
|
||||
@bot.command(name='trackdays')
|
||||
async def trackdays(ctx):
|
||||
import trackdays
|
||||
|
||||
for track, events in trackdays.get_msreg().items():
|
||||
embed = discord.Embed(description=":checkered_flag: **Upcoming events at %s**:checkered_flag: " % track, color=0x428bca, type="rich")
|
||||
for track_day in events:
|
||||
embed.add_field(name='-------------\n**Event Name**', value=track_day['event_name'], inline=False)
|
||||
embed.add_field(name='Date', value=track_day['event_date'], inline=False)
|
||||
embed.add_field(name='Event URL', value=track_day['event_url'], inline=False)
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@bot.command(name='verify')
|
||||
async def verify(ctx):
|
||||
message = list(await ctx.message.channel.history(limit=2).flatten())[-1]
|
||||
@ -334,7 +347,16 @@ async def birb(ctx):
|
||||
@bot.command(name='dale')
|
||||
async def dale(ctx):
|
||||
import animals
|
||||
await ctx.send(file=discord.File(animals.dale()))
|
||||
# If the file picked is too large, try again
|
||||
dale_pic = None
|
||||
while not dale_pic:
|
||||
try:
|
||||
dale_pic = animals.dale()
|
||||
await ctx.send(file=discord.File(dale_pic))
|
||||
except Exception:
|
||||
print("File too large, trying again")
|
||||
dale_pic = None
|
||||
|
||||
|
||||
@bot.command(name='corona')
|
||||
async def corona(ctx):
|
||||
|
@ -157,10 +157,10 @@ def get_help_message(method):
|
||||
'Returns the URL for an anime girl pouting you filthy weeb\n',
|
||||
'Usage: !pout'
|
||||
],
|
||||
'quake': [
|
||||
'Returns player stats for a quake champions account\n'
|
||||
'Usage: !quake <player name>'
|
||||
],
|
||||
# 'quake': [
|
||||
# 'Returns player stats for a quake champions account\n'
|
||||
# 'Usage: !quake <player name>'
|
||||
# ],
|
||||
'rat': [
|
||||
'Returns a random rat photo',
|
||||
'\nUsage: !rat'
|
||||
@ -181,6 +181,18 @@ def get_help_message(method):
|
||||
'Returns basic stock information for the stock you entered.',
|
||||
'\nUsage: !stock AAPL TSLA'
|
||||
],
|
||||
'trackdays': [
|
||||
'Returns the track schedule for the tracks we frequent (buttonwillow, laguna, sonoma, thunderhill).\n',
|
||||
# 'Use abbreviations to reference the tracks, as follows\n',
|
||||
# 'bw = Buttonwillow Raceway\n',
|
||||
# 'willow = Willow Springs\n',
|
||||
# 'streets = Streets of Willow Springs\n',
|
||||
# 'laguna = WeatherTech Raceway Laguna Seca\n',
|
||||
# 'thill = Thunderhill Raceway Park\n',
|
||||
# 'sonoma = Sonoma Raceway\n',
|
||||
# 'acs = Auto Club Speedway\n',
|
||||
'Usage: !trackdays'
|
||||
],
|
||||
'tts': [
|
||||
'Uploads a file with the specified text as an MP3.\nThis is advanced shitposting',
|
||||
'\nUsage: !tts who watches the watchmen?',
|
||||
@ -205,7 +217,7 @@ def get_help_message(method):
|
||||
|
||||
def get_help_embed(bot):
|
||||
categories = {
|
||||
'fun': ['ffxiv', 'clap', 'youtube', 'excuse', 'greentext', 'lewd', 'message', 'meme', 'homepage', 'pout', 'roll', 'smug', 'quake', 'wink', 'verify', 'horny', 'wasted', 'simp'],
|
||||
'fun': ['ffxiv', 'clap', 'youtube', 'excuse', 'greentext', 'lewd', 'message', 'meme', 'homepage', 'pout', 'roll', 'smug', 'wink', 'verify', 'horny', 'wasted', 'simp', 'trackdays'],
|
||||
'util': ['ask', 'corona', 'emoji', '8ball', 'decide', 'info', 'icon', 'wallpaper', 'stock', 'tts', 'issue'],
|
||||
'users': ['help', 'invite', 'purge', 'roles', 'source'],
|
||||
'pictures of animals': ['birb', 'redpanda,' 'dale', 'dog', 'rat', 'koala', 'panda', 'raccoon', 'fox', 'cat', 'kangaroo'],
|
||||
@ -224,8 +236,8 @@ def get_help_embed(bot):
|
||||
|
||||
description2 = "**Use `!help <Command>` for more information about a command.** \n\n" + \
|
||||
"**Examples:** \n `!help dog` for detailed help for the dog command \n\n" + \
|
||||
"**Useful links:** [My source code](http://git.luker.gq/ldooks/dragon-bot), [Server status](http://luker.gq/status), [Donate](http://luker.gq/donate) \n\n" + \
|
||||
"**Invite me to another server:** [Click here](https://discord.com/oauth2/authorize?client_id=%s&scope=bot)" % bot.user.id
|
||||
"**Useful links:** [My source code](http://git.luker.gq/ldooks/dragon-bot), [Donate](http://luker.gq/donate) \n\n" + \
|
||||
"**Invite me to another server:** [Click here](https://discord.com/oauth2/authorize?client_id=%s&scope=bot&permissions=8)" % bot.user.id
|
||||
|
||||
embed.add_field(name="\u200b", value=description2, inline=False)
|
||||
return embed
|
||||
|
43
app/trackdays.py
Executable file
43
app/trackdays.py
Executable file
@ -0,0 +1,43 @@
|
||||
from datetime import datetime
|
||||
import json
|
||||
import pprint
|
||||
import requests
|
||||
import xmltodict
|
||||
|
||||
def get_msreg():
|
||||
base_url = 'https://api.motorsportreg.com/rest/calendars/organization'
|
||||
orgs = {
|
||||
'speeddistrict': '2E22740B-E8C9-9FB9-21406A496429A28B',
|
||||
'ongrid' : '06277C99-00C9-23EB-FD08FE5275BCC0C5',
|
||||
'speedsf' : '072A885E-AD68-6F64-E88C19E4D0D21DFB',
|
||||
'turn8' : 'F3469266-BEFF-E329-4FD6C4B189ACE2A8',
|
||||
'speedventures': 'DF7453ED-BF33-DC17-2C9BFD84C1F05E86',
|
||||
#'corsaclub' : 'CE6E69CF-BAEC-DBB6-303EE7D3EC69B8A3',
|
||||
}
|
||||
events = {}
|
||||
for org_name, org_id in orgs.items():
|
||||
xml_blob = requests.get("%s/%s?exclude_cancelled=true&postalcode=%s&radius=500" % (base_url, org_id, zipcode)).text
|
||||
json_blob = json.loads(json.dumps(xmltodict.parse(xml_blob)['response']['events']))
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
|
||||
for event in json_blob['event']:
|
||||
event_object = {
|
||||
'event_name': event['name'],
|
||||
'event_url': event['detailuri'].split('?utm')[0],
|
||||
'event_date': event['start'],
|
||||
}
|
||||
track = event['venue']['name']
|
||||
if track not in events:
|
||||
events[track] = []
|
||||
events[track].append(event_object)
|
||||
|
||||
# sort track events by date
|
||||
def date_to_datettime(input):
|
||||
return datetime.strptime(input['event_date'], '%Y-%m-%d')
|
||||
for races in events.values():
|
||||
sorted(races, key=date_to_datettime)
|
||||
|
||||
return events
|
||||
|
||||
# if __name__ == '__main__':
|
||||
# get_msreg()
|
Loading…
x
Reference in New Issue
Block a user