saveCountryOptions()
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<html>
|
||||
|
||||
<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>Batch Codes of Coronavirus 2019 Vaccines</title>
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.4/css/jquery.dataTables.css">
|
||||
<link rel="stylesheet" type="text/css" href="batchCodeTable.css">
|
||||
<link rel="stylesheet" type="text/css" href="forkMeOnGitHub.css">
|
||||
<link href="https://cdn.datatables.net/1.11.4/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
|
||||
<link href="batchCodeTable.css" rel="stylesheet" type="text/css" />
|
||||
<link href="forkMeOnGitHub.css" rel="stylesheet" type="text/css" />
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
<script type="text/javascript" charset="utf8"
|
||||
src="https://cdn.datatables.net/1.11.4/js/jquery.dataTables.min.js"></script>
|
||||
<script charset="utf8" src="https://cdn.datatables.net/1.11.4/js/jquery.dataTables.min.js"
|
||||
type="text/javascript"></script>
|
||||
<script src="./batchCodeTable.js"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
@@ -32,7 +32,7 @@
|
||||
<p>
|
||||
<label>Select country:
|
||||
<select id="countrySelect" name="country">
|
||||
<option value="Global" selected>Global</option>
|
||||
<option selected="" value="Global">Global</option>
|
||||
<option value="Afghanistan">Afghanistan</option>
|
||||
<option value="Albania">Albania</option>
|
||||
<option value="Algeria">Algeria</option>
|
||||
@@ -161,11 +161,11 @@
|
||||
<option value="Zambia">Zambia</option>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
<h2 class="heading"></h2>
|
||||
<p>
|
||||
<b>Check out your batch code</b> (Last updated: <span id="last_updated">March 18, 2022</span>)
|
||||
</p>
|
||||
<p>
|
||||
<table class="display" id="batchCodeTable">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -181,7 +181,6 @@
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</p>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -365,6 +365,80 @@
|
||||
" return self.countryBatchCodeTable[0:0].droplevel(0)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "4db36933",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"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": "32d4eecf",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from bs4 import BeautifulSoup\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class CountryOptionsSetter:\n",
|
||||
"\n",
|
||||
" def setCountryOptions(self, html, options):\n",
|
||||
" soup = self._setCountryOptions(self._parse(html), self._parseOptions(options))\n",
|
||||
" return str(soup)\n",
|
||||
"\n",
|
||||
" def _setCountryOptions(self, soup, options):\n",
|
||||
" countrySelect = soup.find(id = \"countrySelect\")\n",
|
||||
" countrySelect.clear()\n",
|
||||
" for option in options:\n",
|
||||
" countrySelect.append(option)\n",
|
||||
" return soup\n",
|
||||
"\n",
|
||||
" def _parseOptions(self, options):\n",
|
||||
" return [self._parse(option).option for option in options]\n",
|
||||
"\n",
|
||||
" def _parse(self, html):\n",
|
||||
" return BeautifulSoup(html, 'lxml')\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "2f0f9b4b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from bs4 import BeautifulSoup\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def saveCountryOptions(countryOptions):\n",
|
||||
" HtmlTransformerUtil().applySoupTransformerToFile(\n",
|
||||
" file = \"../docs/batchCodeTable.html\",\n",
|
||||
" soupTransformer =\n",
|
||||
" lambda soup:\n",
|
||||
" BeautifulSoup(\n",
|
||||
" CountryOptionsSetter().setCountryOptions(html = str(soup), options = countryOptions),\n",
|
||||
" 'lxml'))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -684,6 +758,85 @@
|
||||
" check_dtype = False)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "125351b3",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class CountryOptionsSetterTest(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_setCountryOptions(self):\n",
|
||||
" # Given\n",
|
||||
" countryOptionsSetter = CountryOptionsSetter()\n",
|
||||
"\n",
|
||||
" # When\n",
|
||||
" htmlActual = countryOptionsSetter.setCountryOptions(\n",
|
||||
" html='''\n",
|
||||
" <html>\n",
|
||||
" <body>\n",
|
||||
" <p>Test<p/>\n",
|
||||
" <select id=\"countrySelect\" name=\"country\">\n",
|
||||
" <option value=\"Global\" selected>Global</option>\n",
|
||||
" <option value=\"Afghanistan\">Afghanistan</option>\n",
|
||||
" <option value=\"Albania\">Albania</option>\n",
|
||||
" <option value=\"Algeria\">Algeria</option>\n",
|
||||
" </select>\n",
|
||||
" </body>\n",
|
||||
" </html>\n",
|
||||
" ''',\n",
|
||||
" options=[\n",
|
||||
" '<option value=\"Global\" selected>Global</option>',\n",
|
||||
" '<option value=\"Azerbaijan\">Azerbaijan</option>',\n",
|
||||
" '<option value=\"Bahrain\">Bahrain</option>'])\n",
|
||||
"\n",
|
||||
" # Then\n",
|
||||
" assertEqualHTML(\n",
|
||||
" htmlActual,\n",
|
||||
" '''\n",
|
||||
" <html>\n",
|
||||
" <body>\n",
|
||||
" <p>Test<p/>\n",
|
||||
" <select id=\"countrySelect\" name=\"country\">\n",
|
||||
" <option value=\"Global\" selected>Global</option>\n",
|
||||
" <option value=\"Azerbaijan\">Azerbaijan</option>\n",
|
||||
" <option value=\"Bahrain\">Bahrain</option>\n",
|
||||
" </select>\n",
|
||||
" </body>\n",
|
||||
" </html>\n",
|
||||
" ''')\n",
|
||||
"\n",
|
||||
"# adapted from https://stackoverflow.com/questions/8006909/pretty-print-assertequal-for-html-strings\n",
|
||||
"def assertEqualHTML(string1, string2, file1='', file2=''):\n",
|
||||
" u'''\n",
|
||||
" Compare two unicode strings containing HTML.\n",
|
||||
" A human friendly diff goes to logging.error() if they\n",
|
||||
" are not equal, and an exception gets raised.\n",
|
||||
" '''\n",
|
||||
" from bs4 import BeautifulSoup as bs\n",
|
||||
" import difflib\n",
|
||||
"\n",
|
||||
" def short(mystr):\n",
|
||||
" max = 20\n",
|
||||
" if len(mystr) > max:\n",
|
||||
" return mystr[:max]\n",
|
||||
" return mystr\n",
|
||||
" p = []\n",
|
||||
" for mystr, file in [(string1, file1), (string2, file2)]:\n",
|
||||
" if not isinstance(mystr, str):\n",
|
||||
" raise Exception(u'string ist not unicode: %r %s' %\n",
|
||||
" (short(mystr), file))\n",
|
||||
" soup = bs(mystr)\n",
|
||||
" pretty = soup.prettify()\n",
|
||||
" p.append(pretty)\n",
|
||||
" if p[0] != p[1]:\n",
|
||||
" for line in difflib.unified_diff(p[0].splitlines(), p[1].splitlines(), fromfile=file1, tofile=file2):\n",
|
||||
" display(line)\n",
|
||||
" display(p[0], ' != ', p[1])\n",
|
||||
" raise Exception('Not equal %s %s' % (file1, file2))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -766,13 +919,11 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# FK-TODO: analog zu Intensivstationen.ipynb einen KreisOptionsSetter einsetzen zum automatischen Speichern der Options in der html-Datei\n",
|
||||
"def printCountryOptions(countries):\n",
|
||||
" for country in countries:\n",
|
||||
" printCountryOption(country)\n",
|
||||
"def getCountryOptions(countries):\n",
|
||||
" return [getCountryOption(country) for country in countries]\n",
|
||||
"\n",
|
||||
"def printCountryOption(country):\n",
|
||||
" print('<option value=\"{country}\">{country}</option>'.format(country = country))"
|
||||
"def getCountryOption(country):\n",
|
||||
" return '<option value=\"{country}\">{country}</option>'.format(country = country)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -782,8 +933,27 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"countries = sorted(internationalVaersCovid19['COUNTRY'].unique())\n",
|
||||
"printCountryOptions(countries)"
|
||||
"countries = sorted(internationalVaersCovid19['COUNTRY'].unique())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "1c518028",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"countryOptions = ['<option value=\"Global\" selected>Global</option>'] + getCountryOptions(countries)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "8d6507ca",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"saveCountryOptions(countryOptions)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ FK-FIXME:
|
||||
|
||||
FK-TODO:
|
||||
- Darstellung als Dashboard, siehe https://covid-karte.de/ oder https://experience.arcgis.com/experience/3a132983ad3c4ab8a28704e9addefaba
|
||||
- Rot-Gelb-Grün eingefärbte Deutschland-Karte anzeigen wie in https://experience.arcgis.com/experience/3a132983ad3c4ab8a28704e9addefaba
|
||||
- nach den "Median der Anteile freier Betten"-Werten Rot-Gelb-Grün eingefärbte Deutschland-Karte anzeigen wie in https://experience.arcgis.com/experience/3a132983ad3c4ab8a28704e9addefaba
|
||||
- Alle Charts mit Slidern versehen?
|
||||
|
||||
anacron job:
|
||||
|
||||
@@ -432,8 +432,6 @@
|
||||
" ''')\n",
|
||||
"\n",
|
||||
"# adapted from https://stackoverflow.com/questions/8006909/pretty-print-assertequal-for-html-strings\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def assertEqualHTML(string1, string2, file1='', file2=''):\n",
|
||||
" u'''\n",
|
||||
" Compare two unicode strings containing HTML.\n",
|
||||
|
||||
Reference in New Issue
Block a user