-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoolManager.py
58 lines (48 loc) · 2.05 KB
/
PoolManager.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
from pymongo import MongoClient
from bson import ObjectId
from DayManager import DayManager
from support_object import time_pointers, day_transformers
class PoolManager():
def __init__(self):
client = MongoClient()
self.daymanager = DayManager()
self.database = client['pool_group']
def init_pool(self):
return {
"title": None,
"closed": False,
"time_value": {
"close_datetime": self.daymanager.get_close_pool( self.daymanager.add_day() ),
"pool_day": self.daymanager.get_today(),
"time_pointers": "oggi"
}
}
def get_pool(self, _id):
return self.database.pool.find_one({"_id": ObjectId(_id)})
def close_pool(self, _id):
self.database.pool.update_one({"_id": _id}, {"$set": {'closed': True}} )
def pools_same_day(self, chat_id, time_value):
return self.database.pool.find_one({
"chat_id": chat_id,
"closed": False,
"time_value.pool_day": time_value['pool_day'],
"time_value.time_pointers": time_value['time_pointers']
}) is None
def get_opened_pools(self, chat_id, owner=None):
if owner != None:
opened_pool = self.database.pool.find_one({"chat_id": chat_id, "closed": False, "owner": owner})
else:
opened_pool = self.database.pool.find({"chat_id": chat_id, "closed": False})
return list(opened_pool)
def get_pools_toclose(self, time_pointer):
pools = self.database.pool.find({
"time_value.time_pointers": time_pointer,
"time_value.pool_day": self.daymanager.get_today(),
"time_value.close_datetime": self.daymanager.get_close_pool(hour=time_pointers[time_pointer])
})
return list(pools)
def new_pool(self, pooldict):
self.database.pool.insert_one( pooldict )
return pooldict['_id']
def update_pool(self, _id, pooldict):
self.database.pool.update_one({"_id": _id}, {"$set": pooldict })