-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
47 lines (42 loc) · 1.49 KB
/
database.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
import psycopg2
from psycopg2 import sql
from dotenv import load_dotenv
import os
load_dotenv()
def initialize_database():
conn = psycopg2.connect(
host=os.getenv("POSTGRES_HOST"),
port=os.getenv("POSTGRES_PORT"),
database=os.getenv("POSTGRES_DB"),
user=os.getenv("POSTGRES_USER"),
password=os.getenv("POSTGRES_PASSWORD")
)
cursor = conn.cursor()
cursor.execute('DROP TABLE IF EXISTS detalhes')
cursor.execute('DROP TABLE IF EXISTS atividades')
cursor.execute('''CREATE TABLE IF NOT EXISTS atividades(
id SERIAL PRIMARY KEY,
activity_id BIGINT UNIQUE,
athlete_name TEXT,
activitie_name TEXT,
elapsed_time TEXT,
started_date TEXT,
started_time TEXT,
sport_type TEXT,
distance REAL
)''')
cursor.execute('''CREATE TABLE IF NOT EXISTS detalhes(
activitie_id INTEGER REFERENCES atividades(id),
lat REAL,
long REAL,
time REAL,
distance REAL,
altitude REAL,
heartrate INTEGER,
speed REAL,
smooth_grade REAL,
heart_zones INTEGER
)''')
conn.commit()
cursor.close()
conn.close()