Skip to content

Added ical export for your favorites #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions favorites-ical.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import requests
from bs4 import BeautifulSoup
from datetime import datetime
import pytz
from pytz import timezone
from icalendar import Calendar, vText, Event
import json

base_url = "https://www.portal.reinvent.awsevents.com/connect/"
favorites_url = "https://www.portal.reinvent.awsevents.com/connect/interests.ww"
login_url = "https://www.portal.reinvent.awsevents.com/connect/processLogin.do"
scheduling_url = "https://www.portal.reinvent.awsevents.com/connect/dwr/call/plaincall/ConnectAjax.getSchedulingJSON.dwr"
vegas = timezone("US/Pacific")

# Set username and password for reinvent event website
USERNAME = 'YOUR_USERNAME'
PASSWORD = 'YOUR_PASSWORD'

# login and start a session
session = requests.session()
payload = {"password": PASSWORD, "username": USERNAME }
resp = session.post(login_url, data=payload)

# get all the favorites
resp = session.get(favorites_url)
html = resp.content
soup = BeautifulSoup(html, "html.parser")

# find all selected sessions
selected_sessions = soup.findAll("div", {"class": "sessionRow"})

session_data = []

# loop through all sessions, and gather the needed information
for selected_session in selected_sessions:
# get the link
link = selected_session.find("a", {"class": "openInPopup"})
url = link['href']

# get the session title
title = link.find("span", {"class": "title"}).text

# get the abstract
abstract = selected_session.find("span", {"class": "abstract"}).text
session_url = "%s%s" % (base_url, url)

# this contains the session id (int)
session_id = url.split("=")[-1]

# get the scheduling information and location from the magic json url
payload = {
"callCount":"1",
"windowName":"",
"c0-scriptName":"ConnectAjax",
"c0-methodName":"getSchedulingJSON",
"c0-id":"0",
"c0-param0":"string:%s" % session_id,
"batchId":"4",
"instanceId":"0",
"page":"%2Fconnect%2Finterests.ww",
"scriptSessionId":"OGxWNAOpsVunFAFyWddX2cGpNYl/RTNxNYl-Roe8DFsEq",
}
resp = session.post(scheduling_url, data=payload)

# do some magic and actually get the escaped json
json_response = resp.content.split("\n")[5].replace('r.handleCallback("4","0","',"").replace('");',"").replace('\\"','"').replace("\\'","'")
schedule_data = json.loads(json_response)['data'][0]
print "."


# Friday, Dec 1, 9:15 AM
# print schedule_data
start_dt = datetime.strptime(schedule_data['startTime'], '%A, %b %d, %I:%M %p').replace(year=2017, tzinfo=vegas)
schedule_data['startDatetime'] = start_dt
end_dt = datetime.strptime(schedule_data['endTime'], '%I:%M %p').replace(day=start_dt.day, month=start_dt.month, year=2017, tzinfo=vegas)
schedule_data['endDatetime'] = end_dt

session_data.append({
"title": title,
"abstract": abstract,
"link": link,
"schedule": schedule_data
})

# ok, we have everything we need, now generate an ical file
cal = Calendar()
cal.add('prodid', '-//Re-Invent plan generator product//mxm.dk//')
cal.add('version', '2.0')
for session in session_data:
event = Event()
event.add('summary', session['title'].replace("'","\'"))
event.add('description', session['abstract'])
event.add('location', session['schedule']['room'])
event.add('dtstart', session['schedule']['startDatetime'])
event.add('dtend', session['schedule']['endDatetime'])
# event.add('url', session['link'])
event.add('dtstamp', session['schedule']['startDatetime'])
cal.add_component(event)

# write the ical file
with open("reinvent.ics","w") as f:
f.write(cal.to_ical())
12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
beautifulsoup4==4.6.0
bs4==0.0.1
certifi==2017.7.27.1
chardet==3.0.4
icalendar==3.11.7
idna==2.6
python-dateutil==2.6.1
pytz==2017.2
requests==2.18.4
selenium==3.6.0
six==1.11.0
urllib3==1.22