async def worker(queue: aio.Queue): """ Worker to check queued idents and update lists """ i = 0 maxi = 100 while True: icao = await queue.get() try: m = avwx.Metar(icao) if await m.async_update(): GOOD.append(icao) BAD.remove(icao) elif icao not in BAD: BAD.append(icao) i += 1 # Sleep to prevent 403 from services if i >= maxi: i = 0 await aio.sleep(10) except avwx.exceptions.SourceError as exc: print(exc) sys.exit(3) except avwx.exceptions.BadStation: pass except KeyboardInterrupt: sys.exit(1) except Exception as exc: print() print(exc) print(icao) print(m.raw) print() finally: queue.task_done()
def new_station(self): """ Update the current station from ident and display new main screen """ try: avwx.core.valid_station(self.station) except avwx.exceptions.BadStation: return self.error_station() self.draw_loading_screen() new_metar = avwx.Metar(self.station) try: new_metar.update() except (TimeoutError, ConnectionError, avwx.exceptions.SourceError): self.error_connection() except avwx.exceptions.InvalidRequest: self.error_station() except Exception as exc: logger.error(f'An unknown error has occured: {exc}') self.error_unknown() else: logger.info(new_metar.raw) self.metar = new_metar self.old_ident = copy(self.ident) self.reset_update_time() self.export_session() self.draw_main()
def make_metar_test(station: str) -> dict: """Builds METAR test file for station""" m = avwx.Metar(station) m.update() return { "data": asdict(m.data), "translations": asdict(m.translations), "summary": m.summary, "speech": m.speech, }
def __init__(self, station: str, size: (int, int), inverted: bool): logger.debug('Running init') try: self.metar = avwx.Metar(station) except avwx.exceptions.BadStation: self.metar = avwx.Metar('KJFK') self.ident = common.station_to_ident(station) self.old_ident = copy(self.ident) self.width, self.height = size self.win = pygame.display.set_mode(size) self.c = Color() self.inverted = inverted if inverted: self.c.BLACK, self.c.WHITE = self.c.WHITE, self.c.BLACK # Hide mouse for touchscreen input/Disable if test non touchscreen if cfg.on_pi: pygame.mouse.set_visible(False) self.reset_update_time() self.buttons = [] logger.debug('Finished running init')
def make_metar_test(station: str) -> dict: """ Builds METAR test file for station """ m = avwx.Metar(station) m.update() # Clear timestamp due to parse_date limitations m.data.time = None return { "data": asdict(m.data), "translations": asdict(m.translations), "summary": m.summary, "speech": m.speech, }
def make_metar_test(station: str): """ Builds METAR test files """ m = avwx.Metar(station) m.update() # Clear timestamp due to parse_date limitations m.data.time = None return { 'data': asdict(m.data), 'translations': asdict(m.translations), 'summary': m.summary, 'speech': m.speech, 'station_info': asdict(m.station_info) }
def parse_given(rtype: str, report: str, opts: [str]) -> (dict, int): """Attepts to parse a given report supplied by the user""" if len(report) < 4: return { 'Error': 'Could not find station at beginning of report', 'Timestamp': datetime.utcnow() }, 400 station = report[:4] try: ureport = avwx.Metar(station) if rtype == 'metar' else avwx.Taf( station) ureport.update(report) resp = ureport.data resp['Meta'] = {'Timestamp': datetime.utcnow()} if 'translate' in opts or 'summary' in opts: resp['Translations'] = ureport.translations if rtype == 'metar': if 'summary' in opts: resp['Summary'] = ureport.summary if 'speech' in opts: resp['Speech'] = ureport.speech else: if 'summary' in opts: #Special handling for TAF summary response for i, forecast in enumerate( ureport.translations['Forecast']): resp['Forecast'][i]['Summary'] = avwx.summary.taf( forecast) #Add station info if requested if 'info' in opts: try: resp['Info'] = ureport.station_info except avwx.exceptions.BadStation: resp['Info'] = {} return resp, 200 except avwx.exceptions.BadStation: return { 'Error': ERRORS[0].format(rtype), 'Timestamp': datetime.utcnow() }, 400 except: return { 'Error': ERRORS[1].format(rtype), 'Timestamp': datetime.utcnow() }, 500
def parse_given(rtype: str, report: str, opts: [str]) -> (dict, int): """ Attepts to parse a given report supplied by the user """ if len(report) < 4 or '{' in report: return { 'error': 'Could not find station at beginning of report', 'timestamp': datetime.utcnow() }, 400 station = report[:4] try: ureport = avwx.Metar(station) if rtype == 'metar' else avwx.Taf(station) ureport.update(report) resp = asdict(ureport.data) resp['meta'] = {'timestamp': datetime.utcnow()} if 'translate' in opts: resp['translations'] = asdict(ureport.translations) if 'summary' in opts: if rtype == 'taf': for i in range(len(ureport.translations['forecast'])): resp['forecast'][i]['summary'] = ureport.summary[i] else: resp['summary'] = ureport.summary if 'speech' in opts: resp['speech'] = ureport.speech # Add station info if requested if 'info' in opts: try: resp['info'] = asdict(ureport.station_info) except avwx.exceptions.BadStation: resp['info'] = {} return resp, 200 except avwx.exceptions.BadStation: return {'error': ERRORS[2].format(station), 'timestamp': datetime.utcnow()}, 400 except: rollbar.report_exc_info() return {'error': ERRORS[1].format(rtype), 'timestamp': datetime.utcnow()}, 500
def get_metar(airport): raw_metar = requests.get(f'{metar_url}{airport}?token={avwx_token}').json()['raw'] metar = avwx.Metar(airport) metar.update() return metar
#bot1680074948:AAGVcSE-ToArVshcC3hf_JLuwhSmRt52-jo import avwx from avwx.current.metar import Metar import requests as rq import json url = ("https://api.telegram.org/bot1680074948:AAGVcSE-ToArVshcC3hf_JLuwhSmRt52-jo/") jfk_metar = avwx.Metar('KJFK') hnl_taf = avwx.Taf('PHNL') print(jfk_metar.update()) print(jfk_metar.raw) print(hnl_taf.update()) print(hnl_taf.raw) def getUpdates(): global r global url r= rq.get(url+'getUpdates') return r.json() def get_data(items=1): global idlist,get,chat_id idlist = [43213135,1146053565,785166521] get = getUpdates() chat_id = get['result'] [-1] ['message'] [ 'chat'] ['id'] global url req= rq.get(url+'getUpdates') return req.json()