Podpora Food API na Windows
This commit is contained in:
parent
4aadb346ee
commit
783340bf06
@ -7,6 +7,7 @@ import tempfile
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
import platform
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
|
|
||||||
URL_SLADOVNICKA = "https://sladovnicka.unasplzenchutna.cz/cz/denni-nabidka"
|
URL_SLADOVNICKA = "https://sladovnicka.unasplzenchutna.cz/cz/denni-nabidka"
|
||||||
@ -52,7 +53,7 @@ def getOrDownloadHtml(prefix: str, url: str):
|
|||||||
filepath = os.path.join(tempfile.gettempdir(), filename)
|
filepath = os.path.join(tempfile.gettempdir(), filename)
|
||||||
if not os.path.isfile(filepath):
|
if not os.path.isfile(filepath):
|
||||||
urllib.request.urlretrieve(url, filepath)
|
urllib.request.urlretrieve(url, filepath)
|
||||||
file = open(filepath, "r")
|
file = open(filepath, "r", encoding='utf-8')
|
||||||
contents = file.read()
|
contents = file.read()
|
||||||
file.close()
|
file.close()
|
||||||
return contents
|
return contents
|
||||||
@ -113,7 +114,12 @@ def getMenuSladovnicka(mock: bool = False) -> List[Food]:
|
|||||||
split = datumDen.split(".")
|
split = datumDen.split(".")
|
||||||
denMesic = split[0] + "." + split[1] + "."
|
denMesic = split[0] + "." + split[1] + "."
|
||||||
# nazevDen = split[2]
|
# nazevDen = split[2]
|
||||||
dnesniDatum = date.today().strftime("%-d.%-m.")
|
# Windows má pro padding '#', POSIX systémy '-'
|
||||||
|
if platform.system() == 'Windows':
|
||||||
|
format = "%#d.%#m."
|
||||||
|
else:
|
||||||
|
format = "%-d.%-m."
|
||||||
|
dnesniDatum = date.today().strftime(format)
|
||||||
if denMesic != dnesniDatum:
|
if denMesic != dnesniDatum:
|
||||||
print('Chyba: neočekávané datum na stránce Sladovnické (' +
|
print('Chyba: neočekávané datum na stránce Sladovnické (' +
|
||||||
denMesic + '), očekáváno ' + dnesniDatum, file=sys.stderr)
|
denMesic + '), očekáváno ' + dnesniDatum, file=sys.stderr)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user