-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestdump.py
81 lines (62 loc) · 3.56 KB
/
testdump.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from models import storage
from models.user import User
from models.recipe import Recipe
from models.roles import UserRole
from sqlalchemy.exc import IntegrityError
from api.v1.utils import extractErrorMessage
ola = {'firstname': 'Michael', 'lastname': 'Olasunkanmi', 'username': 'Ollywayne', 'email': '[email protected]',
'phone': '0885465549', 'address': 'Abuja', 'password': 'pass'}
user = User(**ola)
user.save()
mike = {'firstname': 'Michael', 'lastname': 'Adebayo', 'username': 'Mike Rock', 'email': '[email protected]',
'phone': '0885465549', 'address': 'Abuja', 'password': 'pass', "role": UserRole.admin}
user = User(**mike)
user.save()
eba = {"name": "Eba", "cuisine": "Nigeria",
"ingredients": ["2 Cups of Garri", "Boiled water"],
"instructions": ["Dance around the room for 2 mins", "Do the Hokey Pokey"], "userID": user.id,
"prep_time_minutes": 20,
"cook_time_minutes": 40,
"serving_size": 4,
"calories_per_serving": 400}
food = Recipe(**eba)
food.save()
user2 = User(**mike)
try:
user2.save()
except IntegrityError as e:
print(extractErrorMessage(e.args[0]))
from dotenv import load_dotenv
from os import getenv
load_dotenv()
USER = getenv("DB_USER")
HOST = getenv("DB_HOST")
PWD = getenv("DB_PWD")
DB = getenv("DB_NAME")
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy import create_engine
from models import storage
from models.user import User
from models.recipe import Recipe
from models.chat.chat import Chat
from models.chat.chatSession import ChatSession
engine = create_engine(
f"mysql+mysqldb://{USER}:{PWD}@{HOST}/{DB}",
pool_pre_ping=True)
sessionFactory = sessionmaker(bind=engine, expire_on_commit=False)
session = scoped_session(sessionFactory)
u = storage.getByEmail('[email protected]')
s = storage.createChatSession(u.id, "Bread and Butter")
# >>> systemMessage = "Your name is Yishu. You are a food and nutrition specialist bot. You provide expert assistance on all matters related to food, nutrition and health"
# >>> chat = Chat(userID=user.id, chat={"role": "system", "content": systemMessage})
# >>> chat
# <models.chat.chat.Chat object at 0x7fc8cd2a5c60>
# >>> chat.toDict()
# {'userID': '2de148a6-3512-4654-a062-c0baa40f19db', 'chat': {'role': 'system', 'content': 'Your name is Yishu. You are a food and nutrition specialist bot. You provide expert assistance on all matters related to food, nutrition and health'}, 'id': 'e4354ae9-351b-4816-ac75-215374d7e2fd', 'createdAt': '2023-12-04T09:13:57.738085', 'updatedAt': '2023-12-04T09:13:57.738107'}
# >>> chat.save()
# WARNING: MYSQL_OPT_RECONNECT is deprecated and will be removed in a future version.
# >>>
# curl -X POST 0:6000/api/v1/users -H 'Content-Type: application/json' -d '{"username": "Ola of da milky way", "password": "pass", "email": "[email protected]", "junk": "filter this", "firstname": "Mike", "lastname": "Rock"}'
# curl 0:6000/api/v1/login -H 'Content-Type: application/json' -d '{"email": "[email protected]", "password": "pass"}'
# curl "0:6000/api/v1/recipes?filter_by=cuisine+Nigerian,Ghanaian:serving+6:mike+wonderful&page=5&keyword=Jollof&detailed=true"
# curl -XPOST 0:6000/api/v1/recipes -H 'Content-Type: application/json' -H 'auth-token: 0768d7a0-1c77-4560-a501-b7da15345692' -d '{"name": "Eba", "cuisine": "Nigeria", "ingredients": ["2 Cups of Garri", "Boiled water"], "instructions": ["Dance around the room for 2 mins", "Do the Hokey Pokey"], "userID": "8bdfa62f-b226-4d6c-bd73-16c02c370a4d", "prep_time_minutes": 20, "cook_time_minutes": 40, "serving_size": 4, "calories_per_serving": 400}'