refactoring

This commit is contained in:
frankknoll
2023-10-10 10:38:52 +02:00
parent 16b5d7a57f
commit d2ad1b805a
2 changed files with 11 additions and 16 deletions

View File

@@ -2,13 +2,16 @@ from bs4 import BeautifulSoup
from HtmlTransformerUtil import HtmlTransformerUtil from HtmlTransformerUtil import HtmlTransformerUtil
from BatchcodeOptionsSetter import BatchcodeOptionsSetter from BatchcodeOptionsSetter import BatchcodeOptionsSetter
from HtmlUtils import getBatchcodeOptions, getBatchcodes from HtmlUtils import getBatchcodeOptions, getBatchcodes
from DateProvider import DateProvider from SymptomsCausedByVaccines.HtmlUpdater import saveLastUpdated2HtmlFile
def updateBatchCodeTableHtmlFile(batchCodeTable, batchCodeTableHtmlFile, lastUpdated): def updateBatchCodeTableHtmlFile(batchCodeTable, batchCodeTableHtmlFile, lastUpdated):
batchcodeOptions = getBatchcodeOptions(getBatchcodes(batchCodeTable.sort_values(by = 'Adverse Reaction Reports', ascending = False))) batchcodeOptions = getBatchcodeOptions(getBatchcodes(batchCodeTable.sort_values(by = 'Adverse Reaction Reports', ascending = False)))
_saveBatchcodeOptions(batchcodeOptions, batchCodeTableHtmlFile) _saveBatchcodeOptions(batchcodeOptions, batchCodeTableHtmlFile)
saveLastUpdated2HtmlFile(lastUpdated, batchCodeTableHtmlFile) saveLastUpdated2HtmlFile(
lastUpdated = lastUpdated,
htmlFile = batchCodeTableHtmlFile,
lastUpdatedElementId = 'last_updated')
def _saveBatchcodeOptions(batchcodeOptions, batchCodeTableHtmlFile): def _saveBatchcodeOptions(batchcodeOptions, batchCodeTableHtmlFile):
HtmlTransformerUtil().applySoupTransformerToFile( HtmlTransformerUtil().applySoupTransformerToFile(
@@ -19,13 +22,3 @@ def _saveBatchcodeOptions(batchcodeOptions, batchCodeTableHtmlFile):
html=str(soup), html=str(soup),
options=batchcodeOptions), options=batchcodeOptions),
'lxml')) 'lxml'))
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

@@ -9,7 +9,10 @@ from SymptomsCausedByVaccines.OptionsSetter import OptionsSetter
def updateHtmlFile(symptomByVaccine, htmlFile, lastUpdated): def updateHtmlFile(symptomByVaccine, htmlFile, lastUpdated):
vaccineOptions = getVaccineOptions(Analyzer(symptomByVaccine).getVaccines()) vaccineOptions = getVaccineOptions(Analyzer(symptomByVaccine).getVaccines())
_saveVaccineOptions(vaccineOptions, htmlFile) _saveVaccineOptions(vaccineOptions, htmlFile)
saveLastUpdated2HtmlFile(lastUpdated, htmlFile) saveLastUpdated2HtmlFile(
lastUpdated = lastUpdated,
htmlFile = htmlFile,
lastUpdatedElementId = 'last_updated')
def _saveVaccineOptions(vaccineOptions, htmlFile): def _saveVaccineOptions(vaccineOptions, htmlFile):
HtmlTransformerUtil().applySoupTransformerToFile( HtmlTransformerUtil().applySoupTransformerToFile(
@@ -22,10 +25,9 @@ def _saveVaccineOptions(vaccineOptions, htmlFile):
options = vaccineOptions), options = vaccineOptions),
'lxml')) 'lxml'))
# FK-TODO: DRY with src/BatchCodeTableHtmlUpdater.py def saveLastUpdated2HtmlFile(lastUpdated, htmlFile, lastUpdatedElementId):
def saveLastUpdated2HtmlFile(lastUpdated, htmlFile):
def setLastUpdated(soup): def setLastUpdated(soup):
soup.find(id="last_updated").string.replace_with( soup.find(id = lastUpdatedElementId).string.replace_with(
lastUpdated.strftime(DateProvider.DATE_FORMAT)) lastUpdated.strftime(DateProvider.DATE_FORMAT))
return soup return soup