-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added scripts to manually update Cloud SQL database.
- Loading branch information
1 parent
a7b826b
commit d24bd90
Showing
6 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.env | ||
pyvenv.cfg | ||
Include | ||
Lib | ||
Scripts |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
course_name,facilitator,onlinecourse_date_completed,link_to_certificate | ||
Machine Learning,Andrew Ng,2020-09-01,https://www.coursera.org/account/accomplishments/certificate/D98R6TFBN3JP | ||
Project SPARTA: Data Visualization Fundamentals,Department of Science and Technology,2020-07-23,https://coursebank.ph/certificates/479392b2cd21442a8f79de78bbfc6090 | ||
Project SPARTA: Dashboard and Drilldown Analytics,Department of Science and Technology,2020-06-14,https://coursebank.ph/certificates/099dfbb5ae434ca1af7688c22647ddf3 | ||
Project SPARTA: Essential Excel Skills for Data Preparation and Analysis,Department of Science and Technology,2020-04-15,https://coursebank.ph/certificates/3d3c3b1f129e484e8cebc670ebc32371 | ||
Project SPARTA: Getting Grounded on Analytics,Department of Science and Technology,2020-04-03,https://coursebank.ph/certificates/2dafee277c8c45b29932422f77db1213 | ||
Project SPARTA: Data Management Fundamentals,Department of Science and Technology,, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
webinar_name,organizer,webinar_date,html_desc | ||
LinkedIn Metadata Day 2020,LinkedIn,15/12/2020,"Zoom webinar bringing together data engineers from large tech companies like Google, LinkedIn, AirBnb, and Paypal to discuss latest developments in the field of data governance; specifically with regards to management of metadata. <a href=""https://metadataday2020.splashthat.com/""> Event page.</a>" | ||
"Drawing Distinctions: An Introduction to Financing Companies, Lending Companies, Foundations and Microfinance NGOs",Securities and Exchange Commission,28/10/2020," <a href=""https://drive.google.com/file/d/1d_fOAd87YpHKUJD6NOsqO2MYuEM9MewI/view""> Link to certificate.</a>" | ||
BASIQS: Business Model Canvas for Beginners,QBO Philippines,22/10/2020, | ||
Wildcard QLITAN: Journey of INQBATION Graduates,QBO Philippines,29/09/2020, | ||
WORQSHOP: Data Analytics with MoEngage,QBO Philippines,09/09/2020, | ||
Distinguished Speaker Series Webinar: Understanding Public Finance and Taxation in a Fiat Currency System,Asian Development Bank,01/09/2020,"A one-hour webinar featuring Khalid Saeed of Worcester Polytechnic Institute who discussed the relevance of modern money theory for contemporary public finance. <a href=""""> Event page.</a>" | ||
Claim it right: Tax deductions explained,PWC Isla Lipana & Co.,28/08/2020,"A two-hour session discussing tax-deductible items along with codal references and court rulings. <a href=""""> </a>" | ||
WORQSHOP: Growth Hacking Your Way to Success,QBO Philippines,14/08/2020, | ||
SEC: Mandate and Functions and The Revised Corporation Code: Salient Provisions,Securities and Exchange Commission,12/08/2020," <a href=""https://drive.google.com/file/d/18BJfZaTfk9r5LJA1KlLYHDHTsLfLyW73/view""> Link to certificate.</a>" | ||
Sealed and Secured: The Low Down on Data Privacy and Cybersecurity,UnionBank of the Philippines,06/08/2020," <a href=""https://apptitude.xyz/dashboard/student/certificate/0x3e770C29E05038087B2B40f219E09b687d7972fA/""> Link to certificate.</a>" | ||
Taking The Robot Out of Human,KPMG R.G Manabat & Co.,14/07/2020,"An overview on Robotic Process Automation (RPA): what it is, how industries use it to achieve strategic goals, and how KPMG can help in operationalizing RPA. (1 hr) <a href=""https://drive.google.com/file/d/1TNbSUTb30sNbBijtokUKsKKNMAuXurKO/view""> Link to certificate.</a>" | ||
Data Science and AI Ethics,UnionBank of the Philippines,13/07/2020," <a href=""https://apptitude.xyz/dashboard/student/certificate/0xb27b8ffa9b8B00975DE2Cd5F8Ef7D91Ac3cd17F6/""> Link to certificate.</a>" | ||
BIR Goes Digital: How to File and Pay Your Taxes Online for Corporate/Non-Individual Taxpayers,Bureau of Internal Revenue,08/06/2020," <a href=""https://drive.google.com/file/d/1PeanQY3qIND6mY32bfp9Lhd5W6G_JBpf/view""> Link to certificate.</a>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["sdl_onlinecourse", "sdl_webinars"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import psycopg2 | ||
from sqlalchemy import create_engine | ||
from dotenv import load_dotenv | ||
import os | ||
import pandas as pd | ||
import json | ||
|
||
print("\nUpdating database... Please make sure that Cloud SQL Proxy is running.\n\n") | ||
|
||
# Load environment variables | ||
load_dotenv() | ||
|
||
DB_USER = os.getenv('DB_USER') | ||
TAIL = os.getenv('TAIL') | ||
DB_NAME = os.getenv('DB_NAME') | ||
PROJECT = os.getenv('DJANGO_PROJECT_NAME') | ||
HOST = "127.0.0.1" | ||
|
||
# Create sqlalchemy engine. | ||
# To be passed to pandas DataFrame.to_sql() as arg | ||
my_engine = str().join( | ||
[ | ||
"postgresql+", | ||
":".join(["psycopg2", f"//" + DB_USER, TAIL]), | ||
"".join(["@", HOST, f"/", DB_NAME]) | ||
] | ||
) | ||
|
||
engine = create_engine(my_engine) | ||
CLOUD_SQL = engine.connect() | ||
|
||
# Connection details for psycopg2 | ||
PSQL_CONNECTION_DETAILS = str(" ").join( | ||
[ | ||
"dbname=" + DB_NAME, | ||
"user=" + DB_USER, | ||
"password=" + TAIL | ||
] | ||
) | ||
|
||
# Table names in the database | ||
file = open("table_names.json", "r") | ||
with file: | ||
TABLE_NAMES = json.loads((file.read())) | ||
file.close() | ||
|
||
# Create Postgresql connection and cursor | ||
conn = psycopg2.connect(PSQL_CONNECTION_DETAILS) | ||
cur = conn.cursor() | ||
|
||
#Update table | ||
|
||
def df_convert_iloc2_as_date(df): | ||
date_series = pd.to_datetime(df.iloc[:,2]) | ||
df.iloc[:,2] = date_series | ||
return df | ||
|
||
for table in TABLE_NAMES: | ||
model = "_".join([PROJECT, table]) | ||
print(f"Updating {model}...\n\n") | ||
|
||
add_table = pd.read_csv(table + ".csv") | ||
add_table = df_convert_iloc2_as_date(add_table) | ||
|
||
try: | ||
add_table.to_sql(model, CLOUD_SQL, | ||
if_exists='append', index=False) | ||
|
||
print(f"Table {model} has been updated!!!\n\n") | ||
except Exception as e: | ||
print(e) | ||
|
||
#Check | ||
query = f"SELECT * FROM {model};" | ||
|
||
cur.execute(query) | ||
cur.fetchall() | ||
conn.commit() | ||
|
||
print("\n\nDone.\n") | ||
|
||
|
||
print("Closing connections.") | ||
cur.close() | ||
conn.close() | ||
CLOUD_SQL.close() |