Files
HowBadIsMyBatch/src/SymptomsCausedByVaccines/HtmlUpdater.py
2023-10-10 11:04:38 +02:00

44 lines
1.5 KiB
Python

from bs4 import BeautifulSoup
from HtmlTransformerUtil import HtmlTransformerUtil
from DateProvider import DateProvider
from SymptomsCausedByVaccines.HtmlUtils import getVaccineOptions, getSymptomOptions
from SymptomsCausedByVaccines.OptionsSetter import OptionsSetter
def updateHtmlFile(vaccines, symptoms, htmlFile, lastUpdated):
_saveOptions(
options = getVaccineOptions(vaccines),
htmlFile = htmlFile,
selectElementId = 'vaccineSelect')
_saveOptions(
options = getSymptomOptions(symptoms),
htmlFile = htmlFile,
selectElementId = 'symptomSelect')
saveLastUpdated2HtmlFile(
lastUpdated = lastUpdated,
htmlFile = htmlFile,
lastUpdatedElementId = 'last_updated')
def _saveOptions(options, htmlFile, selectElementId):
HtmlTransformerUtil().applySoupTransformerToFile(
file=htmlFile,
soupTransformer = lambda soup:
BeautifulSoup(
OptionsSetter().setOptions(
html = str(soup),
selectElementId = selectElementId,
options = options),
'lxml'))
def saveLastUpdated2HtmlFile(lastUpdated, htmlFile, lastUpdatedElementId):
def setLastUpdated(soup):
soup.find(id = lastUpdatedElementId).string.replace_with(
lastUpdated.strftime(DateProvider.DATE_FORMAT))
return soup
HtmlTransformerUtil().applySoupTransformerToFile(
file = htmlFile,
soupTransformer = setLastUpdated)