-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongodb.py
31 lines (24 loc) · 892 Bytes
/
mongodb.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
from pymongo import MongoClient
from settings import MONGO_DB, MONGODB_LINK
mdb = MongoClient(MONGODB_LINK)[MONGO_DB]
def search_or_save_user(mdb, effective_user, message):
user = mdb.users.find_one({"user_id": effective_user.id})
if not user:
user = {
"user_id": effective_user.id,
"first_name": effective_user.first_name,
"last_name": effective_user.last_name,
"chat_id": message.chat.id
}
mdb.users.insert_one(user)
return user
def search_or_save_task(mdb, effective_user, user_data):
task = {
"user_id": effective_user.id,
'task_title': user_data['task_title'],
'deadline_date': user_data['deadline_date'],
'notification_date': user_data['notification_date'],
'task_status': user_data['task_status']
}
mdb.tasks.insert_one(task)
return task