From 6c67bd601a1ad3a96972954f99fe571e20f7ab34 Mon Sep 17 00:00:00 2001 From: frankknoll Date: Thu, 24 Mar 2022 10:30:27 +0100 Subject: [PATCH] refactoring --- src/HowBadIsMyBatch.ipynb | 57 +++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/HowBadIsMyBatch.ipynb b/src/HowBadIsMyBatch.ipynb index b4f373d9c2f..7b9e84c10f1 100644 --- a/src/HowBadIsMyBatch.ipynb +++ b/src/HowBadIsMyBatch.ipynb @@ -26,34 +26,45 @@ "import re\n", "from dateutil.parser import parse\n", "\n", - "def needsUpdate():\n", - " lastUpdated = _getLastUpdated()\n", - " print(' lastUpdated:', lastUpdated)\n", - "\n", - " lastUpdatedDataSource = _getLastUpdatedDataSource()\n", - " print('lastUpdatedDataSource:', lastUpdatedDataSource)\n", - "\n", - " return lastUpdated < lastUpdatedDataSource\n", + "class DateProvider:\n", " \n", - "def _getLastUpdated():\n", - " return __getLastUpdated(\n", - " url = \"https://knollfrank.github.io/HowBadIsMyBatch/batchCodeTable.html\",\n", - " getDateStr = lambda soup: soup.find(id = \"last_updated\").text)\n", + " def needsUpdate(self):\n", + " lastUpdated = self._getLastUpdated()\n", + " print(' lastUpdated:', lastUpdated)\n", "\n", - "def _getLastUpdatedDataSource():\n", - " def getDateStr(soup):\n", - " lastUpdated = soup.find(string = re.compile(\"Last updated\"))\n", - " return re.search('Last updated: (.+).', lastUpdated).group(1)\n", + " lastUpdatedDataSource = self._getLastUpdatedDataSource()\n", + " print('lastUpdatedDataSource:', lastUpdatedDataSource)\n", "\n", - " return __getLastUpdated(url = \"https://vaers.hhs.gov/data/datasets.html\", getDateStr = getDateStr)\n", + " return lastUpdated < lastUpdatedDataSource\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", "\n", - "def __getLastUpdated(url, getDateStr):\n", - " htmlContent = requests.get(url).text\n", - " soup = BeautifulSoup(htmlContent, \"lxml\")\n", - " dateStr = getDateStr(soup)\n", - " return parse(dateStr).date()\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", "\n", - "print('needsUpdate:', needsUpdate())" + " return self.__getLastUpdated(url = \"https://vaers.hhs.gov/data/datasets.html\", getDateStr = getDateStr)\n", + "\n", + " def __getLastUpdated(self, url, getDateStr):\n", + " htmlContent = requests.get(url).text\n", + " soup = BeautifulSoup(htmlContent, \"lxml\")\n", + " dateStr = getDateStr(soup)\n", + " return parse(dateStr).date()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ffad1c04", + "metadata": {}, + "outputs": [], + "source": [ + "dateProvider = DateProvider()\n", + "print('needsUpdate:', dateProvider.needsUpdate())" ] }, {