Skip to content

Commit

Permalink
Merge pull request #227 from idoneam/dev
Browse files Browse the repository at this point in the history
Release Burnside Basement Patch 2
  • Loading branch information
jidicula authored Dec 6, 2019
2 parents a47b4a1 + 359eb0e commit 5080ddd
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions cogs/subscribers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,27 @@
CFIA_FEED_URL = "http://inspection.gc.ca/eng/1388422350443/1388422374046.xml"
METRO_STATUS_API = "https://www.stm.info/en/ajax/etats-du-service"

METRO_GREEN_LINE = "1"
METRO_ORANGE_LINE = "2"
METRO_YELLOW_LINE = "4"
METRO_BLUE_LINE = "5"

METRO_COLOURS = {
METRO_GREEN_LINE: 0x008E4F,
METRO_ORANGE_LINE: 0xF08123,
METRO_YELLOW_LINE: 0xFFE400,
METRO_BLUE_LINE: 0x0083CA,
}

METRO_NORMAL_SERVICE_MESSAGE = "Normal métro service"

# Default values by line number for status
# Integers in list are line colours
metro_status = {
"1": ["Normal métro service", 36431], # Green Line
"2": ["Normal métro service", 15761699], # Orange Line
"4": ["Normal métro service", 16770048], # Yellow Line
"5": ["Normal métro service", 33738]
} # Blue Line
METRO_GREEN_LINE: METRO_NORMAL_SERVICE_MESSAGE,
METRO_ORANGE_LINE: METRO_NORMAL_SERVICE_MESSAGE,
METRO_YELLOW_LINE: METRO_NORMAL_SERVICE_MESSAGE,
METRO_BLUE_LINE: METRO_NORMAL_SERVICE_MESSAGE,
}

os.makedirs('./pickles', exist_ok=True)

Expand Down Expand Up @@ -119,18 +132,17 @@ def check_status(line_number, response):
metro_status_channel = utils.get(
self.bot.get_guild(self.bot.config.server_id).text_channels,
name=self.bot.config.metro_status_channel)
response = requests.request("GET", METRO_STATUS_API)
response = requests.get(METRO_STATUS_API)
for line_status in metro_status.items():
line_number = line_status[0]
cached_status = line_status[1][0]
line_colour = line_status[1][1]
current_status = check_status(line_number, response)
if current_status[1] != cached_status:
cached_status = line_status[1]
line_name, current_status = check_status(line_number, response)
if current_status != cached_status:
metro_status[line_number] = current_status
metro_status_update = discord.Embed(
title=current_status[0],
description=current_status[1],
colour=line_colour)
title=line_name,
description=current_status,
colour=METRO_COLOURS[line_number])
await metro_status_channel.send(embed=metro_status_update)
await asyncio.sleep(60) # Run every 60 seconds

Expand Down

0 comments on commit 5080ddd

Please sign in to comment.