some cosmetic improvements from pylint
This commit is contained in:
parent
bc933a56f4
commit
48cc791e7e
|
@ -1,9 +1,12 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
""" queries openweathermap to get weather data """
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import configparser
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from time import sleep
|
|
||||||
import configparser
|
|
||||||
import sys, os
|
|
||||||
|
|
||||||
|
|
||||||
iconlist = {
|
iconlist = {
|
||||||
|
@ -34,13 +37,13 @@ def get_config(config_path):
|
||||||
config_parser = configparser.ConfigParser()
|
config_parser = configparser.ConfigParser()
|
||||||
config_parser.read(config_path)
|
config_parser.read(config_path)
|
||||||
# return false on error
|
# return false on error
|
||||||
if config_parser.options('api') != ['openweathermap_api_key', 'lat', 'lon']:
|
if config_parser.options('api') == ['openweathermap_api_key', 'lat', 'lon']:
|
||||||
print('config parse error')
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
api_key = config_parser.get('api', 'openweathermap_api_key')
|
api_key = config_parser.get('api', 'openweathermap_api_key')
|
||||||
lat = config_parser.get('api', 'lat')
|
lat = config_parser.get('api', 'lat')
|
||||||
lon = config_parser.get('api', 'lon')
|
lon = config_parser.get('api', 'lon')
|
||||||
|
else:
|
||||||
|
print('config parse error')
|
||||||
|
return False
|
||||||
return api_key, lat, lon
|
return api_key, lat, lon
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,17 +54,17 @@ def get_data(api_key, lat, lon):
|
||||||
# try up to 3 times
|
# try up to 3 times
|
||||||
for i in range(1, 4):
|
for i in range(1, 4):
|
||||||
try:
|
try:
|
||||||
r = requests.get(url, timeout=5)
|
response = requests.get(url, timeout=5)
|
||||||
except:
|
except:
|
||||||
sleep(int(i) * 30)
|
sleep(int(i) * 30)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
# parse response
|
# parse response
|
||||||
json = r.json()
|
json = response.json()
|
||||||
celsius = round(json['main']['temp'])
|
celsius = round(json['main']['temp'])
|
||||||
celsius_pretty = str(celsius) + "°"
|
celsius_pretty = str(celsius) + "°"
|
||||||
icon_ID = json['weather'][0]['icon']
|
icon_id = json['weather'][0]['icon']
|
||||||
icon = iconlist.get(icon_ID)
|
icon = iconlist.get(icon_id)
|
||||||
# return
|
# return
|
||||||
return celsius_pretty, icon
|
return celsius_pretty, icon
|
||||||
|
|
||||||
|
@ -82,4 +85,3 @@ def main():
|
||||||
# start from here
|
# start from here
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue