Commit a271d8a6 authored by Kiste's avatar Kiste
Browse files

Seperate function

parent bb232d61
......@@ -21,8 +21,12 @@ def main():
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 = (args.user, args.password)
session.auth = (user, password)
fg = FeedGenerator()
fg.id('https://studip.uni-hannover.de/')
fg.title('Stud.IP LUH')
......@@ -30,20 +34,20 @@ def main():
fg.logo('https://studip.uni-hannover.de/assets/images/favicon.png')
fg.language('de')
json_semester = session.get(BASEURL + '/courses/semester')
json_semester = session.get(BASEURL + '/courses/semester').json()
latest = None
for semester in json_semester.json()['semesters']:
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'])
for course in json_courses.json()['courses']:
json_news = session.get(BASEURL + '/news/range/' + course['course_id'])
for news in json_news.json()['news']:
json_user = session.get(BASEURL + '/user/' + news['user_id'])
author = json_user.json()['user']
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'])
......@@ -53,4 +57,4 @@ def main():
fe.title(str.join('', ('[', course['title'], '] ', news['topic'])))
fe.updated(news['iso_chdate'])
fg.atom_file(args.output)
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