def make_taf_test(station: str) -> dict: """Builds TAF test file for station""" t = avwx.Taf(station) t.update() return { "data": asdict(t.data), "translations": asdict(t.translations), "summary": t.summary, "speech": t.speech, "station": asdict(t.station), }
def test_wind_shear(self): """""" report = ( "TAF AMD CYOW 282059Z 2821/2918 09008KT WS015/20055KT P6SM BKN220 " "BECMG 2821/2823 19015G25KT " "FM290300 21013G23KT P6SM -SHRA BKN040 OVC100 " "TEMPO 2903/2909 4SM BR OVC020 " "FM290900 25012KT P6SM SCT030 " "FM291300 32017G27KT P6SM OVC030 " "TEMPO 2913/2918 P6SM -SHRA OVC020 RMK NXT FCST BY 290000Z") taf = avwx.Taf('CYBC') taf.update(report) lines = taf.data['Forecast'] self.assertEqual(len(lines), 7) self.assertEqual(lines[0]['Wind-Shear'], 'WS015/20055') self.assertEqual(taf.translations['Forecast'][1]['Clouds'], '')
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 test_prob_line(self): """Even though PROB__ is not in TAF_NEWLINE, it should still separate, add a new line, and include the prob value in line['Probability'] """ report = ( "TAF AMD CYBC 271356Z 2714/2802 23015G25KT P6SM BKN090 " "TEMPO 2714/2718 P6SM -SHRA BKN060 OVC090 " "FM271800 22015G25KT P6SM OVC040 " "TEMPO 2718/2724 6SM -SHRA " "PROB30 2718/2724 VRB25G35KT 1SM +TSRA BR BKN020 OVC040CB " "FM280000 23008KT P6SM BKN040 RMK FCST BASED ON AUTO OBS. NXT FCST BY 272000Z" ) taf = avwx.Taf('CYBC') taf.update(report) lines = taf.data['Forecast'] self.assertEqual(len(lines), 6) self.assertEqual(lines[3]['Probability'], '') self.assertEqual(lines[4]['Probability'], '30') self.assertTrue(lines[4]['Raw-Line'].startswith('PROB30'))
def make_taf_test(station: str, report: str = None) -> dict: """ Builds TAF test file for station """ t = avwx.Taf(station) t.update(report) data = asdict(t.data) # Clear timestamp due to parse_date limitations for key in ("time", "start_time", "end_time"): data[key] = None for i in range(len(data["forecast"])): for key in ("start_time", "end_time"): data["forecast"][i][key] = None return { "data": data, "translations": asdict(t.translations), "summary": t.summary, "speech": t.speech, "station_info": asdict(t.station_info), }
def make_taf_test(station: str, report: str = None): """ Builds TAF test files """ t = avwx.Taf(station) t.update(report) data = asdict(t.data) # Clear timestamp due to parse_date limitations for key in ('time', 'start_time', 'end_time'): data[key] = None for i in range(len(data['forecast'])): for key in ('start_time', 'end_time'): data['forecast'][i][key] = None return { 'data': data, 'translations': asdict(t.translations), 'summary': t.summary, 'speech': t.speech, 'station_info': asdict(t.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 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_taf(airport): raw_taf = requests.get(f'{taf_url}{airport}?token={avwx_token}').json()['raw'] taf = avwx.Taf(airport) taf.update() return taf
#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()