Skip to content

Commit

Permalink
fix events
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed Oct 18, 2024
1 parent 40b4bba commit 85c3feb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions events_feeds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
- name: PyWorking Sessions
site_url: https://pyworking.cz/
url: https://www.meetup.com/pyworking/events/
format: json-dl
format: meetupcom

- name: PyData Prague
site_url: https://www.meetup.com/pydata-prague/
url: https://www.meetup.com/pydata-prague/events/
format: json-dl
format: meetupcom

- name: Czech Python Events
site_url: https://calendar.google.com/calendar/embed?src=kfdeelic1a13jsp7jvai861vfs%40group.calendar.google.com&ctz=Europe%2FPrague
Expand Down
26 changes: 18 additions & 8 deletions hooks/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ def fetch_events(days_limit: int | None = None, past: bool = False) -> list[dict
for event_data in parse_icalendar(feed["data"])
]
)
elif feed["format"] == "json-dl":
elif feed["format"] == "meetupcom":
events.extend(
[
dict(feed=feed, **event_data)
for event_data in parse_json_dl(feed["data"], feed["url"])
for event_data in parse_meetupcom(feed["data"], feed["url"])
]
)
else:
Expand Down Expand Up @@ -115,31 +115,41 @@ def parse_icalendar(text: str) -> list[dict]:
starts_at=to_prague_tz(event.begin),
ends_at=to_prague_tz(event.end) if event.end else None,
location=event.location,
url=event.url if event.url else find_first_url(event.description),
url=event.url if event.url else find_first_url(event.description or ""),
is_tentative="tentative-date" in event.categories,
)
for event in ics.Calendar(text).events
]


def parse_json_dl(html: str, base_url: str) -> list[dict]:
def parse_meetupcom(html: str, base_url: str) -> list[dict]:
response = requests.get(base_url)
events = teemup.parse(response.text)
events: list[teemup.Event] = teemup.parse(response.text)
return [
dict(
name=event["title"],
starts_at=event["starts_at"],
ends_at=event["ends_at"],
location=event["venue"],
location=parse_meetupcom_venue(event["venue"]) if event["venue"] else None,
url=event["url"],
is_tentative=False,
)
for event in events
]


def parse_json_dl_location(location: dict[str, str]) -> str:
return f"{location['name']}, {location['address']['streetAddress']}, {location['address']['addressLocality']}, {location['address']['addressCountry']}"
def parse_meetupcom_venue(location: teemup.Venue) -> str:
return ", ".join(
filter(
None,
[
location["name"],
location["address"],
location["city"],
location["country"],
],
)
)


def to_prague_tz(dt: datetime) -> datetime:
Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ mkdocs-material = "9.5.39"
strictyaml = "1.7.3"
ics = {version = "0.8.0.dev0", allow-prereleases = true}
requests = "2.32.3"
teemup = "1.1.0"
mkdocs = "1.6.1"
teemup = "1.1.1"

[tool.poetry.group.dev.dependencies]
pytest = "8.3.2"
Expand Down

0 comments on commit 85c3feb

Please sign in to comment.