PiVelib should be fully working.
This commit is contained in:
parent
a469a3611f
commit
e4f3e29035
147
pivelib.py
147
pivelib.py
@ -18,6 +18,8 @@ import xml.etree.ElementTree as ET
|
|||||||
import datetime
|
import datetime
|
||||||
import wiringpi2 as wp2
|
import wiringpi2 as wp2
|
||||||
import time as time_lib
|
import time as time_lib
|
||||||
|
import signal
|
||||||
|
import threading
|
||||||
|
|
||||||
wp2.wiringPiSetup()
|
wp2.wiringPiSetup()
|
||||||
|
|
||||||
@ -155,12 +157,14 @@ def stringLCD(string):
|
|||||||
for character in string:
|
for character in string:
|
||||||
characterLCD(character)
|
characterLCD(character)
|
||||||
|
|
||||||
|
|
||||||
# X ranges from 0 to 84
|
# X ranges from 0 to 84
|
||||||
# Y ranges from 0 to 5
|
# Y ranges from 0 to 5
|
||||||
def gotoXYLCD(x, y):
|
def gotoXYLCD(x, y):
|
||||||
writeLCD(0, 0x80 | x)
|
writeLCD(0, 0x80 | x)
|
||||||
writeLCD(0, 0x40 | y)
|
writeLCD(0, 0x40 | y)
|
||||||
|
|
||||||
|
|
||||||
def initLCD():
|
def initLCD():
|
||||||
wp2.pinMode(PIN_SCE, 1)
|
wp2.pinMode(PIN_SCE, 1)
|
||||||
wp2.pinMode(PIN_RESET, 1)
|
wp2.pinMode(PIN_RESET, 1)
|
||||||
@ -184,41 +188,33 @@ def clearLCD():
|
|||||||
writeLCD(LCD_D, 0x00)
|
writeLCD(LCD_D, 0x00)
|
||||||
characterLCD(' ')
|
characterLCD(' ')
|
||||||
|
|
||||||
# ==========
|
|
||||||
# Paramètres
|
|
||||||
# ==========
|
|
||||||
|
|
||||||
if(len(sys.argv) == 1):
|
def kill_handler(signum, frame):
|
||||||
exit('Vous devez fournir au moins un numéro de station en argument.')
|
global running
|
||||||
|
global update_thread
|
||||||
|
print("Exiting...")
|
||||||
|
running = False
|
||||||
|
update_thread.cancel()
|
||||||
|
|
||||||
stations = []
|
|
||||||
for station in sys.argv[1:]:
|
|
||||||
stations.append(int(station))
|
|
||||||
|
|
||||||
base_url = ('http://www.velib.paris.fr/service/stationdetails/paris/')
|
def update():
|
||||||
|
print("Updating...")
|
||||||
|
global available
|
||||||
|
global free
|
||||||
|
global weather_now
|
||||||
|
global temp_now
|
||||||
|
global weather_3h
|
||||||
|
global temp_3h
|
||||||
|
global weather_6h
|
||||||
|
global temp_6h
|
||||||
|
global weather_9h
|
||||||
|
global temp_9h
|
||||||
|
global running
|
||||||
|
|
||||||
# =============================
|
# =======================
|
||||||
# Initialisation des librairies
|
# Requête sur l'API Vélib
|
||||||
# =============================
|
# =======================
|
||||||
http = urllib3.PoolManager()
|
for station in stations:
|
||||||
initLCD()
|
|
||||||
clearLCD()
|
|
||||||
gotoXYLCD(0,0)
|
|
||||||
stringLCD("Loading...")
|
|
||||||
|
|
||||||
# ====
|
|
||||||
# Date
|
|
||||||
# ====
|
|
||||||
now = datetime.datetime.now()
|
|
||||||
date = now.strftime('%d/%m/%Y')
|
|
||||||
time = now.strftime('%H:%M')
|
|
||||||
|
|
||||||
# =======================
|
|
||||||
# Requête sur l'API Vélib
|
|
||||||
# =======================
|
|
||||||
available = {}
|
|
||||||
free = {}
|
|
||||||
for station in stations:
|
|
||||||
r = http.request('GET', base_url+str(station))
|
r = http.request('GET', base_url+str(station))
|
||||||
|
|
||||||
if r.status == 200:
|
if r.status == 200:
|
||||||
@ -233,23 +229,14 @@ for station in stations:
|
|||||||
available[station] = -1
|
available[station] = -1
|
||||||
free[station] = -1
|
free[station] = -1
|
||||||
|
|
||||||
# ==================================
|
# ==================================
|
||||||
# Requête pour les prédictions météo
|
# Requête pour les prédictions météo
|
||||||
# ==================================
|
# ==================================
|
||||||
url_weather = ('http://api.openweathermap.org/data/2.5/forecast' +
|
url_weather = ('http://api.openweathermap.org/data/2.5/forecast' +
|
||||||
'?q=Paris,fr&mode=xml&lang=fr&units=metric')
|
'?q=Paris,fr&mode=xml&lang=fr&units=metric')
|
||||||
r = http.request('GET', url_weather)
|
r = http.request('GET', url_weather)
|
||||||
|
|
||||||
weather_now = ''
|
if r.status == 200:
|
||||||
temp_now = -1
|
|
||||||
weather_3h = ''
|
|
||||||
temp_3h = -1
|
|
||||||
weather_6h = ''
|
|
||||||
temp_6h = -1
|
|
||||||
weather_9h = ''
|
|
||||||
temp_9h = -1
|
|
||||||
|
|
||||||
if r.status == 200:
|
|
||||||
weather_xml = ET.fromstring(r.data)
|
weather_xml = ET.fromstring(r.data)
|
||||||
|
|
||||||
for child in weather_xml.iter('forecast'):
|
for child in weather_xml.iter('forecast'):
|
||||||
@ -277,12 +264,62 @@ if r.status == 200:
|
|||||||
time_from < now+datetime.timedelta(hours=9)):
|
time_from < now+datetime.timedelta(hours=9)):
|
||||||
weather_9h = time.find('clouds').attrib['value']
|
weather_9h = time.find('clouds').attrib['value']
|
||||||
temp_9h = time.find('temperature').attrib['value']
|
temp_9h = time.find('temperature').attrib['value']
|
||||||
|
# ==========
|
||||||
|
# Paramètres
|
||||||
|
# ==========
|
||||||
|
|
||||||
|
if(len(sys.argv) == 1):
|
||||||
|
sys.exit('You must provide at least one station number as ' +
|
||||||
|
'argument on the command line.')
|
||||||
|
|
||||||
|
stations = []
|
||||||
|
for station in sys.argv[1:]:
|
||||||
|
stations.append(int(station))
|
||||||
|
|
||||||
|
base_url = ('http://www.velib.paris.fr/service/stationdetails/paris/')
|
||||||
|
|
||||||
|
# =============================
|
||||||
|
# Initialisation des librairies
|
||||||
|
# =============================
|
||||||
|
http = urllib3.PoolManager()
|
||||||
|
initLCD()
|
||||||
|
clearLCD()
|
||||||
|
gotoXYLCD(0, 0)
|
||||||
|
stringLCD("Loading...")
|
||||||
|
|
||||||
|
running = True
|
||||||
|
update_thread = threading.Timer(900, update)
|
||||||
|
update_thread.start()
|
||||||
|
signal.signal(signal.SIGINT, kill_handler)
|
||||||
|
|
||||||
|
# ====
|
||||||
|
# Date
|
||||||
|
# ====
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
date = now.strftime('%d/%m/%Y')
|
||||||
|
time = now.strftime('%H:%M')
|
||||||
|
|
||||||
|
# ====
|
||||||
|
# Vars
|
||||||
|
# ====
|
||||||
|
available = {}
|
||||||
|
free = {}
|
||||||
|
|
||||||
|
weather_now = ''
|
||||||
|
temp_now = -1
|
||||||
|
weather_3h = ''
|
||||||
|
temp_3h = -1
|
||||||
|
weather_6h = ''
|
||||||
|
temp_6h = -1
|
||||||
|
weather_9h = ''
|
||||||
|
temp_9h = -1
|
||||||
|
|
||||||
|
update()
|
||||||
|
|
||||||
|
|
||||||
# ============================
|
# ============================
|
||||||
# Afficher les infos à l'écran
|
# Afficher les infos à l'écran
|
||||||
# ============================
|
# ============================
|
||||||
running = True
|
|
||||||
while running:
|
while running:
|
||||||
for station in stations:
|
for station in stations:
|
||||||
clearLCD()
|
clearLCD()
|
||||||
@ -296,6 +333,8 @@ while running:
|
|||||||
stringLCD("Free: "+str(free[station]))
|
stringLCD("Free: "+str(free[station]))
|
||||||
time_lib.sleep(2)
|
time_lib.sleep(2)
|
||||||
|
|
||||||
|
if running is False:
|
||||||
|
continue
|
||||||
clearLCD()
|
clearLCD()
|
||||||
gotoXYLCD(0, 0)
|
gotoXYLCD(0, 0)
|
||||||
stringLCD("[Weather]")
|
stringLCD("[Weather]")
|
||||||
@ -304,9 +343,11 @@ while running:
|
|||||||
gotoXYLCD(0, 2)
|
gotoXYLCD(0, 2)
|
||||||
stringLCD(weather_now.capitalize())
|
stringLCD(weather_now.capitalize())
|
||||||
gotoXYLCD(0, 4)
|
gotoXYLCD(0, 4)
|
||||||
stringLCD(str(temp_now)+"C")
|
stringLCD("Temp:"+str(temp_now)+"C")
|
||||||
time_lib.sleep(2)
|
time_lib.sleep(2)
|
||||||
|
|
||||||
|
if running is False:
|
||||||
|
continue
|
||||||
clearLCD()
|
clearLCD()
|
||||||
gotoXYLCD(0, 0)
|
gotoXYLCD(0, 0)
|
||||||
stringLCD("[Weather]")
|
stringLCD("[Weather]")
|
||||||
@ -315,9 +356,11 @@ while running:
|
|||||||
gotoXYLCD(0, 2)
|
gotoXYLCD(0, 2)
|
||||||
stringLCD(weather_3h.capitalize())
|
stringLCD(weather_3h.capitalize())
|
||||||
gotoXYLCD(0, 4)
|
gotoXYLCD(0, 4)
|
||||||
stringLCD(str(temp_3h)+"C")
|
stringLCD("Temp:"+str(temp_3h)+"C")
|
||||||
time_lib.sleep(2)
|
time_lib.sleep(2)
|
||||||
|
|
||||||
|
if running is False:
|
||||||
|
continue
|
||||||
clearLCD()
|
clearLCD()
|
||||||
gotoXYLCD(0, 0)
|
gotoXYLCD(0, 0)
|
||||||
stringLCD("[Weather]")
|
stringLCD("[Weather]")
|
||||||
@ -326,9 +369,11 @@ while running:
|
|||||||
gotoXYLCD(0, 2)
|
gotoXYLCD(0, 2)
|
||||||
stringLCD(weather_6h.capitalize())
|
stringLCD(weather_6h.capitalize())
|
||||||
gotoXYLCD(0, 4)
|
gotoXYLCD(0, 4)
|
||||||
stringLCD(str(temp_6h)+"C")
|
stringLCD("Temp:"+str(temp_6h)+"C")
|
||||||
time_lib.sleep(2)
|
time_lib.sleep(2)
|
||||||
|
|
||||||
|
if running is False:
|
||||||
|
continue
|
||||||
clearLCD()
|
clearLCD()
|
||||||
gotoXYLCD(0, 0)
|
gotoXYLCD(0, 0)
|
||||||
stringLCD("[Weather]")
|
stringLCD("[Weather]")
|
||||||
@ -337,7 +382,7 @@ while running:
|
|||||||
gotoXYLCD(0, 2)
|
gotoXYLCD(0, 2)
|
||||||
stringLCD(weather_9h.capitalize())
|
stringLCD(weather_9h.capitalize())
|
||||||
gotoXYLCD(0, 4)
|
gotoXYLCD(0, 4)
|
||||||
stringLCD(str(temp_9h)+"C")
|
stringLCD("Temp:"+str(temp_9h)+"C")
|
||||||
time_lib.sleep(2)
|
time_lib.sleep(2)
|
||||||
|
|
||||||
clearLCD()
|
clearLCD()
|
||||||
|
Loading…
Reference in New Issue
Block a user