-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate_venues.py
More file actions
114 lines (105 loc) · 3.39 KB
/
Copy pathpopulate_venues.py
File metadata and controls
114 lines (105 loc) · 3.39 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from database import engine, SessionLocal, Base, Venue, migrate_database
import re
# 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"
]
# Sample metadata for demo venue pages
VENUE_METADATA = {
"Marble Bar": {
"address": "1501 Holden Street, Detroit, MI 48208",
"description": (
"Located on the lower level of the historic Detroit Masonic Temple, "
"Marble Bar is a 500-capacity live music venue.\n\n"
"Marble floors, a large wooden dance floor, and a vintage 40-foot bar "
"create a classic Detroit nightlife atmosphere."
),
"phone": "313-338-3674",
"website": "https://facebook.com/marblebardetroit/",
},
"Menjo's": {
"address": "950 W McNichols Rd, Detroit, MI 48203",
"phone": "313-832-8590",
},
"Society Detroit": {
"address": "1434 Griswold St, Detroit, MI 48226",
"website": "https://societydetroit.com",
},
}
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:
metadata = VENUE_METADATA.get(venue_name, {})
existing_venue = session.query(Venue).filter_by(name=venue_name).first()
if not existing_venue:
venue = Venue(
name=venue_name,
address=metadata.get('address'),
description=metadata.get('description'),
phone=metadata.get('phone'),
website=metadata.get('website'),
)
session.add(venue)
print(f"Added venue: {venue_name}")
elif metadata:
for field in ('address', 'description', 'phone', 'website'):
if metadata.get(field) and not getattr(existing_venue, field):
setattr(existing_venue, field, metadata[field])
print(f"Updated venue metadata: {venue_name}")
# Commit the changes
session.commit()
print("All venues have been added successfully!")
except Exception as e:
print(f"An error occurred: {e}")
session.rollback()
finally:
session.close()
if __name__ == "__main__":
populate_venues()