-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.py
73 lines (63 loc) · 1.53 KB
/
db.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
import psycopg2
conn = psycopg2.connect("postgres:///beer_feed")
with conn.cursor() as cur:
cur.execute("""
CREATE TABLE IF NOT EXISTS beers (
auth_rating REAL,
beer_abv REAL,
beer_name TEXT,
beer_style TEXT,
beer_id INT PRIMARY KEY,
rating_count INT,
rating_score REAL,
last_updated TIMESTAMP
)
""")
cur.execute("""
CREATE TABLE IF NOT EXISTS breweries (
brewery_id INT PRIMARY KEY,
brewery_name TEXT,
brewery_page_url TEXT,
brewery_slug TEXT,
brewery_type TEXT
)
""")
cur.execute("""
CREATE TABLE IF NOT EXISTS venues(
venue_id INT PRIMARY KEY,
venue_name TEXT,
venue_slug TEXT,
lat REAL,
lng REAL
)
"""
)
cur.execute("""
CREATE TABLE IF NOT EXISTS checkins (
beer_id INT references beers(beer_id),
brewery_id INT references breweries(brewery_id),
checkin_comment TEXT,
checkin_id INT PRIMARY KEY,
created_at TIMESTAMP,
distance REAL,
venue_id int references venues(venue_id),
user_id int,
rating REAL,
feed TEXT references feeds(feed)
)
""")
cur.execute("""
CREATE TABLE IF NOT EXISTS tokens (
token TEXT PRIMARY KEY,
last_used TIMESTAMP NOT NULL DEFAULT NOW()
)
""")
cur.execute("""
CREATE TABLE feeds (
feed TEXT PRIMARY KEY,
name TEXT,
lat REAL,
lon REAL
);
""")
conn.commit()