How to use get_location_info method in lisa

Best Python code snippet using lisa_python

weather_fun.py

Source:weather_fun.py Github

copy

Full Screen

1import requests2import json3import sys4import os5import matplotlib.pyplot as plt6def send_photo(user_id):7 auth="bot???:????"8 url = "https://api.telegram.org//sendPhoto".format(auth);9 files = {'photo': open('tmp.png', 'rb')}10 data = {'chat_id' : user_id}11 r= requests.post(url, files=files, data=data)12 print(r.status_code, r.reason, r.content)13chat_id="???" #token of the telegram bot14def six_hr_rain_prob(info,user_id):15 def extract_labels_rainprob(item):16 fig = plt.figure()17 _len = len(item['time']) #how many item in the list18 x_axis = list(range(0,_len))19 x_label=[]20 y_axis=[]21 for detail in item['time']:22 y_axis.append(int(detail['elementValue'][0]['value']))23 x_label.append(detail['startTime'][5:-6])24 plt.plot(x_axis, y_axis)25 plt.ylim(0, 100)26 plt.grid(True)27 plt.xticks(x_axis,x_label,rotation='vertical') #28 plt.savefig("tmp.png")29 return fig30 item = info['weatherElement'][7]31 res = item['description']32 res += "\n----------------------------------------------------------------"33 for detail in item['time']:34 res +="\n{start} ~ {end}\t\t {percent}%".format(start=detail['startTime'], end=detail['endTime'], percent= detail['elementValue'][0]['value'])35 res += "\n----------------------------------------------------------------\n"36 extract_labels_rainprob(item)37 send_photo(user_id)38 os.system("rm tmp.png")39 return "here's the result\n"40def feeling_temperature(info):41 item = info['weatherElement'][2]42 res = item['description'] + '\n----------------------------------------------------------------'43 for detail in item['time']:44 #print("{time}\t\t {temp}°C".format(time=detail['dataTime'], temp= detail['elementValue'][0]['value'])45 res += "\n{time}\t\t {temp}°C".format(time=detail['dataTime'], temp= detail['elementValue'][0]['value'])46 res +="\n----------------------------------------------------------------\n"47 return48def real_temperature(info,user_id):49 def extract_labels_realtemp(item):50 fig = plt.figure()51 _len = len(item['time']) #how many item in the list52 x_axis = list(range(0,_len))53 x_label=[]54 y_axis=[]55 for detail in item['time']:56 y_axis.append(int(detail['elementValue'][0]['value']))57 x_label.append(detail['dataTime'][5:-6])58 plt.plot(x_axis, y_axis)59 plt.ylim(min(y_axis)-3, max(y_axis)+3)60 plt.grid(True)61 plt.xticks(x_axis,x_label,rotation='vertical') #62 plt.savefig("tmp.png")63 return fig64 item = info['weatherElement'][3]65 #print(item['description'])66 res = item['description'] + '\n----------------------------------------------------------------'67 #print('----------------------------------------------------------------')68 for detail in item['time']:69 #print("{time}\t\t {temp}°C".format(time=detail['dataTime'], temp= detail['elementValue'][0]['value']))70 res += "\n{time}\t\t {temp}°C".format(time=detail['dataTime'], temp= detail['elementValue'][0]['value'])71 res +="\n----------------------------------------------------------------\n"72 extract_labels_realtemp(item)73 send_photo(user_id)74 os.system("rm tmp.png")75 return res76def whole(fun=0,city="新竹市東區",user_id=0): #function => 0 for temp, 1 for six_hr_rain, 2 for both77 auth_code='???'78 if city=="新竹市東區":79 res = requests.get("https://opendata.cwb.gov.tw/api/v1/rest/datastore/F-D0047-053?Authorization={}&limit=3&offset=0&format=JSON&sort=time".format(auth_code))80 parsed_result=json.loads(res.text)81 get_location_info = parsed_result['records']['locations'][0]['location'][1]82 if city=="台北市信義區":83 res = requests.get("https://opendata.cwb.gov.tw/api/v1/rest/datastore/F-D0047-061?Authorization={}&limit=3&offset=0&format=JSON&sort=time&locationName=信義區".format(auth_code))84 parsed_result=json.loads(res.text)85 get_location_info = parsed_result['records']['locations'][0]['location'][0]86 if city=="台北市南港區":87 res = requests.get("https://opendata.cwb.gov.tw/api/v1/rest/datastore/F-D0047-061?Authorization={}&limit=3&offset=0&format=JSON&sort=time&locationName=南港區".format(auth_code))88 parsed_result=json.loads(res.text)89 get_location_info = parsed_result['records']['locations'][0]['location'][0]90 if city=='新北市汐止區':91 res = requests.get("https://opendata.cwb.gov.tw/api/v1/rest/datastore/F-D0047-069?Authorization={}&limit=3&offset=0&format=JSON&sort=time&locationName=汐止區".format(auth_code))92 parsed_result=json.loads(res.text)93 get_location_info = parsed_result['records']['locations'][0]['location'][0]94 if city=='基隆市中山區': 95 res = requests.get("https://opendata.cwb.gov.tw/api/v1/rest/datastore/F-D0047-049?Authorization={}&format=JSON&limit=3&offset=0&format=JSON&sort=time&locationName=%E4%B8%AD%E5%B1%B1%E5%8D%80".format(auth_code))96 parsed_result=json.loads(res.text)97 get_location_info = parsed_result['records']['locations'][0]['location'][0]98 if fun==0:99 _str = real_temperature(get_location_info,user_id)100 elif fun==1:101 _str = six_hr_rain_prob(get_location_info,user_id)102 elif fun==2:103 _str = six_hr_rain_prob(get_location_info,user_id) + real_temperature(get_location_info,user_id)...

Full Screen

Full Screen

event_csv_row.py

Source:event_csv_row.py Github

copy

Full Screen

...25 throwable_string = throwable_string.replace("\"", "\\\"")26 throwable_string = throwable_string.replace("\t", "\\\t")27 28 csv_row += self._separator + self._encloser.enclose(throwable_string)29 csv_row += self._separator + self._encloser.enclose(self._event.get_location_info().get_class())30 csv_row += self._separator + self._encloser.enclose(self._event.get_location_info().get_method())31 csv_row += self._separator + self._encloser.enclose(self._event.get_location_info().get_file())32 csv_row += self._separator + self._encloser.enclose(self._event.get_location_info().get_line())...

Full Screen

Full Screen

location.py

Source:location.py Github

copy

Full Screen

1import requests2def get_location_info():3 return requests.get("https://freegeoip.net/json").json()4if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful