From 847b885f0da78373e574e255f4c81e4859f8e10f Mon Sep 17 00:00:00 2001 From: ramia bajwa Date: Thu, 18 Mar 2021 16:02:17 -0400 Subject: [PATCH 1/4] Aggregation --- README.md | 2 +- scraping/DatabaseConnector/db_connector.py | 2 ++ scraping/date_converter.py | 29 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 190b3fcd..ccb28c4c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# What is CoronaTracker +# What is CoronaTracker? [CoronaTracker](https://www.coronatracker.com/) is a full-stack web app for the public to track the latest development of Coronavirus, including data, news, and social media. diff --git a/scraping/DatabaseConnector/db_connector.py b/scraping/DatabaseConnector/db_connector.py index 18994fcf..fbc429c2 100644 --- a/scraping/DatabaseConnector/db_connector.py +++ b/scraping/DatabaseConnector/db_connector.py @@ -3,6 +3,8 @@ class DatabaseConnector: + #aggregate root + def __init__(self, config_path="./"): self.mysql = None self.config_path = config_path diff --git a/scraping/date_converter.py b/scraping/date_converter.py index 5e0839ea..ca8098d0 100644 --- a/scraping/date_converter.py +++ b/scraping/date_converter.py @@ -11,3 +11,32 @@ print(type(datetime_object)) print(datetime_object) # printed in default format print(datetime_object.astimezone(timezone.utc)) + + +import re +from datetime import datetime, timezone + +Class Datetime: + #Aggregate root + +def __init__(self, date, time, str): + +#ConvertDate main identifier date and time. + self.date = date + self.time = time + self.str = str + +str = "Sat, 25 Jan 2020 01:52:22 +2000" + +all = re.findall(r"[\d]{1,2} [ADFJMNOS]\w* [\d]{4} \b(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9] [\+]{1}[0-9]{4}\b", str) + +datetime_str = all[0] # '09/19/18 13:55:26' + +datetime_object = datetime.strptime(datetime_str, '%d %b %Y %H:%M:%S %z') + +#created new instance of the class +Convdatetime = Datetime(date, time, str) + +print(type(datetime_object)) +print(datetime_object) # printed in default format +print(datetime_object.astimezone(timezone.utc)) From 108f81a4fbe667af99b5a80f79b2cab551b2b01a Mon Sep 17 00:00:00 2001 From: Ramia Ejaz <77527087+ramiabaj@users.noreply.github.com> Date: Fri, 19 Mar 2021 14:16:04 -0400 Subject: [PATCH 2/4] Update date_converter.py --- scraping/date_converter.py | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/scraping/date_converter.py b/scraping/date_converter.py index ca8098d0..b74d9163 100644 --- a/scraping/date_converter.py +++ b/scraping/date_converter.py @@ -13,30 +13,3 @@ print(datetime_object.astimezone(timezone.utc)) -import re -from datetime import datetime, timezone - -Class Datetime: - #Aggregate root - -def __init__(self, date, time, str): - -#ConvertDate main identifier date and time. - self.date = date - self.time = time - self.str = str - -str = "Sat, 25 Jan 2020 01:52:22 +2000" - -all = re.findall(r"[\d]{1,2} [ADFJMNOS]\w* [\d]{4} \b(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9] [\+]{1}[0-9]{4}\b", str) - -datetime_str = all[0] # '09/19/18 13:55:26' - -datetime_object = datetime.strptime(datetime_str, '%d %b %Y %H:%M:%S %z') - -#created new instance of the class -Convdatetime = Datetime(date, time, str) - -print(type(datetime_object)) -print(datetime_object) # printed in default format -print(datetime_object.astimezone(timezone.utc)) From bd0af34886b5e96b9828e644f9288b1bf8adb503 Mon Sep 17 00:00:00 2001 From: ramia bajwa Date: Wed, 14 Apr 2021 01:58:09 -0400 Subject: [PATCH 3/4] Creational Builder Design Pattern --- .DS_Store | Bin 6148 -> 6148 bytes scraping/.DS_Store | Bin 6148 -> 8196 bytes scraping/ScrapeBingCovid/scrape_bing.py | 117 ++++++++++++++++++++++++ 3 files changed, 117 insertions(+) diff --git a/.DS_Store b/.DS_Store index 11a502813656be9f88710c5115eec7056682f59f..8eba4f05c16559d5511741b02d9449be3e0558be 100644 GIT binary patch delta 687 zcmZWn&ubGw6n?W?(@AX1Ce4qEiq%jM8bXSup$9RIphShlrr3m57dJE8-A&sx z#whd;XxW2$F5U!@90kFfC$Ano_z(0V9(6X`(qiW@^UZtTd*3(1+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M-Ki9P!i;9ESoDw{&=ZV7 zG3yiyGHsPG69&Cx zW#yZgn4G$BaoVzGteLr)m(6zEZzfK1*lRf5=lt!FleAr3-;Luitvl}1!0)#fu5QFp z;slZ3mEgehq4MHc5P5OG5g$fgPugj!2bNW_Dy@a;V6eKrY~Q)PK3uj3Yilc9zdIaO ztm=)`dpmmv$8QJkh9@7uFp|)(N19jP)AA!~f8ea(`$~@C$M9G$&noYy9IMmXs{wXj zQqsoxk<(t3-sYW(lLC9TOUGCVymQn}F0CSg)t<93hgIWa|NYu;r?-#A^@npqoMcu{ zN{gu&2F8|wNj38&j{mpLzyBXwe$2!T1LMGenA&V^HZarE9}mSzbF6J6?;&$yy^)d< mfROJJL<^F+2#_?G!Z7ep8TbjOYEZQR delta 176 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{MGjdEU6q~50D9QrjfW=Z65*bPu5ng+FGDdyGD8tis(>MtAs)yoW+ Date: Thu, 15 Apr 2021 22:34:19 -0400 Subject: [PATCH 4/4] Structural Design Pattern --- .DS_Store | Bin 6148 -> 6148 bytes scraping/.DS_Store | Bin 8196 -> 8196 bytes scraping/DatabaseConnector/db_connector.py | 44 +++++++++++++++++++-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/.DS_Store b/.DS_Store index 8eba4f05c16559d5511741b02d9449be3e0558be..161cd8654652e4de5e590333d45ad0bbcb25b2e3 100644 GIT binary patch delta 263 zcmZoMXffEZm6dVx~oGXMYp delta 270 zcmZoMXffEZm6dVdv5u90-3RW6ikeHmAm#%F8 zfdLFSl^rx7ECB{(2!nw^*})CM3||@kGx9QuF)A@?GwK*InlhR*Ixu=NdNKMi1~LXQMneo>VuTtb U3#FkHW6I=A_Q{*sIsWnk09mIxXaE2J diff --git a/scraping/.DS_Store b/scraping/.DS_Store index 79fefc49cf96e884013c27c41196613443bbd5de..acc2eb4a480e478e9e62f2ff8c5c4ad0fd313cdd 100644 GIT binary patch delta 58 zcmZp1XmOa}&nU7nU^hRb$YdUY+R5$$ijx(DuTORrQ06HMF3QWv&r4@uU|`(bA`s5D OnO))=%jS#1?92cZ-x0F_ delta 36 scmZp1XmOa}&nUDpU^hRb&}1Hg+Ra-9gV;7U=rC?(m-xoAv4Wi$0Nx1;vj6}9 diff --git a/scraping/DatabaseConnector/db_connector.py b/scraping/DatabaseConnector/db_connector.py index fbc429c2..0cded7ef 100644 --- a/scraping/DatabaseConnector/db_connector.py +++ b/scraping/DatabaseConnector/db_connector.py @@ -2,9 +2,19 @@ import json -class DatabaseConnector: - #aggregate root - + +"""Adapter Design Pattern""" + +from abc import ABCMeta, abstractmethod + +class IA(metaclass=ABCMeta): +@staticmethod +@abstractmethod + +def method_a(): +"""an abstract method""" + +class DatabaseConnector(IA): def __init__(self, config_path="./"): self.mysql = None self.config_path = config_path @@ -20,6 +30,12 @@ def connect(self): ) print("Database connected: {}".format(info)) +class IB(metaclass=ABCMeta): + @staticmethod + @abstractmethod + def method_b(): + +class NewsArticle(IB): def select(self): cursor = self.mydb.cursor() mycursor.execute("SELECT * FROM {}".format(TABLE_NAME)) @@ -68,9 +84,29 @@ def insert_news_article(self, data_dict, table_name): print(ex) print("Record not inserted") + class NewsAticleAdapter(IA): + def __init__(self): + self.classNA = NewsArticle() + + def method_a(self): + """Calls class NewsArticle method insert_news_article""" + self.NewsArticle.insert_news_aticle() + +RESULT = NewsArticleAdapter() +RESULT.method_a() + + # worldometers TABLE_SCHEMA # country, total_cases, total_deaths, total_recovered, total_tests, new_cases, new_deaths, active_cases, serious_critical_cases, total_cases_per_million_pop, total_tests_per_million_pop, last_updated - def insert_worldometer_stats(self, data_dict, table_name): + + +class IC(metaclass=ABCMeta): + @staticmethod + @abstractmethod + def method_c(): + + class Worldometers(IC): + def insert_worldometer_stats(self, data_dict, table_name): if not table_name: raise ValueError("db_connector insert_worldometer missing table_name") table_name = table_name