Skip to content

Commit

Permalink
Merge pull request #582 from pyvec/honzajavorek/fix-events
Browse files Browse the repository at this point in the history
Fix events
  • Loading branch information
honzajavorek authored Oct 18, 2024
2 parents 40b4bba + fc999a5 commit d31f92c
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 188 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
Loading

0 comments on commit d31f92c

Please sign in to comment.