fix .nextrocket trigger
This commit is contained in:
		
							
								
								
									
										4
									
								
								bert.py
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								bert.py
									
									
									
									
									
								
							| @@ -172,8 +172,8 @@ def getMessage(): | |||||||
|  |  | ||||||
|  |  | ||||||
| def getRocket(): | def getRocket(): | ||||||
|    rocket, mission, status, delta = launch.next_launch() |    rocket, mission, 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) |    rstring = "%sNext rocket: %s%s %s| %s%s %s| %s%s" % (b, y, rocket, b, y, mission, b, y, delta) | ||||||
|    return rstring |    return rstring | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										55
									
								
								launch.py
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								launch.py
									
									
									
									
									
								
							| @@ -10,61 +10,34 @@ from string import Template | |||||||
| b = "\x0312" | b = "\x0312" | ||||||
| y = "\x038" | 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): | class launch(object): | ||||||
|    def api_request(self): |    def api_request(self): | ||||||
|       request = urllib.request.Request(API_URL) |       request = urllib.request.Request(API_URL) | ||||||
|       response = urllib.request.urlopen(request).read() |       response = urllib.request.urlopen(request).read() | ||||||
|       json_data = json.loads(response.decode('UTF-8')) |       json_data = json.loads(response.decode('UTF-8')) | ||||||
|       return json_data['launches'][0] |       return json_data['result'][0] | ||||||
|  |  | ||||||
|    def rocket_name(self, json_data): |    def rocket_name(self, json_data): | ||||||
|       try: |       try: | ||||||
|          name = json_data['rocket']['name'] |          name = json_data['vehicle']['name'] | ||||||
|       except: |       except: | ||||||
|          name = "UNKNOWN" |          name = "UNKNOWN" | ||||||
|       return name |       return name | ||||||
|  |  | ||||||
|    def mission_name(self, json_data): |    def mission_name(self, json_data): | ||||||
|       try: |       try: | ||||||
|          name = json_data['missions'][0]['name'] |          name = json_data['name'] | ||||||
|       except: |       except: | ||||||
|          name = "UNKNOWN" |          name = "UNKNOWN" | ||||||
|       return name |       return name | ||||||
|  |  | ||||||
|    def net_raw_utc(self, json_data): |    def net_raw_utc(self, json_data): | ||||||
|       time_utc_string = json_data['net'] |       time_utc_string = json_data['t0'] | ||||||
|       try: |       time_utc = datetime.datetime.fromisoformat(time_utc_string) | ||||||
|          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])) |  | ||||||
|       return time_utc |       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): | class DeltaTemplate(Template): | ||||||
|     delimiter = "%" |     delimiter = "%" | ||||||
| @@ -86,18 +59,10 @@ def next_launch(): | |||||||
|    json_data = l.api_request() |    json_data = l.api_request() | ||||||
|    rocket = l.rocket_name(json_data) |    rocket = l.rocket_name(json_data) | ||||||
|    mission = l.mission_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) |    launch_time = l.net_raw_utc(json_data) | ||||||
|       now = datetime.datetime.utcnow().replace(microsecond=0) |    now = datetime.datetime.now(datetime.timezone.utc).replace(microsecond=0) | ||||||
|       if launch_time > now: |    timedelta = abs(launch_time - now) | ||||||
|          timedelta = launch_time - now |    t_string = "-" if launch_time > now else "+" | ||||||
|          t_string = "-" |  | ||||||
|       else: |  | ||||||
|          timedelta = now - launch_time |  | ||||||
|          t_string = "+" |  | ||||||
|    deltastring = strfdelta(timedelta, "T"+t_string+"%D:%H:%M:%S") |    deltastring = strfdelta(timedelta, "T"+t_string+"%D:%H:%M:%S") | ||||||
|    del l |    del l | ||||||
|    return rocket, mission, status, deltastring |    return rocket, mission, deltastring | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user