autopep8 to clean up the code

This commit is contained in:
mrwunderbar666 2017-08-01 16:10:18 +08:00
parent f983c621bc
commit ed68965eef

View File

@ -16,7 +16,8 @@
from __future__ import print_function from __future__ import print_function
from datetime import datetime from datetime import datetime
import calendar import calendar
import urllib, json import urllib
import json
import time import time
import os import os
@ -36,6 +37,7 @@ API_KEY = "YOUR API KEY"
LAT = "22.345490" # Your Location LAT = "22.345490" # Your Location
LONG = "114.189945" # Your Location LONG = "114.189945" # Your Location
def forecast_icon(idx): def forecast_icon(idx):
icon = data['daily']['data'][idx]['icon'] icon = data['daily']['data'][idx]['icon']
image = GRAPHICS_PATH + icon + ".png" image = GRAPHICS_PATH + icon + ".png"
@ -55,7 +57,12 @@ def forecast(idx):
print(hi) print(hi)
print(cond) print(cond)
time.sleep(1) time.sleep(1)
printer.set(font='a', height=2, align='left', bold=False, double_height=False) printer.set(
font='a',
height=2,
align='left',
bold=False,
double_height=False)
printer.text(day + ' \n ') printer.text(day + ' \n ')
time.sleep(5) # Sleep to prevent printer buffer overflow time.sleep(5) # Sleep to prevent printer buffer overflow
printer.text('\n') printer.text('\n')
@ -66,7 +73,8 @@ def forecast(idx):
printer.text(' high ' + str(hi)) printer.text(' high ' + str(hi))
printer.text(deg) printer.text(deg)
printer.text('\n') printer.text('\n')
printer.text(cond.replace(u'\u2013', '-').encode('utf-8')) # take care of pesky unicode dash # take care of pesky unicode dash
printer.text(cond.replace(u'\u2013', '-').encode('utf-8'))
printer.text('\n \n') printer.text('\n \n')
@ -79,7 +87,8 @@ def icon():
deg = ' C' # Degree symbol on thermal printer, need to find a better way to use a proper degree symbol deg = ' C' # Degree symbol on thermal printer, need to find a better way to use a proper degree symbol
# if you want Fahrenheit change units= to 'us' # if you want Fahrenheit change units= to 'us'
url = "https://api.darksky.net/forecast/"+API_KEY+"/"+LAT+","+LONG+"?exclude=[alerts,minutely,hourly,flags]&units=si" #change last bit to 'us' for Fahrenheit url = "https://api.darksky.net/forecast/" + API_KEY + "/" + LAT + "," + LONG + \
"?exclude=[alerts,minutely,hourly,flags]&units=si" # change last bit to 'us' for Fahrenheit
response = urllib.urlopen(url) response = urllib.urlopen(url)
data = json.loads(response.read()) data = json.loads(response.read())