python-gotosocial-notif/models.py

50 lines
1.1 KiB
Python
Raw Normal View History

2024-09-29 12:14:20 +02:00
# %%
# ZED Python REPL
import os
2024-10-01 06:32:29 +02:00
from sqlalchemy import Column, Date, Integer, String, create_engine
2024-09-29 12:14:20 +02:00
from sqlalchemy.ext.declarative import declarative_base
2024-10-01 06:32:29 +02:00
from sqlalchemy.orm import sessionmaker
2024-09-29 12:14:20 +02:00
cwd = os.getcwd()
db_dir = f"{cwd}/db"
2024-11-20 14:30:18 +01:00
print(db_dir)
if not os.path.exists(db_dir):
print("Folder db tidak ditemukan, membuat folder db")
os.makedirs(db_dir)
else:
print("Tidak bisa membuat folder db, silakan membuat secara manual folder db")
2024-09-29 12:14:20 +02:00
# Engine
engine = create_engine(f"sqlite:///{db_dir}/gotodon.db")
2024-09-29 12:14:20 +02:00
# Base
Base = declarative_base()
2024-10-01 06:32:29 +02:00
2024-09-29 12:14:20 +02:00
# Models
class Notifikasi(Base):
2024-10-01 06:32:29 +02:00
__tablename__ = "notifikasi"
2024-09-29 12:14:20 +02:00
id = Column(Integer, primary_key=True)
inreplyto = Column(String)
post_id = Column(String, unique=True)
created_at = Column(Date)
handler = Column(String)
display_name = Column(String)
type = Column(String)
status = Column(String)
url = Column(String)
remark = Column(String)
def __repr__(self) -> str:
return f"<{self.id} : {self.handler} >"
2024-10-01 06:32:29 +02:00
2024-09-29 12:14:20 +02:00
# Buat tabel
Base.metadata.create_all(engine)
# Session
Session = sessionmaker(bind=engine)