Skip to content

Commit 2fd9f0a

Browse files
authored
Merge pull request #289 from raven0034/master
event_sync to read ISO from updated Fulcrum API
2 parents d996ac7 + c7d675e commit 2fd9f0a

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

cogs/commands/event_sync.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
ENDPOINT = "https://events.uwcs.co.uk/api/events/days/"
1818

19+
LONDON = timezone("Europe/London")
20+
1921

2022
class Sync(commands.Cog):
2123
def __init__(self, bot: Bot):
@@ -24,7 +26,7 @@ def __init__(self, bot: Bot):
2426
@commands.hybrid_command(help=LONG_HELP_TEXT, brief=SHORT_HELP_TEXT)
2527
@commands.check(is_compsoc_exec_in_guild)
2628
async def event(self, ctx: Context, days: int = 7, logging: bool = False):
27-
now = datetime.now(timezone("Europe/London"))
29+
now = datetime.now(LONDON)
2830
before = now + timedelta(days=days)
2931

3032
await ctx.send(f"Syncing events from {now} to {before}")
@@ -73,7 +75,7 @@ async def update_event(self, ctx, ev, links, dc_events):
7375
else:
7476
# Don't edit if no change
7577
if self.check_event_equiv(event_args, event):
76-
# Updat existing event
78+
# Update existing event
7779
await event.edit(**event_args)
7880
await ctx.send(
7981
f"Updated event **{ev.get('summary')}** at event {event.url}"
@@ -96,12 +98,10 @@ def api_event_to_dc_args(ev):
9698
return {
9799
"name": ev.get("name"),
98100
"description": description,
99-
"start_time": datetime.strptime(
100-
ev.get("start_time"), "%Y-%m-%dT%H:%M"
101-
).replace(tzinfo=timezone("Europe/London")),
102-
"end_time": datetime.strptime(ev.get("end_time"), "%Y-%m-%dT%H:%M").replace(
103-
tzinfo=timezone("Europe/London")
104-
),
101+
# depends on Fulcrum API providing tz-aware dts
102+
# this handling fine despite py3.10 quirks
103+
"start_time": datetime.fromisoformat(ev.get("start_time")),
104+
"end_time": datetime.fromisoformat(ev.get("end_time")),
105105
"entity_type": discord.EntityType.external,
106106
"location": ev.get("location"),
107107
}
@@ -125,7 +125,7 @@ def check_event_equiv(event_args, event):
125125
@staticmethod
126126
def update_db_link(uid, event_id, link):
127127
"""Update database record. If new, create, otherwise update"""
128-
now = datetime.now(timezone("Europe/London"))
128+
now = datetime.now(LONDON)
129129
if not link:
130130
link = EventLink(uid=uid, discord_event=event_id, last_modified=now)
131131
db_session.add(link)

0 commit comments

Comments
 (0)