-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate_venues.py
More file actions
84 lines (75 loc) · 2.11 KB
/
populate_venues.py
File metadata and controls
84 lines (75 loc) · 2.11 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from database import engine, SessionLocal, Base, Venue, migrate_database
import re
from fts import setup_fts_triggers
# List of venues extracted from the provided text
venues = [
"Collected Detroit",
"TV Lounge",
"Hart Plaza",
"Gregory Marina",
"Leland City Club",
"Marble Bar",
"McShane's Pub",
"Foxglove",
"SPKR BOX",
"Batch Brewing Company",
"Level Two Bar",
"Moondog Café",
"Society Detroit",
"Two James",
"The Diamond Queen River Boat",
"Common Pub",
"MotorCity Wine",
"225 Speakeasy",
"Spot Lite",
"UFO Bar",
"Johnny Noodle King",
"The Shadow Gallery",
"Mudgie's",
"Third Street Bar",
"Corktown Tavern",
"The Old Miami",
"Temple Bar",
"Menjo's",
"Red Door Digital",
"Tangent Gallery",
"Bert's Warehouse Theatre",
"Lincoln Factory",
"Magic Stick",
"7824 Mount Elliot Street",
"The Russell Industrial Center",
"Trumbullplex",
"Well Done Goods",
"Good Life"
]
def populate_venues():
# Create tables first, before any model relationships are accessed
print("Creating database tables...")
Base.metadata.create_all(engine)
# Run migration to ensure categories are set up
print("Running database migration...")
migrate_database()
# Create a session
session = SessionLocal()
try:
# Add each venue
print("Setting up venues...")
for venue_name in venues:
# Check if venue already exists
existing_venue = session.query(Venue).filter_by(name=venue_name).first()
if not existing_venue:
venue = Venue(name=venue_name)
session.add(venue)
print(f"Added venue: {venue_name}")
# Commit the changes
session.commit()
print("All venues have been added successfully!")
# Set up FTS triggers
setup_fts_triggers()
except Exception as e:
print(f"An error occurred: {e}")
session.rollback()
finally:
session.close()
if __name__ == "__main__":
populate_venues()