from datetime import datetime from bs4 import BeautifulSoup from icalendar import Calendar, Event import pytz file = open('index.html', 'r') page = file.read() cal = Calendar() def handleFilm(p) : title = p.find('a', {'class':'Film_title'}) print(title.string) runtime = p.find('div', {'class':'Film_runtime'}) time = p.find('span', {'class': 'start_time'}) # Starts at 05:15 PM EST on May 29 time_formatted = datetime.strptime(time.string, "Starts at %I:%M %p EST on %B %d") time_formatted = time_formatted.replace(year=2020) tz_time = pytz.timezone('US/Eastern') tz_time.localize(time_formatted) print(time_formatted) print("Europe : " + str(tz_time)) summary = p.find('div', {'class' : 'Film_summary'}) event = Event() event.add('description', summary.string) event.add('summary', title.string) event.add('dtstart', time_formatted) cal.add_component(event) soup = BeautifulSoup(page) for p in soup.find_all('div', {'class': 'Film'}): handleFilm(p) f = open("waoff-calendar.ics", 'wb') f.write(cal.to_ical()) f.close()