-
Notifications
You must be signed in to change notification settings - Fork 4
/
update_prices_table.py
76 lines (47 loc) · 2.1 KB
/
update_prices_table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os
import pandas as pd
import psycopg2
from dotenv import load_dotenv, find_dotenv
from scipy import stats
from sklearn.linear_model import LinearRegression
from v2_dictionaries_and_lists import *
from v2_functions_and_classes import product_ws_clean_and_classify, product_rt_clean_and_classify
load_dotenv()
# First I will work on wholesale prices only.
def update_prices_table():
# Stablishes connection with our db.
connection = psycopg2.connect(user=os.environ.get('aws_db_user'),
password=os.environ.get('aws_db_password'),
host=os.environ.get('aws_db_host'),
port=os.environ.get('aws_db_port'),
database=os.environ.get('aws_db_name'))
# Create the cursor.
cursor = connection.cursor()
# What markets are vialable?
cursor.execute('''
SELECT DISTINCT product_name, market_id, source_id, currency_code
FROM wholesale_bands
''')
wholesale_markets = cursor.fetchall()
cursor.execute('''
SELECT DISTINCT product_name, market_id, source_id, currency_code
FROM retail_bands
''')
retail_markets = cursor.fetchall()
cursor.close()
connection.close()
for i in range(len(wholesale_markets)):
product_name = wholesale_markets[i][0]
market_id = wholesale_markets[i][1]
source_id = wholesale_markets[i][2]
currency_code = wholesale_markets[i][3]
product_ws_clean_and_classify(product_name, market_id, source_id, currency_code)
print('Retail markets:')
for i in range(len(retail_markets)):
product_name = retail_markets[i][0]
market_id = retail_markets[i][1]
source_id = retail_markets[i][2]
currency_code = retail_markets[i][3]
product_rt_clean_and_classify(product_name, market_id, source_id, currency_code)
if __name__ == "__main__":
update_prices_table()