Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavioural pattern iterator #210

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update db_connector.py
kekekekasper authored Apr 13, 2021
commit 4c3325a0cef8963ea339e4d2103a26a3851ea764
81 changes: 4 additions & 77 deletions scraping/DatabaseConnector/db_connector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mysql.connector
import json

import DatabaseConnectorBuilder

class DatabaseConnector:
def __init__(self, config_path="./"):
@@ -33,30 +33,7 @@ def insert_news_article(self, data_dict, table_name):
sql = "INSERT INTO {} (title, description, author, url, content, urlToImage, publishedAt, addedOn, siteName, language, countryCode, status) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE title = %s, description = %s, author = %s, content = %s, urlToImage = %s, publishedAt = %s, addedOn = %s, siteName = %s, language = %s, countryCode = %s".format(
table_name
)
val = (
data_dict["title"],
data_dict["description"],
data_dict["author"],
data_dict["url"],
data_dict["content"],
data_dict["urlToImage"],
data_dict["publishedAt"],
data_dict["addedOn"],
data_dict["siteName"],
data_dict["language"],
data_dict["countryCode"],
1, # Status
data_dict["title"],
data_dict["description"],
data_dict["author"],
data_dict["content"],
data_dict["urlToImage"],
data_dict["publishedAt"],
data_dict["addedOn"],
data_dict["siteName"],
data_dict["language"],
data_dict["countryCode"],
)
val = Build.build_news_article()
print("SQL query: ", sql, val)
try:
mycursor.execute(sql, val)
@@ -76,33 +53,7 @@ def insert_worldometer_stats(self, data_dict, table_name):
sql = "INSERT INTO {} (country, total_cases, total_deaths, total_recovered, total_tests, new_cases, new_deaths, active_cases, serious_critical_cases, total_cases_per_million_pop, total_deaths_per_million_pop, total_tests_per_million_pop, last_updated) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE country = %s, total_cases = %s, total_deaths = %s, total_recovered = %s, total_tests = %s, new_cases = %s, new_deaths = %s, active_cases = %s, serious_critical_cases = %s, total_cases_per_million_pop = %s, total_deaths_per_million_pop = %s, total_tests_per_million_pop = %s".format(
table_name
)
val = (
data_dict["country"],
data_dict["total_cases"],
data_dict["total_deaths"],
data_dict["total_recovered"],
data_dict["total_tests"],
data_dict["new_cases"],
data_dict["new_deaths"],
data_dict["active_cases"],
data_dict["serious_critical_cases"],
data_dict["total_cases_per_million_pop"],
data_dict["total_deaths_per_million_pop"],
data_dict["total_tests_per_million_pop"],
data_dict["last_updated"],
data_dict["country"],
data_dict["total_cases"],
data_dict["total_deaths"],
data_dict["total_recovered"],
data_dict["total_tests"],
data_dict["new_cases"],
data_dict["new_deaths"],
data_dict["active_cases"],
data_dict["serious_critical_cases"],
data_dict["total_cases_per_million_pop"],
data_dict["total_deaths_per_million_pop"],
data_dict["total_tests_per_million_pop"],
)
val = Build.build_worldometer_stats()
print("SQL query: ", sql, val)
try:
mycursor.execute(sql, val)
@@ -124,31 +75,7 @@ def insert_worldometers_total_sum(self, data_dict, table_name):
sql = "INSERT INTO {} (total_cases, total_deaths, total_recovered, total_tests, new_cases, new_deaths, active_cases, serious_critical_cases, total_cases_per_million_pop, total_deaths_per_million_pop, total_tests_per_million_pop, last_updated) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE total_cases = %s, total_deaths = %s, total_recovered = %s, total_tests = %s, new_cases = %s, new_deaths = %s, active_cases = %s, serious_critical_cases = %s, total_cases_per_million_pop = %s, total_deaths_per_million_pop = %s, total_tests_per_million_pop = %s".format(
table_name
)
val = (
data_dict["total_cases"],
data_dict["total_deaths"],
data_dict["total_recovered"],
data_dict["total_tests"],
data_dict["new_cases"],
data_dict["new_deaths"],
data_dict["active_cases"],
data_dict["serious_critical_cases"],
data_dict["total_cases_per_million_pop"],
data_dict["total_deaths_per_million_pop"],
data_dict["total_tests_per_million_pop"],
data_dict["last_updated"],
data_dict["total_cases"],
data_dict["total_deaths"],
data_dict["total_recovered"],
data_dict["total_tests"],
data_dict["new_cases"],
data_dict["new_deaths"],
data_dict["active_cases"],
data_dict["serious_critical_cases"],
data_dict["total_cases_per_million_pop"],
data_dict["total_deaths_per_million_pop"],
data_dict["total_tests_per_million_pop"],
)
val = Build.build_worldometers_total_sum()
print("SQL query: ", sql, val)
try:
mycursor.execute(sql, val)