Skip to content

Commit

Permalink
Add irccat command
Browse files Browse the repository at this point in the history
  • Loading branch information
russss committed Jan 17, 2025
1 parent 070a1bd commit 487b165
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tools/ps_irc_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env -S uv run -q
# /// script
# dependencies = [
# "httpx",
# "arrow",
# ]
# ///
#
# Called by IRCCat to handle the ?ps command in IRC.

import httpx
import arrow

data = httpx.get("https://london.pubstandards.com/next.json").json()

event = None

for e in data:
datetime = arrow.get(e["date"] + " " + e["time"])
event = e
if datetime.date() >= arrow.now().date():
break

if event is None:
print("No upcoming events.")
exit()

if datetime < arrow.now():
msg = f"{event['title']} is happening right now at {event['location']}. Get to the pub!"
else:
friendly_date = datetime.humanize(granularity=["day", "hour"])
msg = f"{event['title']} is happening at {event['location']} {friendly_date}: "
msg += f"https://london.pubstandards.com/event/{event['slug']}"

print(msg.encode("utf-8"))

0 comments on commit 487b165

Please sign in to comment.