-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
54 lines (42 loc) · 1.24 KB
/
main.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
# -*- coding: utf-8 -*-
"""
Inserting data to postgres
"""
from src.manage_db import ManageDB
if __name__ == '__main__':
# Database params
# TODO: this info should be retrieved from env vars or a file that is not
# commited to git
dbname = 'data'
host = 'localhost'
port = 5431
user = 'postgres'
password = 'postgres'
# Connect to database
postgres = ManageDB(
dbname=dbname, host=host, port=port, user=user, password=password
)
postgres.connect()
# Create new table
table = 'data'
columns = {
'id': 'text PRIMARY KEY',
't': 'text',
'n': 'text',
'm': 'text',
'stage': 'text',
'date_of_diagnosis': 'text',
'date_of_fu': 'text',
'vital_status': 'text'
}
postgres.create_table(table=table, columns=columns)
# Prepare data
file_path = 'data/sample_data.csv'
df = postgres.prepare_data(file_path=file_path, columns=columns.keys())
# Insert data to table
postgres.insert_data(table=table, columns=columns.keys(), df=df)
print('All worked out')
# Display table
postgres.show_table(table=table)
# Close database
postgres.close()