Seite Tide vorbereitet für Wasserstandsvorhersagen
This commit is contained in:
parent
fb7c688a99
commit
e9d473fd10
|
@ -37,6 +37,7 @@ from .racetracker import RaceTracker
|
||||||
from .rollpitch import RollPitch
|
from .rollpitch import RollPitch
|
||||||
from .skyview import SkyView
|
from .skyview import SkyView
|
||||||
from .solar import Solar
|
from .solar import Solar
|
||||||
|
from .tide import Tide
|
||||||
from .rudder import Rudder
|
from .rudder import Rudder
|
||||||
from .voltage import Voltage
|
from .voltage import Voltage
|
||||||
from .wind import Wind
|
from .wind import Wind
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
"""
|
||||||
|
|
||||||
|
NAVTEX
|
||||||
|
- Meldungen anzeigen
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import cairo
|
||||||
|
from .page import Page
|
||||||
|
|
||||||
|
class Tide(Page):
|
||||||
|
|
||||||
|
def __init__(self, pageno, cfg, appdata, boatdata):
|
||||||
|
super().__init__(pageno, cfg, appdata, boatdata)
|
||||||
|
|
||||||
|
self.station = "f3c6ee73-5561-4068-96ec-364016e7d9ef" # Schulau
|
||||||
|
|
||||||
|
def draw(self, ctx):
|
||||||
|
# Title
|
||||||
|
ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD)
|
||||||
|
ctx.set_font_size(24)
|
||||||
|
ctx.move_to(8, 40)
|
||||||
|
ctx.show_text("Tide prediction")
|
||||||
|
|
||||||
|
ctx.set_font_size(16)
|
||||||
|
ctx.set_line_width(2)
|
||||||
|
|
||||||
|
x0 = 40 # links unten
|
||||||
|
y0 = 250
|
||||||
|
x1 = 380 # rechts oben
|
||||||
|
y1 = 60
|
||||||
|
|
||||||
|
# X-Achse
|
||||||
|
ctx.move_to(x0 + 0.5, y0 + 0.5)
|
||||||
|
ctx.line_to(x0 + 0.5, y1 + 0.5)
|
||||||
|
# self.draw_text_center(ctx, x0 - 20, y0 + (y1 -y0) / 2, "Höhe, cm", rotate=True)
|
||||||
|
self.draw_text_center(ctx, 60, 150, "Höhe, cm", rotate=True)
|
||||||
|
#self.draw_text_center(ctx, 100, 100, "Höhe, cm", rotate=False)
|
||||||
|
#ctx.move_to(90, 90) # Rotationsursprung
|
||||||
|
#ctx.line_to(110, 110)
|
||||||
|
#ctx.move_to(90, 110)
|
||||||
|
#ctx.line_to(110, 90)
|
||||||
|
#ctx.stroke()
|
||||||
|
|
||||||
|
# Y-Achse
|
||||||
|
ctx.move_to(x0 + 0.5, y0 + 0.5)
|
||||||
|
ctx.line_to(x1 + 0.5, y0 + 0.5)
|
||||||
|
self.draw_text_center(ctx, x0 + (x1 - x0) / 2, y0 + 12, "Zeit, h")
|
||||||
|
ctx.stroke()
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
"""
|
||||||
|
Web Interface
|
||||||
|
|
||||||
|
Regelmäßiges Abfragen von Daten im Internet
|
||||||
|
- NAVTEX
|
||||||
|
- DWD
|
||||||
|
- Pegelstände
|
||||||
|
- pegelonline
|
||||||
|
- WSV
|
||||||
|
- Wetterinformationen
|
||||||
|
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import http.client
|
||||||
|
import ssl
|
||||||
|
import re
|
||||||
|
import sqlite3
|
||||||
|
import datetime
|
||||||
|
from gi.repository import GLib
|
||||||
|
|
||||||
|
class WebInterface():
|
||||||
|
|
||||||
|
def __init__(self, logger, cfg):
|
||||||
|
self.log = logger
|
||||||
|
dbpath = os.path.join(cfg['histpath'], "tidedata.db")
|
||||||
|
try:
|
||||||
|
self.conn = sqlite3.connect(dbpath)
|
||||||
|
self.cur = self.conn.cursor()
|
||||||
|
except:
|
||||||
|
self.log.error(f"Failed to open tide database: {dbpath}")
|
||||||
|
return
|
||||||
|
# Datenbank erstellen wenn nicht vorhanden
|
||||||
|
sql = "SELECT name FROM sqlite_master WHERE type='table' AND name='station'"
|
||||||
|
self.cur.execute(sql)
|
||||||
|
if self.cur.fetchone() == None:
|
||||||
|
sql = ("CREATE TABLE IF NOT EXISTS station ("
|
||||||
|
"uuid TEXT PRIMARY KEY NOT NULL,"
|
||||||
|
"name TEXT"
|
||||||
|
)
|
||||||
|
self.cur.execute(sql)
|
||||||
|
self.log.info(f"Created tide database: {dbpath}")
|
||||||
|
|
||||||
|
# In der Konfiguration werden Minuten angegeben
|
||||||
|
#GLib.timeout_add_seconds(cfg['tide_refresh'] * 60, self.on_timer)
|
||||||
|
GLib.timeout_add_seconds(60 * 60, self.on_timer)
|
||||||
|
self.running = True
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self.conn.close()
|
||||||
|
|
||||||
|
def on_timer(self):
|
||||||
|
"""
|
||||||
|
Data handling
|
||||||
|
"""
|
||||||
|
self.refresh()
|
||||||
|
self.housekeeping()
|
||||||
|
return True
|
||||||
|
|
||||||
|
def bsh_get_data(self, local=False):
|
||||||
|
"""
|
||||||
|
Webseite auslesen
|
||||||
|
"""
|
||||||
|
if local:
|
||||||
|
# Für Tests um nicht permanent die Webseite abzufragen
|
||||||
|
with open("DE__714P.json", "r") as fh:
|
||||||
|
content = fh.read()
|
||||||
|
else:
|
||||||
|
ssl_context = ssl.create_default_context()
|
||||||
|
conn = http.client.HTTPSConnection("wasserstand-nordsee.bsh.de", 443, context=ssl_context)
|
||||||
|
url = "https://wasserstand-nordsee.bsh.de/data/DE__714P.json"
|
||||||
|
|
||||||
|
try:
|
||||||
|
conn.request("GET", url)
|
||||||
|
response = conn.getresponse()
|
||||||
|
if response.status == 200:
|
||||||
|
content = response.read().decode()
|
||||||
|
else:
|
||||||
|
print(f"Error: {response.status}")
|
||||||
|
return []
|
||||||
|
except http.client.HTTPException as e:
|
||||||
|
self.log.warning(f"HTTP error occurred: {e}")
|
||||||
|
return []
|
||||||
|
except ssl.SSLError as ssl_error:
|
||||||
|
self.log.warning(f"SSL error occurred: {ssl_error}")
|
||||||
|
return []
|
||||||
|
|
||||||
|
return content
|
||||||
|
|
||||||
|
def refresh(self):
|
||||||
|
self.log.info("Data refresh")
|
||||||
|
data = self.bsh_get_data(True)
|
||||||
|
"""
|
||||||
|
sql = "INSERT INTO message (msgid, station, content) VALUES (?, ?, ?)"
|
||||||
|
for m in messages:
|
||||||
|
msg = self.parse_message(m)
|
||||||
|
self.cur.execute("SELECT COUNT(*) FROM message WHERE msgid=?", (msg['id'],))
|
||||||
|
result = self.cur.fetchone()
|
||||||
|
if result[0] == 0:
|
||||||
|
self.log.debug(f"NAVTEX: insert new message '{msg['id']}'")
|
||||||
|
self.cur.execute(sql, (msg['id'], msg['station'], m))
|
||||||
|
self.conn.commit()
|
||||||
|
"""
|
||||||
|
|
||||||
|
def housekeeping(self):
|
||||||
|
self.log.info("Housekeeping")
|
Loading…
Reference in New Issue