From 5cbcb2e6f2dc7107dde6e5bef542c67793b7e1a3 Mon Sep 17 00:00:00 2001 From: jkhsjdhjs Date: Mon, 17 Jul 2023 01:07:44 +0000 Subject: [PATCH] fix .nextrocket trigger --- bert.py | 4 ++-- launch.py | 59 +++++++++++-------------------------------------------- 2 files changed, 14 insertions(+), 49 deletions(-) diff --git a/bert.py b/bert.py index 7345f24..a6c8214 100755 --- a/bert.py +++ b/bert.py @@ -172,8 +172,8 @@ def getMessage(): def getRocket(): - rocket, mission, status, delta = launch.next_launch() - rstring = "%sNext rocket: %s%s %s| %s%s %s| %sStatus: %s %s| %s%s" % (b, y, rocket, b, y, mission, b, y, status, b, y, delta) + rocket, mission, delta = launch.next_launch() + rstring = "%sNext rocket: %s%s %s| %s%s %s| %s%s" % (b, y, rocket, b, y, mission, b, y, delta) return rstring diff --git a/launch.py b/launch.py index 970cee4..ad4cf8b 100644 --- a/launch.py +++ b/launch.py @@ -10,61 +10,34 @@ from string import Template b = "\x0312" y = "\x038" -API_URL = "https://launchlibrary.net/1.2/launch/next/1" +API_URL = "https://fdo.rocketlaunch.live/json/launches/next/1" class launch(object): def api_request(self): request = urllib.request.Request(API_URL) response = urllib.request.urlopen(request).read() json_data = json.loads(response.decode('UTF-8')) - return json_data['launches'][0] + return json_data['result'][0] def rocket_name(self, json_data): try: - name = json_data['rocket']['name'] + name = json_data['vehicle']['name'] except: name = "UNKNOWN" return name def mission_name(self, json_data): try: - name = json_data['missions'][0]['name'] + name = json_data['name'] except: name = "UNKNOWN" return name def net_raw_utc(self, json_data): - time_utc_string = json_data['net'] - try: - time_utc = datetime.datetime.strptime(time_utc_string, '%B %d, %Y %H:%M:%S %Z') - except TypeError: - time_utc = datetime.datetime(*(time.strptime(time_utc_string, '%B %d, %Y %H:%M:%S %Z')[0:6])) + time_utc_string = json_data['t0'] + time_utc = datetime.datetime.fromisoformat(time_utc_string) return time_utc - def net(self, json_data): - time_utc_string = json_data['net'] - try: - time_utc = datetime.datetime.strptime(time_utc_string, '%B %d, %Y %H:%M:%S %Z') - except TypeError: - time_utc = datetime.datetime(*(time.strptime(time_utc_string, '%B %d, %Y %H:%M:%S %Z')[0:6])) - time_local = pytz.utc.localize(time_utc).astimezone(pytz.timezone('Europe/Berlin')) - time = datetime.datetime.strftime(time_local, 'NET %d.%m.%Y') - return time - - def get_status(self, json_data): - tbd_stat = json_data['tbdtime'] - hold_stat = json_data['inhold'] - go_stat = json_data['status'] - if tbd_stat == 1: - status = "TBD" - elif hold_stat == 1: - status = "HOLD" - elif go_stat == 1: - status = "GO" - else: - status = "UNKNOWN" - return status - class DeltaTemplate(Template): delimiter = "%" @@ -86,18 +59,10 @@ def next_launch(): json_data = l.api_request() rocket = l.rocket_name(json_data) mission = l.mission_name(json_data) - status = l.get_status(json_data) - if status != "GO": - deltastring = l.net(json_data) - else: - launch_time = l.net_raw_utc(json_data) - now = datetime.datetime.utcnow().replace(microsecond=0) - if launch_time > now: - timedelta = launch_time - now - t_string = "-" - else: - timedelta = now - launch_time - t_string = "+" - deltastring = strfdelta(timedelta, "T"+t_string+"%D:%H:%M:%S") + launch_time = l.net_raw_utc(json_data) + now = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0) + timedelta = abs(launch_time - now) + t_string = "-" if launch_time > now else "+" + deltastring = strfdelta(timedelta, "T"+t_string+"%D:%H:%M:%S") del l - return rocket, mission, status, deltastring + return rocket, mission, deltastring