refactoring
This commit is contained in:
@@ -108,15 +108,36 @@
|
||||
"source": [
|
||||
"from bs4 import BeautifulSoup\n",
|
||||
"\n",
|
||||
"class HtmlTransformerUtil:\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",
|
||||
" soup = BeautifulSoup(fp, 'lxml')\n",
|
||||
" return soup\n",
|
||||
"\n",
|
||||
" def _writeSoup(self, soup, file):\n",
|
||||
" with open(file, \"w\") as fp:\n",
|
||||
" fp.write(str(soup)) \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "af101279",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def saveLastUpdatedIntensivstationen(lastUpdated):\n",
|
||||
" file = \"../../docs/intensivstationen.html\"\n",
|
||||
" with open(file) as fp:\n",
|
||||
" soup = BeautifulSoup(fp, 'lxml')\n",
|
||||
" def setLastUpdated(soup):\n",
|
||||
" soup.find(id = \"Datenstand\").string.replace_with(lastUpdated.strftime(DateProvider.INTENSIVSTATIONEN_DATE_FORMAT))\n",
|
||||
" return soup\n",
|
||||
"\n",
|
||||
" soup.find(id = \"Datenstand\").string.replace_with(lastUpdated.strftime(DateProvider.INTENSIVSTATIONEN_DATE_FORMAT))\n",
|
||||
"\n",
|
||||
" with open(file, \"w\") as fp:\n",
|
||||
" fp.write(str(soup))"
|
||||
" HtmlTransformerUtil().applySoupTransformerToFile(\n",
|
||||
" file = \"../../docs/intensivstationen.html\",\n",
|
||||
" soupTransformer = setLastUpdated)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -416,15 +437,11 @@
|
||||
"source": [
|
||||
"from bs4 import BeautifulSoup\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def saveKreisOptions(kreisOptions):\n",
|
||||
" file = \"../../docs/intensivstationen.html\"\n",
|
||||
" with open(file) as fp:\n",
|
||||
" soup = BeautifulSoup(fp, 'lxml')\n",
|
||||
"\n",
|
||||
" soup = KreisOptionsSetter().setKreisOptions(html = str(soup), options = kreisOptions)\n",
|
||||
"\n",
|
||||
" with open(file, \"w\") as fp:\n",
|
||||
" fp.write(soup)"
|
||||
" HtmlTransformerUtil().applySoupTransformerToFile(\n",
|
||||
" file = \"../../docs/intensivstationen.html\",\n",
|
||||
" soupTransformer = lambda soup: BeautifulSoup(KreisOptionsSetter().setKreisOptions(html = str(soup), options = kreisOptions), 'lxml'))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user