Commit 8a7a50dc authored by Maxime Bombar's avatar Maxime Bombar

Export ics

parent 7a4f5f97
......@@ -8,12 +8,12 @@ Dependencies :
"""
import bs4 as BeautifulSoup
import urllib3
import datetime
import icalendar
from icalendar import Calendar, Event
import re
......@@ -99,6 +99,72 @@ def pretty_print(days, date):
print("\n")
print('\n')
def get_time(clas):
time = clas['time']
l = re.findall(r"[\w']+", time)
return l[0], l[1]
def fill_calendar(c, days, date):
"""
Fill calendar with events for each class
"""
for i in range(1,6):
day_date = datetime.datetime.strptime(
datetime.datetime.strptime(
date, '%y-%m-%d'
).strftime('%y-W%W') + '-%s' % i, '%y-W%W-%w'
)
for clas in days[i-1]:
e = Event()
start, end = get_time(clas)
try:
h_start = int(start.split('h')[0])
except:
h_start = 0
try:
m_start = int(start.split('h')[1])
except:
m_start = 0
try:
h_end = int(end.split('h')[0])
except:
h_end = 0
try:
m_end = int(end.split('h')[1])
except:
m_end = 0
e.add('location', clas['room'])
summary = ''
try:
summary += clas['type'] + '\n'
except:
pass
try:
summary += clas['topic'] + '\n'
except:
pass
try:
summary += clas['prof'] + '\n'
except:
pass
try:
summary += clas['title'] + '\n'
except:
pass
e.add('summary', summary)
dtstart = day_date.replace(hour=h_start, minute=m_start)
dtend = day_date.replace(hour=h_end, minute=m_end)
e.add('dtstart', dtstart)
e.add('dtend', dtend)
c.add_component(e)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Fetch calendar from agreg.cmla.ens-cachan.fr', add_help=True)
......@@ -115,6 +181,11 @@ if __name__ == '__main__':
action="store_true",
)
parser.add_argument(
"-i", "--ics",
help="export ics",
action="store_true",
)
args = parser.parse_args()
......@@ -138,6 +209,12 @@ if __name__ == '__main__':
days = pretty_schedule(schedule)
days = format(days)
if args.pretty:
pretty_print(days, date)
c = Calendar()
fill_calendar(c, days, date)
pretty_print(days, date)
print(c.to_ical().decode('utf-8'))
Markdown is supported
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