diff --git a/weather-fetch/fetch.py b/weather-fetch/fetch.py index f2c2180..678d203 100755 --- a/weather-fetch/fetch.py +++ b/weather-fetch/fetch.py @@ -31,23 +31,26 @@ class Report: def __str__(self): ''' - Basically just a pretty print that we use to + Basically just a pretty print that we use to show on the bar ''' return f"It's {self.temp_c}° @ {self.hum}% humidity Status: {self.desc}" if __name__ == '__main__': - response = requests.get('https://wttr.in/?format=j1') - - if response.status_code == 200: - try: - report = Report(response.json()) - print(report) - except ReportErr as re: - print(re, file=sys.stderr) - except Exception as e: - print('unable to decode response payload', file=sys.stderr) - print('Error caught', e, file=sys.stderr) - else: - print('Unable to fetch data from wttr.in', file=sys.stderr) + try: + response = requests.get('https://wttr.in/?format=j1') + # Due to polybar being weird everything goes to stdout + if response.status_code == 200: + try: + report = Report(response.json()) + print(report) + except ReportErr as re: + print(re, file=sys.stderr) + except Exception as e: + print('unable to decode response payload', file=sys.stderr) + print('Error caught', e, file=sys.stderr) + else: + print('Unable to fetch data from wttr.in', file=sys.stderr) + except: + print('Unable to hit wttr API')