from ics import Calendar import requests, arrow, logging, os # VARIABLES log_file = "logfile" url = "https://0783636d.index-education.net/pronote/ical/Agenda.ics?icalsecurise=3972E4CB6D2FF1DE199B75C1969DC54C867D1CA9A09B1C797A0342D5A2749FD9695E01FD2EE008B66074C8A9C38FB737&version=2021.0.2.3¶m=66683d31266f3d31" dates_file = "dates.txt" proxy = {"https":"http://172.17.212.1:3128"} logging.basicConfig(level=logging.INFO, filename=os.path.join(os.path.dirname(__file__),log_file), filemode="a+",format="%(asctime)-15s %(levelname)-8s %(message)s") try: c = Calendar(requests.get(url,proxies=proxy).text) e = list(c.timeline.start_after(arrow.utcnow().to('Europe/Paris'))) except Exception: logging.error("Erreur lors de l'accès au calendrier ! script annulé") exit() try: f = open(os.path.join(os.path.dirname(__file__),dates_file), "w") for x in e: if x.name.casefold() == "lire ensemble": print(x.begin, file=f) print(x.end, file=f) f.close() logging.info("Fichier mis à jour le {}".format(arrow.utcnow().to('Europe/Paris').format('YYYY-MM-DD HH:mm'))) except IOError: logging.error("Erreur de lecture/ecriture")