Compare commits

..

5 Commits

5 changed files with 28 additions and 26 deletions

22
main.py
View File

@ -33,6 +33,8 @@ import time
locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')
NEXT_STOP_Y = 255
from PIL import Image, ImageDraw, ImageFont
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)
if evt_coming:
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)
image.paste(nstops, (480-int(480/1.6), 255))
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), NEXT_STOP_Y))
occuped_space = nstops.height
alerts += nalerts
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:
# weekly weather
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
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
mod = AlertsModule(alerts, ignore_module).draw_module(config, 480, 330)
if mod.height > 260:
image.paste(mod, (0, 580-mod.height+67), mod)
mod = AlertsModule(alerts, ignore_module).draw_module(config, 480, min(317, 640 - NEXT_STOP_Y - occuped_space))
if NEXT_STOP_Y + occuped_space + mod.height > 580 or mod.height > 260:
image.paste(mod, (0, 640-mod.height), mod)
elif mod.height < 100:
image.paste(mod, (0, 580-mod.height-40), mod)
image.paste(mod, (0, 542-mod.height), mod)
else:
image.paste(mod, (0, 580-mod.height-5), mod)
image.paste(mod, (0, 580-mod.height), mod)
# températures
if "WeatherTemperatureModule" not in ignore_module:
from modules.weather import WeatherTemperatureModule
if mod.height > 260:
image.paste(WeatherTemperatureModule().draw_module(config, 480, 200 - mod.height+260), (0, 580 + mod.height-260))
if NEXT_STOP_Y + occuped_space + mod.height > 580 or mod.height > 260:
image.paste(WeatherTemperatureModule().draw_module(config, 480, 140), (0, 640))
else:
image.paste(WeatherTemperatureModule().draw_module(config, 480, 200), (0, 580))

View File

@ -71,7 +71,7 @@ class Config:
gauge_background="red",
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:

View File

@ -2,6 +2,7 @@ from collections.abc import Iterable
from datetime import date, datetime, timedelta, timezone
from functools import reduce
import hashlib
import logging
import re
import time
import urllib.error
@ -47,11 +48,9 @@ class IcalModule:
with open(cache_file, 'wb') as fd:
fd.write(c.read())
except ConnectionResetError as e:
print(e)
pass
logging.exception(e)
except urllib.error.URLError as e:
print(e)
pass
logging.exception(e)
with open(cache_file) as c:
ecal = Calendar.from_ical(c.read())

View File

@ -1,6 +1,7 @@
from datetime import datetime, timedelta, timezone
import hashlib
import json
import logging
import os
import urllib.parse
import urllib.request
@ -97,12 +98,12 @@ class IDFMAPI:
with urllib.request.urlopen(req) as f:
with open(cache_file, 'wb') as fd:
fd.write(f.read())
except ConnectionResetError:
pass
except urllib.error.URLError:
pass
except urllib.error.HTTPError:
pass
except ConnectionResetError as e:
logging.exception(e)
except urllib.error.URLError as e:
logging.exception(e)
except urllib.error.HTTPError as e:
logging.exception(e)
with open(cache_file) as f:
res = json.load(f)
@ -330,7 +331,7 @@ class RATPNextStopModule:
align_x += max_dest + int(line_height/2.5)
for msg in [] + msgs + msgs:
for msg in [] + msgs:
draw.text(
(align_x, align),
msg["message"],
@ -347,6 +348,7 @@ class RATPNextStopModule:
"icon": "wi-earthquake.png",
})
align -= int(line_height * 0.33)
image = image.crop((0,0,width, min(align, height)))
return image, alerts

View File

@ -65,7 +65,9 @@ class SNCFAPI:
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):
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
res = {}
@ -101,13 +103,10 @@ class SNCFAPI:
fd.write(f.read())
except ConnectionResetError as e:
logging.exception(e)
pass
except urllib.error.URLError as e:
logging.exception(e)
pass
except TimeoutError as e:
logging.exception(e)
pass
try:
statinfo = os.stat(cache_file)