Commit 9857a06d authored by Maxime Bombar's avatar Maxime Bombar

Export the whole year

parent 0a462502
......@@ -64,12 +64,30 @@ def format(days):
day = []
for cls in days[i]:
clas = {}
clas['time'] = cls[0].string
clas['type'] = cls[1].string
clas['topic'] = cls[2].string
clas['prof'] = cls[3].string
clas['room'] = cls[4].string
clas['title'] = cls[5].string.replace('č', 'è')
try:
clas['time'] = cls[0].string
except:
pass
try:
clas['type'] = cls[1].string
except:
pass
try:
clas['topic'] = cls[2].string
except:
pass
try:
clas['prof'] = cls[3].string
except:
pass
try:
clas['room'] = cls[4].string
except:
pass
try:
clas['title'] = cls[5].string.replace('č', 'è')
except:
pass
day.append(clas)
pretty_days.append(day)
return pretty_days
......@@ -79,17 +97,17 @@ def pretty_print(days, date):
"""
Display the week schedule
"""
for i in range(1,6):
for i in range(len(days)):
day_date = datetime.datetime.strptime(
datetime.datetime.strptime(
date, '%y-%m-%d'
).strftime('%y-W%W') + '-%s' % i, '%y-W%W-%w'
).strftime('%y-W%W') + '-%s' % (i%6+1), '%y-W%W-%w'
).strftime("%A %B %d, %Y")
print("----------------------------------")
print(" %s:" % day_date)
print("----------------------------------")
for clas in days[i-1]:
for clas in days[i]:
print(clas['time'])
print(clas['type'])
print(clas['topic'])
......@@ -108,15 +126,15 @@ def fill_calendar(c, days, date):
"""
Fill calendar with events for each class
"""
for i in range(1,6):
for i in range(len(days)):
day_date = datetime.datetime.strptime(
datetime.datetime.strptime(
date, '%y-%m-%d'
).strftime('%y-W%W') + '-%s' % i, '%y-W%W-%w'
).strftime('%y-W%W') + '-%s' % (i%6+1), '%y-W%W-%w'
)
for clas in days[i-1]:
for clas in days[i]:
e = Event()
start, end = get_time(clas)
......@@ -138,7 +156,10 @@ def fill_calendar(c, days, date):
except:
m_end = 0
e.add('location', clas['room'])
try:
e.add('location', clas['room'])
except:
pass
summary = ''
try:
summary += clas['type'] + '\n'
......@@ -187,32 +208,67 @@ if __name__ == '__main__':
action="store_true",
)
parser.add_argument(
"-a", "--all",
help="export the whole year",
action="store_true",
)
args = parser.parse_args()
date = datetime.datetime.strptime(
datetime.datetime.strptime(
args.date, '%y-%m-%d'
).strftime('%y-W%W') + '-1', "%y-W%W-%w").strftime('%y-%m-%d')
).strftime('%y-W%W') + '-1', "%y-W%W-%w")
http = urllib3.PoolManager()
request = http.request('GET', 'http://agreg.cmla.ens-cachan.fr/edt.php?option=in&sem=%s&suff=' % (date,))
html = request.data
soup = BeautifulSoup.BeautifulSoup(html, 'lxml') # Create the soup
regex = re.compile('[0-9]*h[0-9]*-[0-9]*h[0-9]*') # regex time
a = soup.find_all('big')[57:] # Fetch "Big" tags, begins from first class on Monday
if not args.all:
date = date.strftime('%y-%m-%d')
request = http.request('GET', 'http://agreg.cmla.ens-cachan.fr/edt.php?option=in&sem=%s&suff=' % (date,))
html = request.data
soup = BeautifulSoup.BeautifulSoup(html, 'lxml') # Create the soup
regex = re.compile('[0-9]*h[0-9]*-[0-9]*h[0-9]*') # regex time
schedule = get_schedule(a)
a = soup.find_all('big')[57:] # Fetch "Big" tags, begins from first class on Monday
schedule = get_schedule(a)
days = pretty_schedule(schedule)
days = pretty_schedule(schedule)
if args.pretty:
pretty_print(days, date)
if args.pretty:
pretty_print(days, date)
else:
c = Calendar()
fill_calendar(c, days, date)
print(c.to_ical().decode('utf-8'))
else:
# fetch every week !
c = Calendar()
fill_calendar(c, days, date)
while date.month < 7 or date.year == 2018:
date_str = date.strftime('%y-%m-%d')
request = http.request('GET', 'http://agreg.cmla.ens-cachan.fr/edt.php?option=in&sem=%s&suff=' % (date_str,))
html = request.data
soup = BeautifulSoup.BeautifulSoup(html, 'lxml') # Create the soup
a = soup.find_all('big')[57:] # Fetch "Big" tags, begins from first class on Monday
schedule = get_schedule(a)
days = pretty_schedule(schedule)
fill_calendar(c, days, date_str)
date += datetime.timedelta(weeks=1)
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