adding function saveLastUpdatedIntensivstationen(lastUpdated)

This commit is contained in:
frankknoll
2022-03-08 11:27:14 +01:00
parent 4edb319335
commit c0cc99caf1
3 changed files with 463 additions and 411 deletions

2
.gitignore vendored
View File

@@ -3,7 +3,7 @@ src/intensivstationen/zeitreihe-tagesdaten.csv
src/intensivstationen/geckodriver.log src/intensivstationen/geckodriver.log
.ipynb_checkpoints/ .ipynb_checkpoints/
.history/ .history/
src/config/ src/tmp/
src/results/ src/results/
docs/data/*.xlsx docs/data/*.xlsx
docs/data/*.html docs/data/*.html

View File

@@ -1,11 +1,11 @@
<!DOCTYPE html> <!DOCTYPE html>
<meta charset="utf-8">
<html> <html>
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta charset="utf-8" />
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<title>DIVI-Intensivregister auf Landkreisebene</title> <title>DIVI-Intensivregister auf Landkreisebene</title>
<link rel="stylesheet" type="text/css" href="forkMeOnGitHub.css"> <link href="forkMeOnGitHub.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.jsdelivr.net/npm/chart.js@^3"></script> <script src="https://cdn.jsdelivr.net/npm/chart.js@^3"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@^2"></script> <script src="https://cdn.jsdelivr.net/npm/moment@^2"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-moment@^1"></script> <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-moment@^1"></script>
@@ -49,9 +49,9 @@
<body> <body>
<span id="forkongithub"><a href="https://github.com/KnollFrank/HowBadIsMyBatch">Fork me on GitHub</a></span> <span id="forkongithub"><a href="https://github.com/KnollFrank/HowBadIsMyBatch">Fork me on GitHub</a></span>
<h1>DIVI-Intensivregister auf Landkreisebene</h1> <h1>DIVI-Intensivregister auf Landkreisebene</h1>
<label>Landkreis: <label>Landkreis:</label>
<select id="kreisSelect" name="kreis"> <select id="kreisSelect" name="kreis">
<option value="de" selected>Alle Landkreise</option> <option selected="" value="de">Alle Landkreise</option>
<option value="Ahrweiler">Ahrweiler</option> <option value="Ahrweiler">Ahrweiler</option>
<option value="Aichach-Friedberg">Aichach-Friedberg</option> <option value="Aichach-Friedberg">Aichach-Friedberg</option>
<option value="Alb-Donau-Kreis">Alb-Donau-Kreis</option> <option value="Alb-Donau-Kreis">Alb-Donau-Kreis</option>

View File

@@ -38,6 +38,8 @@
"from time import sleep\n", "from time import sleep\n",
"from selenium import webdriver\n", "from selenium import webdriver\n",
"\n", "\n",
"INTENSIVSTATIONEN_DATE_FORMAT = \"%d.%m.%Y, %H:%M Uhr\"\n",
"\n",
"def needsUpdate():\n", "def needsUpdate():\n",
" lastUpdatedIntensivstationen = _getLastUpdatedIntensivstationen()\n", " lastUpdatedIntensivstationen = _getLastUpdatedIntensivstationen()\n",
" print('lastUpdatedIntensivstationen:', lastUpdatedIntensivstationen)\n", " print('lastUpdatedIntensivstationen:', lastUpdatedIntensivstationen)\n",
@@ -51,7 +53,7 @@
" htmlContent = requests.get(\"https://knollfrank.github.io/HowBadIsMyBatch/intensivstationen.html\").text\n", " htmlContent = requests.get(\"https://knollfrank.github.io/HowBadIsMyBatch/intensivstationen.html\").text\n",
" soup = BeautifulSoup(htmlContent, \"lxml\")\n", " soup = BeautifulSoup(htmlContent, \"lxml\")\n",
" dateStr = soup.find(id = \"Datenstand\").text\n", " dateStr = soup.find(id = \"Datenstand\").text\n",
" return datetime.strptime(dateStr, \"%d.%m.%Y, %H:%M Uhr\")\n", " return datetime.strptime(dateStr, INTENSIVSTATIONEN_DATE_FORMAT)\n",
"\n", "\n",
"def _getLastUpdatedOriginal():\n", "def _getLastUpdatedOriginal():\n",
" html = _getOriginalHtml()\n", " html = _getOriginalHtml()\n",
@@ -77,6 +79,56 @@
"print('needsUpdate: ', needsUpdate)" "print('needsUpdate: ', needsUpdate)"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"id": "963f068b",
"metadata": {},
"outputs": [],
"source": [
"lastUpdatedOriginal = _getLastUpdatedOriginal()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bc48f4cf",
"metadata": {},
"outputs": [],
"source": [
"lastUpdatedOriginal"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "03784154",
"metadata": {},
"outputs": [],
"source": [
"from bs4 import BeautifulSoup\n",
"\n",
"def saveLastUpdatedIntensivstationen(lastUpdated):\n",
" file = \"../../docs/intensivstationen.html\"\n",
" with open(file) as fp:\n",
" soup = BeautifulSoup(fp, 'lxml')\n",
"\n",
" soup.find(id = \"Datenstand\").string.replace_with(lastUpdated.strftime(INTENSIVSTATIONEN_DATE_FORMAT))\n",
"\n",
" with open(file, \"w\") as fp:\n",
" fp.write(str(soup))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "63be303c",
"metadata": {},
"outputs": [],
"source": [
"saveLastUpdatedIntensivstationen(lastUpdatedOriginal)"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
@@ -115,7 +167,6 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# FK-TODO: falls needsUpdate = True, dann muß das aktuelle Datum noch automatisch in intensivstationen.html eingesetzt werden.\n",
"timeSeries = readTimeseries(download = needsUpdate)\n", "timeSeries = readTimeseries(download = needsUpdate)\n",
"timeSeries" "timeSeries"
] ]
@@ -234,6 +285,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"kreisValues = sorted(kreisValues)\n", "kreisValues = sorted(kreisValues)\n",
"# FK-TODO: die folgenden Optionen in der Datei intensivstationen.html in das select-Element nach \"Alle Landkreise\" einsetzen \n",
"printKreisOptions(kreisValues)" "printKreisOptions(kreisValues)"
] ]
}, },