From d70a18ad82c5e7335d08155cb17e7fe23a809b11 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 1 Dec 2023 10:35:58 +0000 Subject: [PATCH] Add event for Hacker News 'Who is Hiring?' Closes: #78 --- agenda/data.py | 2 ++ agenda/hn.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 agenda/hn.py diff --git a/agenda/data.py b/agenda/data.py index 849b205..66662a4 100644 --- a/agenda/data.py +++ b/agenda/data.py @@ -24,6 +24,7 @@ from . import ( economist, fx, gwr, + hn, meetup, stock_market, subscription, @@ -261,6 +262,7 @@ async def get_data(now: datetime) -> typing.Mapping[str, str | object]: events += subscription.get_events(os.path.join(my_data, "subscriptions.yaml")) events += economist.publication_dates(last_week, next_year) events += meetup.get_events(my_data) + events += hn.whoishiring(last_year, next_year) events += domains.renewal_dates(my_data) diff --git a/agenda/hn.py b/agenda/hn.py new file mode 100644 index 0000000..9f11e91 --- /dev/null +++ b/agenda/hn.py @@ -0,0 +1,30 @@ +"""Hacker News: Who Is Hiring post.""" + +from datetime import date, datetime, time, timedelta + +import pytz +from dateutil.relativedelta import relativedelta + +from .types import Event + +eastern_time = pytz.timezone("America/New_York") + + +def whoishiring(start_date: date, end_date: date) -> list[Event]: + """Who Is Hiring post.""" + events: list[Event] = [] + cur = start_date.replace(day=1) + t = time(11, 0) + while cur < end_date: + cur += relativedelta(months=1) + weekday = cur.weekday() + event_date = cur if 0 <= weekday <= 4 else cur + timedelta(days=7 - weekday) + events.append( + Event( + name="whoishiring", + date=eastern_time.localize(datetime.combine(event_date, t)), + url="https://news.ycombinator.com/submitted?id=whoishiring", + ) + ) + + return events