bbbb/bbbb_database_tools.py

32 lines
1.2 KiB
Python

from BBBB_Models import Comment, OpenAIToken, User, Base
from bbbb import get_real_filename
from sqlalchemy.orm import Session
from sqlalchemy import create_engine
import sys
if __name__ == "__main__":
db_filename = "bbbb_database.db"
engine = create_engine(f"sqlite:///{get_real_filename(db_filename)}")
Base.metadata.create_all(engine)
with Session(engine) as session:
command = sys.argv[1]
if (command == "add_token"):
token = sys.argv[2]
OpenAIToken.add_token(token, session)
print("Added the token!")
elif (command == "reset_users"):
User.reset_all_comments(session)
print("Reset the users!")
elif (command == "test"):
print(OpenAIToken.call_open_ai("THEOREM: Let c be the hypotenuse of a right triangle and let a, b be the other two sides; then a^2 + b^2 = c^2\n\nLet's think step by step.", session))
elif (command == "has_replied"):
comment_id = sys.argv[2]
print(Comment.get_comment(comment_id, session))
print(Comment.has_replied_to_comment(comment_id))
else:
print(f"command {command} not understood.")
session.commit()