Skip to content

Instantly share code, notes, and snippets.

@twu
Created February 27, 2015 09:32
Show Gist options
  • Save twu/ed345ff2e67ba659bdd2 to your computer and use it in GitHub Desktop.
Save twu/ed345ff2e67ba659bdd2 to your computer and use it in GitHub Desktop.
A more "sophisticated" approach to using the TUGBox.
#!/usr/bin/env python
import urllib2
import json
if __name__ == '__main__':
# Computer Science (557), BSc. (140), Current "Studienjahr" (1034)
# .json -> simple json
# .js -> jsonp
# webcal:// ... /exams.ical -> iCalendar
url = 'http://tugbox.herokuapp.com/tug/curriculum/557,140,1034/exams.ical'
response = urllib2.urlopen(url)
for exam in json.load(response):
print exam['name'], exam['kind'], exam['location'], exam['starts'], exam['ends']
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="//code.jquery.com/jquery.min.js"></script>
</head>
<body>
<script>
$.ajax({
url: 'http://tugbox.herokuapp.com/tug/curriculum/557,140,1034/exams.js',
type: 'GET',
jsonpCallback: 'tugbox',
dataType: 'jsonp',
success: function(data) {
$.each(data, function(id) {
var exam = data[id];
starts = new Date(exam['starts'] * 1000);
url = 'https://online.tugraz.at/tug_online/wbregisterexam.lv_termine?cstp_sp_nr='+exam['id']+'&csort=0&cheader=J&pLvGroupFlag=J'
console.log(exam);
t = starts.toDateString() + ' <b>' + exam['name'] + '</b> <a href="'+ url +'">Anmeldung</a><br />'
$('#exams').append(t);
});
}
});
</script>
<pre id="exams"></pre>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment