updating html file with vaccines from table

This commit is contained in:
frankknoll
2023-10-10 10:30:26 +02:00
parent e457568ef6
commit 16b5d7a57f
4 changed files with 215 additions and 17 deletions

View File

@@ -0,0 +1,34 @@
from bs4 import BeautifulSoup
from HtmlTransformerUtil import HtmlTransformerUtil
from DateProvider import DateProvider
from SymptomsCausedByVaccines.Analyzer import Analyzer
from SymptomsCausedByVaccines.HtmlUtils import getVaccineOptions
from SymptomsCausedByVaccines.OptionsSetter import OptionsSetter
def updateHtmlFile(symptomByVaccine, htmlFile, lastUpdated):
vaccineOptions = getVaccineOptions(Analyzer(symptomByVaccine).getVaccines())
_saveVaccineOptions(vaccineOptions, htmlFile)
saveLastUpdated2HtmlFile(lastUpdated, htmlFile)
def _saveVaccineOptions(vaccineOptions, htmlFile):
HtmlTransformerUtil().applySoupTransformerToFile(
file=htmlFile,
soupTransformer = lambda soup:
BeautifulSoup(
OptionsSetter().setOptions(
html = str(soup),
selectElementId = 'vaccineSelect',
options = vaccineOptions),
'lxml'))
# FK-TODO: DRY with src/BatchCodeTableHtmlUpdater.py
def saveLastUpdated2HtmlFile(lastUpdated, htmlFile):
def setLastUpdated(soup):
soup.find(id="last_updated").string.replace_with(
lastUpdated.strftime(DateProvider.DATE_FORMAT))
return soup
HtmlTransformerUtil().applySoupTransformerToFile(
file = htmlFile,
soupTransformer = setLastUpdated)

View File

@@ -0,0 +1,10 @@
def getVaccineOptions(vaccines):
return ['<option hidden disabled selected value>Select Vaccine</option>'] + _getVaccineOptions(vaccines)
def _getVaccineOptions(vaccines):
return [_getVaccineOption(vaccine) for vaccine in vaccines]
def _getVaccineOption(vaccine):
return '<option value="{vaccine}">{vaccine}</option>'.format(vaccine=vaccine)