refactoring

This commit is contained in:
frankknoll
2022-03-16 18:19:18 +01:00
parent 86c99d6c27
commit 72617bc5fb

View File

@@ -108,15 +108,36 @@
"source": [ "source": [
"from bs4 import BeautifulSoup\n", "from bs4 import BeautifulSoup\n",
"\n", "\n",
"def saveLastUpdatedIntensivstationen(lastUpdated):\n", "class HtmlTransformerUtil:\n",
" file = \"../../docs/intensivstationen.html\"\n", " \n",
" def applySoupTransformerToFile(self, file, soupTransformer):\n",
" self._writeSoup(soupTransformer(self._readSoup(file)), file)\n",
"\n",
" def _readSoup(self, file):\n",
" with open(file) as fp:\n", " with open(file) as fp:\n",
" soup = BeautifulSoup(fp, 'lxml')\n", " soup = BeautifulSoup(fp, 'lxml')\n",
" return soup\n",
"\n", "\n",
" soup.find(id = \"Datenstand\").string.replace_with(lastUpdated.strftime(DateProvider.INTENSIVSTATIONEN_DATE_FORMAT))\n", " def _writeSoup(self, soup, file):\n",
"\n",
" with open(file, \"w\") as fp:\n", " with open(file, \"w\") as fp:\n",
" fp.write(str(soup))" " fp.write(str(soup)) \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "af101279",
"metadata": {},
"outputs": [],
"source": [
"def saveLastUpdatedIntensivstationen(lastUpdated):\n",
" def setLastUpdated(soup):\n",
" soup.find(id = \"Datenstand\").string.replace_with(lastUpdated.strftime(DateProvider.INTENSIVSTATIONEN_DATE_FORMAT))\n",
" return soup\n",
"\n",
" HtmlTransformerUtil().applySoupTransformerToFile(\n",
" file = \"../../docs/intensivstationen.html\",\n",
" soupTransformer = setLastUpdated)"
] ]
}, },
{ {
@@ -416,15 +437,11 @@
"source": [ "source": [
"from bs4 import BeautifulSoup\n", "from bs4 import BeautifulSoup\n",
"\n", "\n",
"\n",
"def saveKreisOptions(kreisOptions):\n", "def saveKreisOptions(kreisOptions):\n",
" file = \"../../docs/intensivstationen.html\"\n", " HtmlTransformerUtil().applySoupTransformerToFile(\n",
" with open(file) as fp:\n", " file = \"../../docs/intensivstationen.html\",\n",
" soup = BeautifulSoup(fp, 'lxml')\n", " soupTransformer = lambda soup: BeautifulSoup(KreisOptionsSetter().setKreisOptions(html = str(soup), options = kreisOptions), 'lxml'))\n"
"\n",
" soup = KreisOptionsSetter().setKreisOptions(html = str(soup), options = kreisOptions)\n",
"\n",
" with open(file, \"w\") as fp:\n",
" fp.write(soup)"
] ]
}, },
{ {