Compare commits
5 Commits
36068e9d10
...
804eb38f18
Author | SHA1 | Date | |
---|---|---|---|
804eb38f18 | |||
287c4ac349 | |||
9d625c87ee | |||
5090e8068d | |||
e94062158a |
22
main.py
22
main.py
@ -33,6 +33,8 @@ import time
|
|||||||
|
|
||||||
locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')
|
locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')
|
||||||
|
|
||||||
|
NEXT_STOP_Y = 255
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
class WidgetPlacement:
|
class WidgetPlacement:
|
||||||
@ -85,8 +87,8 @@ def main(only_on_coming_evt=False, ignore_module=[], force_coming_event=True, **
|
|||||||
evt_coming = force_coming_event or ical.non_local_event_coming(config) or ical.local_event_ending(config)
|
evt_coming = force_coming_event or ical.non_local_event_coming(config) or ical.local_event_ending(config)
|
||||||
if evt_coming:
|
if evt_coming:
|
||||||
from modules.ratp import RATPNextStopModule
|
from modules.ratp import RATPNextStopModule
|
||||||
nstops, nalerts = RATPNextStopModule().draw_module(config, ["RB/cite+universitaire/A", "M7/porte+d'italie/A", "B125/raspail+++jaures/A"], int(480/1.6), 275)
|
nstops, nalerts = RATPNextStopModule().draw_module(config, ["RB/cite+universitaire", "M7/porte+d+italie", "B125/raspail+++jean+jaures+++saint+eloi"], int(480/1.6), 275)
|
||||||
image.paste(nstops, (480-int(480/1.6), 255))
|
image.paste(nstops, (480-int(480/1.6), NEXT_STOP_Y))
|
||||||
occuped_space = nstops.height
|
occuped_space = nstops.height
|
||||||
alerts += nalerts
|
alerts += nalerts
|
||||||
elif only_on_coming_evt:
|
elif only_on_coming_evt:
|
||||||
@ -96,7 +98,7 @@ def main(only_on_coming_evt=False, ignore_module=[], force_coming_event=True, **
|
|||||||
if occuped_space < 250:
|
if occuped_space < 250:
|
||||||
# weekly weather
|
# weekly weather
|
||||||
from modules.weather import WeeklyWeatherModule
|
from modules.weather import WeeklyWeatherModule
|
||||||
shape.append(WidgetPlacement(WeeklyWeatherModule, size=(int(480/1.6), 275), position=(480-int(480/1.6), 255 + occuped_space)))
|
shape.append(WidgetPlacement(WeeklyWeatherModule, size=(int(480/1.6), 275), position=(480-int(480/1.6), NEXT_STOP_Y + occuped_space + (5 if occuped_space else 0))))
|
||||||
|
|
||||||
# RATP weather
|
# RATP weather
|
||||||
from modules.ratp import RATPWeatherModule
|
from modules.ratp import RATPWeatherModule
|
||||||
@ -147,19 +149,19 @@ def main(only_on_coming_evt=False, ignore_module=[], force_coming_event=True, **
|
|||||||
|
|
||||||
|
|
||||||
from modules import AlertsModule
|
from modules import AlertsModule
|
||||||
mod = AlertsModule(alerts, ignore_module).draw_module(config, 480, 330)
|
mod = AlertsModule(alerts, ignore_module).draw_module(config, 480, min(317, 640 - NEXT_STOP_Y - occuped_space))
|
||||||
if mod.height > 260:
|
if NEXT_STOP_Y + occuped_space + mod.height > 580 or mod.height > 260:
|
||||||
image.paste(mod, (0, 580-mod.height+67), mod)
|
image.paste(mod, (0, 640-mod.height), mod)
|
||||||
elif mod.height < 100:
|
elif mod.height < 100:
|
||||||
image.paste(mod, (0, 580-mod.height-40), mod)
|
image.paste(mod, (0, 542-mod.height), mod)
|
||||||
else:
|
else:
|
||||||
image.paste(mod, (0, 580-mod.height-5), mod)
|
image.paste(mod, (0, 580-mod.height), mod)
|
||||||
|
|
||||||
# températures
|
# températures
|
||||||
if "WeatherTemperatureModule" not in ignore_module:
|
if "WeatherTemperatureModule" not in ignore_module:
|
||||||
from modules.weather import WeatherTemperatureModule
|
from modules.weather import WeatherTemperatureModule
|
||||||
if mod.height > 260:
|
if NEXT_STOP_Y + occuped_space + mod.height > 580 or mod.height > 260:
|
||||||
image.paste(WeatherTemperatureModule().draw_module(config, 480, 200 - mod.height+260), (0, 580 + mod.height-260))
|
image.paste(WeatherTemperatureModule().draw_module(config, 480, 140), (0, 640))
|
||||||
else:
|
else:
|
||||||
image.paste(WeatherTemperatureModule().draw_module(config, 480, 200), (0, 580))
|
image.paste(WeatherTemperatureModule().draw_module(config, 480, 200), (0, 580))
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ class Config:
|
|||||||
gauge_background="red",
|
gauge_background="red",
|
||||||
colors=('#000', '#777'))
|
colors=('#000', '#777'))
|
||||||
|
|
||||||
self.charts_opts = {'style': self.pygal_custom_style, 'show_legend': False, 'margin_right': 7, 'margin_left': 2, 'margin_bottom': 4, 'margin_top': 1}
|
self.charts_opts = {'style': self.pygal_custom_style, 'show_legend': False, 'margin_right': 7, 'margin_left': 2, 'margin_bottom': 4, 'margin_top': 7}
|
||||||
|
|
||||||
|
|
||||||
class RuleModule:
|
class RuleModule:
|
||||||
|
@ -2,6 +2,7 @@ from collections.abc import Iterable
|
|||||||
from datetime import date, datetime, timedelta, timezone
|
from datetime import date, datetime, timedelta, timezone
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import logging
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import urllib.error
|
import urllib.error
|
||||||
@ -47,11 +48,9 @@ class IcalModule:
|
|||||||
with open(cache_file, 'wb') as fd:
|
with open(cache_file, 'wb') as fd:
|
||||||
fd.write(c.read())
|
fd.write(c.read())
|
||||||
except ConnectionResetError as e:
|
except ConnectionResetError as e:
|
||||||
print(e)
|
logging.exception(e)
|
||||||
pass
|
|
||||||
except urllib.error.URLError as e:
|
except urllib.error.URLError as e:
|
||||||
print(e)
|
logging.exception(e)
|
||||||
pass
|
|
||||||
|
|
||||||
with open(cache_file) as c:
|
with open(cache_file) as c:
|
||||||
ecal = Calendar.from_ical(c.read())
|
ecal = Calendar.from_ical(c.read())
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import urllib.request
|
import urllib.request
|
||||||
@ -97,12 +98,12 @@ class IDFMAPI:
|
|||||||
with urllib.request.urlopen(req) as f:
|
with urllib.request.urlopen(req) as f:
|
||||||
with open(cache_file, 'wb') as fd:
|
with open(cache_file, 'wb') as fd:
|
||||||
fd.write(f.read())
|
fd.write(f.read())
|
||||||
except ConnectionResetError:
|
except ConnectionResetError as e:
|
||||||
pass
|
logging.exception(e)
|
||||||
except urllib.error.URLError:
|
except urllib.error.URLError as e:
|
||||||
pass
|
logging.exception(e)
|
||||||
except urllib.error.HTTPError:
|
except urllib.error.HTTPError as e:
|
||||||
pass
|
logging.exception(e)
|
||||||
|
|
||||||
with open(cache_file) as f:
|
with open(cache_file) as f:
|
||||||
res = json.load(f)
|
res = json.load(f)
|
||||||
@ -330,7 +331,7 @@ class RATPNextStopModule:
|
|||||||
|
|
||||||
align_x += max_dest + int(line_height/2.5)
|
align_x += max_dest + int(line_height/2.5)
|
||||||
|
|
||||||
for msg in [] + msgs + msgs:
|
for msg in [] + msgs:
|
||||||
draw.text(
|
draw.text(
|
||||||
(align_x, align),
|
(align_x, align),
|
||||||
msg["message"],
|
msg["message"],
|
||||||
@ -347,6 +348,7 @@ class RATPNextStopModule:
|
|||||||
"icon": "wi-earthquake.png",
|
"icon": "wi-earthquake.png",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
align -= int(line_height * 0.33)
|
||||||
image = image.crop((0,0,width, min(align, height)))
|
image = image.crop((0,0,width, min(align, height)))
|
||||||
|
|
||||||
return image, alerts
|
return image, alerts
|
||||||
|
@ -65,7 +65,9 @@ class SNCFAPI:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if statinfo is None or datetime.fromtimestamp(statinfo.st_mtime, tz=timezone.utc) + timedelta(minutes=self.max_cache_timeout) < datetime.now(tz=timezone.utc):
|
if statinfo is None or datetime.fromtimestamp(statinfo.st_mtime, tz=timezone.utc) + timedelta(minutes=self.max_cache_timeout) < datetime.now(tz=timezone.utc):
|
||||||
raise Exception("File too old")
|
print(self.baseurl + "/1.0/infoVoy/rechercherListeCirculations?numero=%d&dateCirculation=%s&codeZoneArret&typeHoraire=TEMPS_REEL" % (int(numero), date.strftime("%Y-%m-%d")))
|
||||||
|
logging.exception(Exception("File too old to predict SNCF issue"))
|
||||||
|
return None
|
||||||
|
|
||||||
# Retrieve cached data
|
# Retrieve cached data
|
||||||
res = {}
|
res = {}
|
||||||
@ -101,13 +103,10 @@ class SNCFAPI:
|
|||||||
fd.write(f.read())
|
fd.write(f.read())
|
||||||
except ConnectionResetError as e:
|
except ConnectionResetError as e:
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
pass
|
|
||||||
except urllib.error.URLError as e:
|
except urllib.error.URLError as e:
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
pass
|
|
||||||
except TimeoutError as e:
|
except TimeoutError as e:
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
statinfo = os.stat(cache_file)
|
statinfo = os.stat(cache_file)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user