Skip to content

Commit

Permalink
In case external apis fail do not include this data
Browse files Browse the repository at this point in the history
  • Loading branch information
Gctucci committed Jun 2, 2018
1 parent d699b6e commit c737aaa
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pyhome/sense_hat/hat_sensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ def load_env(fname=".env", sep="=="):
def get_weather():
import requests
logger = logging.getLogger()
coord = os.environ.get['LOCATION'].strip(')').strip('(').split(',')
api_addr = os.environ.get('WEATHER_API') + "&lat=%s&lon=%s"%(coord[0], coord[1]) + "&units=metric"
try:
resp = requests.get(api_addr).json()
logger.info("Got weather response: %s", resp)
except Exception as e:
if os.environ.get('LOCATION') is not None:
coord = os.environ.get['LOCATION'].strip(')').strip('(').split(',')
api_addr = os.environ.get('WEATHER_API') + "&lat=%s&lon=%s"%(coord[0], coord[1]) + "&units=metric"
try:
resp = requests.get(api_addr).json()
logger.info("Got weather response: %s", resp)
except Exception as e:
resp = None
else:
resp = None
return resp

Expand Down

0 comments on commit c737aaa

Please sign in to comment.