Best Python code snippet using lisa_python
weather_fun.py
Source:weather_fun.py
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)...
event_csv_row.py
Source:event_csv_row.py
...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())...
location.py
Source:location.py
1import requests2def get_location_info():3 return requests.get("https://freegeoip.net/json").json()4if __name__ == "__main__":...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!