-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodels.py
More file actions
50 lines (43 loc) · 1.29 KB
/
models.py
File metadata and controls
50 lines (43 loc) · 1.29 KB
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
import sqlite3
import os
# Get the absolute path of transit.db
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) # Gets the directory of the script
DB_PATH = os.path.join(BASE_DIR, '..', 'transit.db') # Moves up one level to store db in /data/
def create_tables():
"""Creates tables for storing locations in SQLite."""
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS libraries (
id INTEGER PRIMARY KEY AUTOINCREMENT,
location TEXT UNIQUE,
address TEXT,
latitude REAL,
longitude REAL
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS printers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
location TEXT UNIQUE,
description TEXT,
latitude REAL,
longitude REAL
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS restaurants (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE,
category TEXT,
address TEXT,
latitude REAL,
longitude REAL,
image_url TEXT,
web_url TEXT
)
''')
conn.commit()
conn.close()
if __name__ == "__main__":
create_tables()