-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalytics.py
37 lines (27 loc) · 1020 Bytes
/
analytics.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
import configparser
import psycopg2
from sql_queries import analytic_queries
def get_results(cur, conn):
"""
This function retrieves results for the analytic queries.
Query1: count and return all records in each table into on single table
Query2: retrieve record for songs and artist with the highest streaming duration
Query3: retrieve record for song and artist with the lowest straming duration
"""
for query in analytic_queries:
cur.execute(query)
results = cur.fetchall()
for row in results:
print(row)
def main():
config = configparser.ConfigParser()
config.read('dwh.cfg')
conn = psycopg2.connect("host={} dbname={} user={} password={} port={}".format(*config['CLUSTER'].values()))
print('1.connection established..')
cur = conn.cursor()
print('2.cursor created successfully')
get_results(cur, conn)
conn.close()
print('3. close connection')
if __name__ == "__main__":
main()