diff --git a/src/agenda_culturel/importation.py b/src/agenda_culturel/importation.py index 6b07b52..d4da385 100644 --- a/src/agenda_culturel/importation.py +++ b/src/agenda_culturel/importation.py @@ -12,18 +12,36 @@ class EventsImporter: try: structure = json.loads(json_structure) - - self.url = structure["header"]["url"] - self.date = structure["header"]["date"] except: return (False, "JSON file is not correctly structured") + if not "header" in structure: + return (False, "JSON is not correctly structured: missing header") + + if "url" in structure["header"]: + self.url = structure["header"]["url"] + else: + return (False, "JSON is not correctly structured: missing url in header") + + if "url" in structure["header"]: + self.date = structure["header"]["date"] + # load events for event in structure["events"]: self.import_event(event) + # update object with infos from header, and with the list of imported objects + # TODO + + # events that are missing from the import but in database are turned into drafts + # TODO + + return (True, "") + def import_event(self, event): + # TODO + pass