-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_make.py
More file actions
44 lines (34 loc) · 1.29 KB
/
db_make.py
File metadata and controls
44 lines (34 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
from sqlalchemy import create_engine, Column, Integer, String, DateTime
from sqlalchemy.orm import sessionmaker, declarative_base
import os
from dotenv import load_dotenv
from datetime import datetime
from db import Base
class UserArtistPlay(Base):
__tablename__ = "user_artist_plays"
id = Column(Integer, primary_key=True, index=True)
username = Column(String, index=True)
artist_name = Column(String, index=True)
period = Column(String) # '7day', '1month', '12month', 'overall'
playcount = Column(Integer)
timestamp = Column(DateTime, default=datetime.utcnow)
class UserTrackPlay(Base):
__tablename__ = "user_track_plays"
id = Column(Integer, primary_key=True, index=True)
username = Column(String, index=True)
artist_name = Column(String, index=True)
track_name = Column(String, index=True)
period = Column(String)
playcount = Column(Integer)
timestamp = Column(DateTime, default=datetime.utcnow)
def pre_init():
load_dotenv()
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///lastfm.db")
engine = create_engine(DATABASE_URL, echo=True)
SessionLocal = sessionmaker(bind=engine)
Base = declarative_base()
def init_db():
Base.metadata.create_all(bind=engine)
if __name__ == "__main__":
init_db()
print("✅ Database created!")