From 81dba3555b85a21582e263ef5fa72db5ff361e3d Mon Sep 17 00:00:00 2001 From: Bashar Khatib <31943899+basharkhatib@users.noreply.github.com> Date: Fri, 23 Jul 2021 15:31:02 -0700 Subject: [PATCH 1/2] Update openexchange_data_pull.py --- openexchange_data_pull.py | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/openexchange_data_pull.py b/openexchange_data_pull.py index 5dc8282..9e89b59 100644 --- a/openexchange_data_pull.py +++ b/openexchange_data_pull.py @@ -13,26 +13,13 @@ """ api_key='b0f11c5769c54c23b381f0ad0d19c619' -day_list = "" +current_date = datetime.today().strftime('%Y-%m-%d') -date_ = datetime.today().strftime('%Y-%m-%d') -day_list += date_ -# print(day_list) - -# url = f'https://openexchangerates.org/api/historical/%7Bdate_%7D.json' - -url = f'https://openexchangerates.org/api/historical/%7Bday_list%7D.json' +url = f'https://openexchangerates.org/api/historical/%7Bcurrent_date%7D.json' response = requests.get(f'{url}?app_id={api_key}') +revenue_rates = response.json()["rates"] -exchange_rate = response.json()["rates"] -my_json = json.dumps(exchange_rate) - - -# ////////////////////////////////////////// -# /////////////////DATABASE///////////////// -# ////////////////////////////////////////// load_dotenv() - DB_HOST = os.getenv('DB_HOST') DB_NAME = os.getenv('DB_NAME') DB_USER = os.getenv('DB_USER') @@ -44,23 +31,9 @@ # Execute statements cur = conn.cursor() -# Create table, add to it two coloms, date and revenue_rates_usd -# cur.execute("CREATE TABLE usd_rates (id SERIAL PRIMARY KEY, date DATE , revenue_rates_usd JSONB NOT NULL );") - # Inserting new data to date and revenue_rates_usd -cur.execute("INSERT INTO usd_rates (date, revenue_rates_usd) VALUES(%s, %s)", (day_list, my_json)) - -# Shows everything in usd_rates table -# all_data = pd.read_sql("SELECT * FROM usd_rates;", conn) - -# Read db table, converting from USD to -all_data = pd.read_sql("SELECT date as date, revenue_rates_usd ->> 'SAR' AS SAR FROM usd_rates;", conn) - -print(all_data) +cur.execute("INSERT INTO usd_rates (date, revenue_rates_usd) VALUES(%s, %s)", (current_date, json.dumps(revenue_rates))) conn.commit() - cur.close() -# Closing conn.close() - From d60e4a4dd5553eca5084c15ec628f1ee07cc2ddf Mon Sep 17 00:00:00 2001 From: Bashar Khatib <31943899+basharkhatib@users.noreply.github.com> Date: Fri, 23 Jul 2021 15:38:43 -0700 Subject: [PATCH 2/2] Create report.py --- report.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 report.py diff --git a/report.py b/report.py new file mode 100644 index 0000000..c28b09f --- /dev/null +++ b/report.py @@ -0,0 +1,23 @@ +import requests +import numpy as np +import matplotlib.pyplot as plt +import pandas as pd +from datetime import date, timedelta + +import psycopg2 +import os + +from dotenv import load_dotenv + +""" +In this script you can choose start and end date, and it will show you the transfer from USD to SAR for each day. +And if you want to check for another currency just change the desired_currency to the symbol of the currency you would like check. +Remember it converts USD to the symbol you chose. +""" + +start_date = sys.argv[0] +end_date = sys.argv[1] + +# Select all records from usd_rates from start_date to end_date +# Get data +# Draw report