refactoring

This commit is contained in:
frankknoll
2022-03-24 10:43:18 +01:00
parent 6c67bd601a
commit 3f4c1bdc7b
2 changed files with 27 additions and 18 deletions

View File

@@ -28,26 +28,32 @@
"\n",
"class DateProvider:\n",
" \n",
" def __init__(self):\n",
" self.lastUpdated = None\n",
" self.lastUpdatedDataSource = None\n",
"\n",
" def needsUpdate(self):\n",
" lastUpdated = self._getLastUpdated()\n",
" print(' lastUpdated:', lastUpdated)\n",
"\n",
" lastUpdatedDataSource = self._getLastUpdatedDataSource()\n",
" print('lastUpdatedDataSource:', lastUpdatedDataSource)\n",
"\n",
" return lastUpdated < lastUpdatedDataSource\n",
" return self.getLastUpdated() < self.getLastUpdatedDataSource()\n",
" \n",
" def _getLastUpdated(self):\n",
" return self.__getLastUpdated(\n",
" url = \"https://knollfrank.github.io/HowBadIsMyBatch/batchCodeTable.html\",\n",
" getDateStr = lambda soup: soup.find(id = \"last_updated\").text)\n",
" def getLastUpdated(self):\n",
" if self.lastUpdated is None:\n",
" self.lastUpdated = self.__getLastUpdated(\n",
" url = \"https://knollfrank.github.io/HowBadIsMyBatch/batchCodeTable.html\",\n",
" getDateStr = lambda soup: soup.find(id = \"last_updated\").text)\n",
" \n",
" return self.lastUpdated\n",
"\n",
" def _getLastUpdatedDataSource(self):\n",
" def getDateStr(soup):\n",
" lastUpdated = soup.find(string = re.compile(\"Last updated\"))\n",
" return re.search('Last updated: (.+).', lastUpdated).group(1)\n",
" def getLastUpdatedDataSource(self):\n",
" if self.lastUpdatedDataSource is None:\n",
" def getDateStr(soup):\n",
" lastUpdated = soup.find(string = re.compile(\"Last updated\"))\n",
" return re.search('Last updated: (.+).', lastUpdated).group(1)\n",
"\n",
" return self.__getLastUpdated(url = \"https://vaers.hhs.gov/data/datasets.html\", getDateStr = getDateStr)\n",
" self.lastUpdatedDataSource = self.__getLastUpdated(\n",
" url = \"https://vaers.hhs.gov/data/datasets.html\",\n",
" getDateStr = getDateStr)\n",
"\n",
" return self.lastUpdatedDataSource\n",
"\n",
" def __getLastUpdated(self, url, getDateStr):\n",
" htmlContent = requests.get(url).text\n",
@@ -64,7 +70,10 @@
"outputs": [],
"source": [
"dateProvider = DateProvider()\n",
"print('needsUpdate:', dateProvider.needsUpdate())"
"print(' lastUpdated:', dateProvider.getLastUpdated())\n",
"print('lastUpdatedDataSource:', dateProvider.getLastUpdatedDataSource()) \n",
"needsUpdate = dateProvider.needsUpdate()\n",
"print('needsUpdate:', needsUpdate)"
]
},
{