forked from JDaniloC/BetBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
98 lines (88 loc) · 2.98 KB
/
database.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from pymongo.database import Database as DatabaseType
from pymongo.collection import Collection
from pymongo import MongoClient
from env import autenticacao # autenticacao = "mongodb+srv://..."
import time, hashlib
users_schema = {
"username": "",
"password": "",
"license": {
"from_date": 0,
"to_date": 0,
"original_value": -1,
"actual_value": 0.0
},
"settings": {
"stopWin": 0,
"stopLoss": 0,
"maxBet": 1
},
"filters": {
"golsFilter": [False, [0, 0]],
"maxTime": 90,
"minOdd": 0.0
},
"search": []
}
def criptografa(password:str):
return hashlib.md5(password.encode("utf-8")).hexdigest()
class Mongo:
def __init__(self, database: DatabaseType,
users_collection: Collection):
self.database = database
self.Users_collection = users_collection
def cadastrar(self, username:str, password:str):
'''
Adiciona um novo usuário
'''
user = users_schema
user['username'] = username
user['password'] = criptografa(password)
user['license']['from_date'] = time.time()
user['license']['to_date'] = time.time() + 2592000
user["_id"] = time.time()
self.Users_collection.insert_one(user)
def renovar_licenca(self, username:str):
'''
Aumenta a licença de determinado usuário
'''
data = time.time() + 2592000
self.Users_collection.find_one_and_update(
{'username':username}, {'$set': {
'license.to_date': data,
}})
def modifica_usuario(self, info: dict, username:str):
'''
Modifica as informações do usuário de determinado usuário
'''
user = self.remover_usuario(username)
info['license']['from_date'] = user['license']['from_date']
info['license']['to_date'] = user['license']['to_date']
user.update(info)
self.Users_collection.insert_one(user)
def remover_usuario(self, username:str):
'''
Remove o usuário de determinado username
Devolve o usuário removido
'''
return self.Users_collection.find_one_and_delete(
{'username': username})
def login(self, username:str, password:str) -> bool:
'''
Devolve as informações do usuário a partir do nome do usuário
'''
user = self.Users_collection.find_one({'username': username})
if user and user['password'] == criptografa(password):
return user
return False
def modificar_banco_users(self, opcao:str):
if opcao == "clear":
self.Users_collection.delete_many({})
elif opcao == "time":
data = time.time() + 2592000
self.Users_collection.update_many(
{}, {'$set': {'license.to_date': data}})
client = MongoClient(autenticacao)
Database = client.betbot
Users_collection = Database.users
MongoDB = Mongo(Database, Users_collection)