fedora-schedule/fedora_schedule.py

60 lines
2.0 KiB
Python

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"
self.schedule_tasks = self._get_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.schedule_tasks
for task in tasks:
if int(task['start']) < today and today < int(task ['end']):
state = task['name']
return f"Fedora {self.release_version}: {state}"
def _get_release(self):
release = {}
release_date = None
tasks = self.schedule_tasks
for task in tasks:
if 'current_final_target_date' in task['slug']:
release_date = time.strftime('%Y-%m-%d', time.gmtime(int(task['end'])))
release = {
'name': task['name'],
'date': release_date
}
return release
def release(self):
release = self._get_release()
return f"{release['name']} is {release['date']}"
def release_date(self):
release = self._get_release()
return release['date']