diff --git a/parse.py b/parse.py index c388532..82b5e0f 100755 --- a/parse.py +++ b/parse.py @@ -1,11 +1,20 @@ #!/usr/bin/env python3 +import sys +import argparse import datetime +import urllib.request from icalendar import Calendar from Edt import * -htmlHandle = open('groupe12.html', 'rb') -htmlStr = htmlHandle.read().decode('iso-8859-15') +# Parse command line arguments +parser = argparse.ArgumentParser(description='Convertit l\'emploi du temps IMA3 en ICS') +parser.add_argument('edt', metavar='EDT', type=str, help='la page pointant vers l\'emploi du temps concerné') +parser.add_argument('-o', '--output', dest='file', type=str, default='-', help='fichier de sortie, - pour stdout') +args = parser.parse_args() + +with urllib.request.urlopen('http://dptima3.polytech-lille.net/' + args.edt + '.html') as handle: + htmlStr = handle.read().decode('iso-8859-15') # Read HTML tables parser = TableHTMLParser() @@ -45,10 +54,6 @@ for parserTable in parser.tables: x = 0 y += 1 - #for line in table: - # print(' | '.join([str(cell) for cell in line])) - #print('-'*20) - tables.append(table) # Creating events @@ -103,11 +108,14 @@ cal.add('version', '2.0') for event in events: if event.active: - print(event) + print(event, file=sys.stderr) cal.add_component(event.getEvent()) # Writing calendar to file -f = open('groupe12.ics', 'wb') -f.write(cal.to_ical()) -f.close() +data = cal.to_ical() +if args.file == '-': + sys.stdout.write(data.decode('utf-8')) +else: + with open(args.file, 'wb') as f: + f.write(data) -- libgit2 0.21.2