From 2076cf2ce95483260018932fe6f835fa6c090201 Mon Sep 17 00:00:00 2001 From: Mark McIntyre Date: Mon, 12 Feb 2024 20:01:16 -0500 Subject: [PATCH] initial load --- .gitignore | 3 +++ __init__.py | 0 fedora_schedule.py | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 .gitignore create mode 100644 __init__.py create mode 100644 fedora_schedule.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..76d72de --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +.py[co] + diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/fedora_schedule.py b/fedora_schedule.py new file mode 100644 index 0000000..99e9648 --- /dev/null +++ b/fedora_schedule.py @@ -0,0 +1,38 @@ +import time +import requests +import json + + +class FedoraSchedule(): + def __init__(self, release_version=""): + self.release_version = str(release_version) + self.schedule_url = "https://fedorapeople.org/groups/schedule" + + def _parse_tasks(self, tasks, tasks_so_far=[]): + for _tasks in tasks: + if _tasks['_level'] < 3: + self._parse_tasks(_tasks['tasks'], tasks_so_far) + else: + if 'tasks' in _tasks.keys(): + self._parse_tasks(_tasks['tasks'], tasks_so_far) + tasks_so_far.append(_tasks) + return tasks_so_far + + def get_schedule(self): + release_schedule_url = f"{self.schedule_url.format(self.release_version)}/f-{self.release_version}/f-{self.release_version}-key.json" + schedule_json = json.loads(requests.get(release_schedule_url).content) + tasks = self._parse_tasks(schedule_json['tasks']) + return tasks + + def current_state(self): + state = "" + today = int(time.strftime("%s", time.gmtime())) + tasks = self.get_schedule() + + for task in tasks: + if int(task['start']) < today and today < int(task ['end']): + state = task['name'] + + return state + +