refactoring
This commit is contained in:
@@ -26,34 +26,45 @@
|
|||||||
"import re\n",
|
"import re\n",
|
||||||
"from dateutil.parser import parse\n",
|
"from dateutil.parser import parse\n",
|
||||||
"\n",
|
"\n",
|
||||||
"def needsUpdate():\n",
|
"class DateProvider:\n",
|
||||||
" lastUpdated = _getLastUpdated()\n",
|
" \n",
|
||||||
|
" def needsUpdate(self):\n",
|
||||||
|
" lastUpdated = self._getLastUpdated()\n",
|
||||||
" print(' lastUpdated:', lastUpdated)\n",
|
" print(' lastUpdated:', lastUpdated)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" lastUpdatedDataSource = _getLastUpdatedDataSource()\n",
|
" lastUpdatedDataSource = self._getLastUpdatedDataSource()\n",
|
||||||
" print('lastUpdatedDataSource:', lastUpdatedDataSource)\n",
|
" print('lastUpdatedDataSource:', lastUpdatedDataSource)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" return lastUpdated < lastUpdatedDataSource\n",
|
" return lastUpdated < lastUpdatedDataSource\n",
|
||||||
" \n",
|
" \n",
|
||||||
"def _getLastUpdated():\n",
|
" def _getLastUpdated(self):\n",
|
||||||
" return __getLastUpdated(\n",
|
" return self.__getLastUpdated(\n",
|
||||||
" url = \"https://knollfrank.github.io/HowBadIsMyBatch/batchCodeTable.html\",\n",
|
" url = \"https://knollfrank.github.io/HowBadIsMyBatch/batchCodeTable.html\",\n",
|
||||||
" getDateStr = lambda soup: soup.find(id = \"last_updated\").text)\n",
|
" getDateStr = lambda soup: soup.find(id = \"last_updated\").text)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"def _getLastUpdatedDataSource():\n",
|
" def _getLastUpdatedDataSource(self):\n",
|
||||||
" def getDateStr(soup):\n",
|
" def getDateStr(soup):\n",
|
||||||
" lastUpdated = soup.find(string = re.compile(\"Last updated\"))\n",
|
" lastUpdated = soup.find(string = re.compile(\"Last updated\"))\n",
|
||||||
" return re.search('Last updated: (.+).', lastUpdated).group(1)\n",
|
" return re.search('Last updated: (.+).', lastUpdated).group(1)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" return __getLastUpdated(url = \"https://vaers.hhs.gov/data/datasets.html\", getDateStr = getDateStr)\n",
|
" return self.__getLastUpdated(url = \"https://vaers.hhs.gov/data/datasets.html\", getDateStr = getDateStr)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"def __getLastUpdated(url, getDateStr):\n",
|
" def __getLastUpdated(self, url, getDateStr):\n",
|
||||||
" htmlContent = requests.get(url).text\n",
|
" htmlContent = requests.get(url).text\n",
|
||||||
" soup = BeautifulSoup(htmlContent, \"lxml\")\n",
|
" soup = BeautifulSoup(htmlContent, \"lxml\")\n",
|
||||||
" dateStr = getDateStr(soup)\n",
|
" dateStr = getDateStr(soup)\n",
|
||||||
" return parse(dateStr).date()\n",
|
" return parse(dateStr).date()"
|
||||||
"\n",
|
]
|
||||||
"print('needsUpdate:', needsUpdate())"
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "ffad1c04",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"dateProvider = DateProvider()\n",
|
||||||
|
"print('needsUpdate:', dateProvider.needsUpdate())"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user