Created
September 6, 2012 18:52
-
-
Save jakobwenzel/3659428 to your computer and use it in GitHub Desktop.
Tucan-Stundenplan Export: Mehrere Monate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#======================================= | |
# Configure Options here | |
#======================================= | |
username = "TU-ID hier" | |
password = "Passwort hier" | |
firstYear = 2012 | |
firstMonth = 10 | |
lastYear = 2013 | |
lastMonth = 04 | |
outputFile = 'calendar.ics' | |
#======================================= | |
# End of Config options | |
#======================================= | |
from twill.commands import * | |
config("readonly_controls_writeable","true") | |
#Go to TuCan | |
go("http://www.tucan.tu-darmstadt.de") | |
#Enter username and password | |
formvalue(1,"usrname",username) | |
formvalue(1,"pass",password) | |
#Login | |
submit() | |
#Navigate to Export | |
follow("Stundenplan") | |
follow("Export") | |
month = firstMonth | |
year = firstYear | |
calendar = "" | |
preamble = "" | |
while month <= lastMonth or year<lastYear: | |
print "Fetching data for "+str(month)+"."+str(year) | |
if month<10: | |
monthStr = "0"+str(month) | |
else: | |
monthStr = str(month) | |
#Enter month | |
formvalue(1,"date","Y"+str(year)+"M"+monthStr) | |
submit() | |
try: | |
follow("Kalenderdatei") | |
content = get_browser().get_html() | |
#Find important parts | |
begin = content.find("BEGIN:VEVENT") | |
end = content.find("END:VCALENDAR") | |
#Save preamble for later use | |
preamble = content[:begin] | |
#Add to Calendar | |
calendar = calendar + content[begin:end] | |
#Back to Month Selection Form | |
back() | |
#Exception should only occurr if there are no events and therefore | |
#no link "Kalenderdatei" | |
except: | |
print "No events for this month" | |
back() | |
#Go to next month | |
month+=1 | |
if month>12: | |
month=1 | |
year+=1 | |
#Add Preamble and end | |
calendar = preamble + calendar + "END:VCALENDAR" | |
#Write to file | |
f = open(outputFile, 'w') | |
f.write(calendar) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i like 👍