-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_id.py
More file actions
29 lines (24 loc) · 779 Bytes
/
get_id.py
File metadata and controls
29 lines (24 loc) · 779 Bytes
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
import sys
import os
from dotenv import load_dotenv
# Add project root to path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# Load env
env_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'backend', '.env')
load_dotenv(env_path)
from backend.app.database import SessionLocal
from backend.app.models import Prompt
def get_prompt_id(title: str):
db = SessionLocal()
try:
prompt = db.query(Prompt).filter(Prompt.title == title).first()
if prompt:
print(f"Title: {title}, ID: {prompt.id}")
else:
print(f"Prompt '{title}' not found.")
except Exception as e:
print(f"Error: {e}")
finally:
db.close()
if __name__ == "__main__":
get_prompt_id("互联网黑话专家")