diff options
author | pixelexplosion | 2019-12-28 17:20:11 +0100 |
---|---|---|
committer | pixelexplosion | 2019-12-28 17:20:11 +0100 |
commit | 9ab9b43476dee0e85c6fd277ca5acb49a4cea87f (patch) | |
tree | 9c0972a6b9b86d27316b888f1a63f0d5789e9282 /parser/schedule.py | |
parent | f62a6417e1c8b791efa249b1984346726c0bacbd (diff) | |
parent | be7194cac8a87fc7ddb525db67c53dd8154d0717 (diff) |
Merge remote-tracking branch 'origin/master'
# Conflicts:
# app.py
Diffstat (limited to 'parser/schedule.py')
-rw-r--r-- | parser/schedule.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/parser/schedule.py b/parser/schedule.py new file mode 100644 index 0000000..30bb74e --- /dev/null +++ b/parser/schedule.py @@ -0,0 +1,51 @@ +import config +import requests + +class ScheduleParser(): + def parse(self, params: dict, do_req: bool = True, l: list = []) -> list: + if do_req: + l = self.__get_data() + + param_name = list(params.keys())[0] + param_value = params[param_name] + del params[param_name] + + confs = [] + + if param_name == 'speaker': + for conference in l: + for person in conference['persons']: + if param_value.lower() in person['public_name'].lower(): + confs.append(conference) + break + + elif param_name == 'room': + for conference in l: + if param_value.lower() in conference['room'].lower(): + confs.append(conference) + + elif param_name == 'time': + for conference in l: + if conference['start'].lower() == param_value.lower(): + confs.append(conference) + + elif param_name == 'title': + for conference in l: + if param_value.lower() in conference['abstract'].lower(): + confs.append(conference) + + + + if len(list(params.keys())) > 0: + return self.parse(params, False, confs) + return confs + + def __get_data(self) -> list: + resp = requests.get(config.SCHEDULE_URL) + elements = [] + for day in resp.json()['schedule']['conference']['days']: + for room in day['rooms']: + for conference in day['rooms'][room]: + elements.append(conference) + return elements + |