From 080c5aabff474ddbd679ce44e877028f9b2bf0d2 Mon Sep 17 00:00:00 2001 From: Klafyvel Date: Tue, 5 Dec 2017 20:05:36 +0100 Subject: [PATCH] Va chercher sur NTNOE --- main.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index 0691d36..962f760 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,8 @@ import datetime import httplib2 import urllib import os +import requests +import shutil from apiclient import discovery from oauth2client import client @@ -95,21 +97,17 @@ def get_ntnoe(): url = "http://ntnoe.metz.supelec.fr/ical/EdTcustom/Eleves/edt_{}.ics" url = url.format(NTNOE_ID) - h = httplib2.Http() - h.add_credentials(NTNOE_ID,NTNOE_PASS) - data = {'envoyer':'Utf8_All','submit':'G%E9n%E9rer'} + data = {'envoyer':'Utf8_All','submit':'Générer'} - h.request( + r = requests.get( "https://ntnoe.metz.supelec.fr/ical/index.php", - body=urllib.parse.urlencode(data), - method='POST', + data=urllib.parse.urlencode(data), + auth=(NTNOE_ID, NTNOE_PASS), ) - # resp,content = h.request( - # "https://ntnoe.metz.supelec.fr/ical/EdTcustom/Eleves/edt_{id}.ics".format(id=NTNOE_ID), - # ) - # print(resp,content) - # TODO : download from ntnoe - + url = "https://ntnoe.metz.supelec.fr/ical/EdTcustom/Eleves/edt_{id}.ics".format(id=NTNOE_ID) + r = requests.get(url, auth=(NTNOE_ID, NTNOE_PASS), stream=True) + with open("edt_{}.ics".format(NTNOE_ID), 'wb') as f: + f.write(r.content) def main(): @@ -126,9 +124,10 @@ def main(): now = datetime.datetime.now() then = now + TIMEDELTA_SYNCHRO + time_search = datetime.datetime(now.year, now.month, now.day, 1) response = service.events().list( calendarId='primary', - timeMin=now.isoformat()+'Z', + timeMin=time_search.isoformat()+'Z', timeMax=then.isoformat()+'Z', ).execute() @@ -149,8 +148,6 @@ def main(): if existing_events.intersection({event.summary}): continue - else: - print(event.summary) event = service.events().insert( calendarId='primary',