2024-09-29 12:14:20 +02:00
|
|
|
# %%
|
|
|
|
# ZED Python REPL
|
2024-10-03 13:37:36 +02:00
|
|
|
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
|
|
|
|
2024-10-03 13:37:36 +02:00
|
|
|
cwd = os.getcwd()
|
2024-10-03 13:49:56 +02:00
|
|
|
db_dir = f"{cwd}/db"
|
2024-11-20 14:30:18 +01:00
|
|
|
print(db_dir)
|
2024-10-03 13:49:56 +02:00
|
|
|
|
|
|
|
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-10-03 13:37:36 +02:00
|
|
|
|
2024-09-29 12:14:20 +02:00
|
|
|
# Engine
|
2024-10-03 13:49:56 +02:00
|
|
|
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)
|