From 39c8978a49d3b6971dc0c289915a9e24b30d9407 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Sat, 23 Dec 2023 09:53:30 +0100 Subject: [PATCH] On produit un fichier json permettant l'import --- experimentations/get_ical_events.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/experimentations/get_ical_events.py b/experimentations/get_ical_events.py index d417bda..1ec6129 100755 --- a/experimentations/get_ical_events.py +++ b/experimentations/get_ical_events.py @@ -11,7 +11,7 @@ from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options import icalendar from datetime import datetime, date - +import json @@ -164,7 +164,7 @@ class ICALExtractor(Extractor): location = self.get_item_from_vevent(event, "LOCATION") if location is None: - location = Zself.default_value_if_exists(default_values, "location") + location = self.default_value_if_exists(default_values, "location") description = self.get_item_from_vevent(event, "DESCRIPTION") @@ -196,7 +196,7 @@ class URL2Events: self.downloader = downloader self.extractor = extractor - def process(self, url, url_human = None, cache = None, default_values = None): + def process(self, url, url_human = None, cache = None, default_values = None, published = False): if cache and os.path.exists(cache): print("Loading cache ({})".format(cache)) @@ -213,7 +213,7 @@ class URL2Events: with open(cache, "w") as text_file: text_file.write(content) - return self.extractor.extract(content, url, url_human, default_values) + return self.extractor.extract(content, url, url_human, default_values, published) if __name__ == "__main__": @@ -224,4 +224,7 @@ if __name__ == "__main__": events = u2e.process(url, url_human, cache = "cache-augustes.ical", default_values = {"category": "Autre", "location": "Café lecture les Augustes"}, published = True) - #print(events) \ No newline at end of file + exportfile = "events-augustes.json" + print("Saving events to file {}".format(exportfile)) + with open(exportfile, "w") as f: + json.dump(events, f, indent=4, default=str)