Commit 10a17e88 authored by Kiste's avatar Kiste
Browse files

Oops

parent 83072f7d
# -*- coding: utf-8 -*-
"""
This program is free software. It comes without any warranty, to the extent
permitted by applicable law. You can redistribute it and/or modify it under the
terms of the Do What The Fuck You Want To Public License, Version 2, as
published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
"""
import argparse
import requests
from feedgen.feed import FeedGenerator
BASEURL = 'https://studip.uni-hannover.de/plugins.php/restipplugin/api'
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-u', '--user', help='Stud.IP Benutzername', required=True)
parser.add_argument('-p', '--password', help='Stud.IP Passwort', required=True)
parser.add_argument('-o', '--output', help='Datei, in die der ATOM-Feed geschrieben wird', required=True)
args = parser.parse_args()
generate_feed(args.user, args.password).atom_file(args.output)
def generate_feed(user, password):
session = requests.Session()
session.auth = (user, password)
fg = FeedGenerator()
fg.id('https://studip.uni-hannover.de/')
fg.title('Stud.IP LUH')
fg.link(href='https://studip.uni-hannover.de/', rel='alternate')
fg.logo('https://studip.uni-hannover.de/assets/images/favicon.png')
fg.language('de')
json_semester = session.get(BASEURL + '/courses/semester').json()
latest = None
for semester in json_semester['semesters']:
if not latest:
latest = semester
else:
if semester['begin'] > latest['begin']:
latest = semester
json_courses = session.get(BASEURL + '/courses/semester/' + latest['semester_id']).json()
for course in json_courses['courses']:
json_news = session.get(BASEURL + '/news/range/' + course['course_id']).json()
for news in json_news['news']:
json_user = session.get(BASEURL + '/user/' + news['user_id']).json()
author = json_user['user']
fe = fg.add_entry()
fe.author(name=str.join(' ', filter(None, (author['title_pre'], author['forename'], author['lastname']))),
email=author['email'])
fe.content(news['body'], type='html')
fe.id(news['news_id'])
fe.published(news['iso_mkdate'])
fe.title(str.join('', ('[', course['title'], '] ', news['topic'])))
fe.updated(news['iso_chdate'])
return fg
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment