updating html file with vaccines from table
This commit is contained in:
34
src/SymptomsCausedByVaccines/HtmlUpdater.py
Normal file
34
src/SymptomsCausedByVaccines/HtmlUpdater.py
Normal 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)
|
||||
10
src/SymptomsCausedByVaccines/HtmlUtils.py
Normal file
10
src/SymptomsCausedByVaccines/HtmlUtils.py
Normal 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)
|
||||
Reference in New Issue
Block a user