initial commit
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import requests
|
||||
from icalendar import Calendar, Event
|
||||
from datetime import datetime
|
||||
from collections import defaultdict
|
||||
|
||||
# Send multiple POST requests to fetch schedule data
|
||||
url = "https://www.eventeny.com/funcs/event/event-page-elements-2022-03-06.php"
|
||||
base_form_data = {
|
||||
"post_type": "fetch_schedule_list",
|
||||
"biz_id": "233997",
|
||||
"event_id": "13462",
|
||||
"tag_filter": "",
|
||||
"track_filter": "50949|50946|50955|50947|50954|50950|53643|53642|50956|50948",
|
||||
"embed": "1"
|
||||
}
|
||||
|
||||
# why are the values here stupid and arbitrary? why does only the first request use date_group_setup 0?
|
||||
# why do we send three requests when the time limits for the first clearly span the whole event?
|
||||
# what are they hiding? who the hell knows? i just scraped it off the sakuracon site
|
||||
requests_data = [
|
||||
{**base_form_data, "date_group_setup": "0", "time_limit_min": "1744948800", "time_limit_max": "1745207999"},
|
||||
{**base_form_data, "date_group_setup": "1", "time_limit_min": "1745035200", "time_limit_max": "1745121599"},
|
||||
{**base_form_data, "date_group_setup": "1", "time_limit_min": "1745121600", "time_limit_max": "1745207999"}
|
||||
]
|
||||
|
||||
all_events = []
|
||||
all_tracks = {}
|
||||
|
||||
for form_data in requests_data:
|
||||
response = requests.post(url, data=form_data)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
all_events.extend(data['list'])
|
||||
all_tracks.update(data['track'])
|
||||
|
||||
# Group events by track_title
|
||||
calendars = defaultdict(Calendar)
|
||||
|
||||
for event in all_events:
|
||||
track_id = event.get("tag_id")
|
||||
track_title = all_tracks.get(track_id)
|
||||
|
||||
cal = calendars[track_title]
|
||||
|
||||
# Initialize calendar if empty
|
||||
if not cal.get("prodid"):
|
||||
cal.add("prodid", f"-//{track_title} Schedule - SC//")
|
||||
cal.add("version", "2.0")
|
||||
cal.add("X-WR-CALNAME", track_title)
|
||||
|
||||
# Retrieve description for event
|
||||
form_data = {
|
||||
"post_type": "fetch_schedule_item",
|
||||
"biz_id": "233997",
|
||||
"event_id": "13462",
|
||||
"ticket_cross_sell": "no",
|
||||
"id": event["id"],
|
||||
}
|
||||
response = requests.post(url, data=form_data)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
desc = data["schedule"]["overview"]["description"]
|
||||
tags_str = ""
|
||||
|
||||
# Create event
|
||||
ical_event = Event()
|
||||
ical_event.add("summary", event['title'])
|
||||
ical_event.add("dtstart", datetime.fromisoformat(event['start_calendar']))
|
||||
ical_event.add("dtend", datetime.fromisoformat(event['end_calendar']))
|
||||
ical_event.add("location", event['location'].replace('&', '&'))
|
||||
ical_event.add("status", event['status'].upper())
|
||||
|
||||
# Add hashtags as categories if available
|
||||
if 'hashtag_title' in event and event['hashtag_title']:
|
||||
ical_event.add('categories', event['hashtag_title'])
|
||||
tags_str = f"Tags: {','.join(event['hashtag_title'])}\n"
|
||||
|
||||
ical_event.add("description", f"Track: {track_title}\n{tags_str}\n{desc}")
|
||||
|
||||
cal.add_component(ical_event)
|
||||
|
||||
# Write out each calendar to a .ics file
|
||||
for track_title, cal in calendars.items():
|
||||
filename = f"calendar_{track_title.replace(' ', '_')}.ics"
|
||||
with open(filename, 'wb') as f:
|
||||
f.write(cal.to_ical())
|
||||
print(f"Wrote: {filename}")
|
||||
Reference in New Issue
Block a user