autopep8 to clean up the code
This commit is contained in:
parent
f983c621bc
commit
ed68965eef
@ -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"
|
||||||
@ -45,29 +47,35 @@ def forecast_icon(idx):
|
|||||||
# Dumps one forecast line to the printer
|
# Dumps one forecast line to the printer
|
||||||
def forecast(idx):
|
def forecast(idx):
|
||||||
date = datetime.fromtimestamp(int(data['daily']['data'][idx]['time']))
|
date = datetime.fromtimestamp(int(data['daily']['data'][idx]['time']))
|
||||||
day = calendar.day_name[date.weekday()]
|
day = calendar.day_name[date.weekday()]
|
||||||
lo = data['daily']['data'][idx]['temperatureMin']
|
lo = data['daily']['data'][idx]['temperatureMin']
|
||||||
hi = data['daily']['data'][idx]['temperatureMax']
|
hi = data['daily']['data'][idx]['temperatureMax']
|
||||||
cond = data['daily']['data'][idx]['summary']
|
cond = data['daily']['data'][idx]['summary']
|
||||||
print(date)
|
print(date)
|
||||||
print(day)
|
print(day)
|
||||||
print(lo)
|
print(lo)
|
||||||
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')
|
||||||
printer.image(forecast_icon(idx))
|
printer.image(forecast_icon(idx))
|
||||||
printer.text('low ' + str(lo) )
|
printer.text('low ' + str(lo))
|
||||||
printer.text(deg)
|
printer.text(deg)
|
||||||
printer.text('\n')
|
printer.text('\n')
|
||||||
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('\n \n')
|
printer.text(cond.replace(u'\u2013', '-').encode('utf-8'))
|
||||||
|
printer.text('\n \n')
|
||||||
|
|
||||||
|
|
||||||
def icon():
|
def icon():
|
||||||
@ -76,10 +84,11 @@ def icon():
|
|||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
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())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user