-
Notifications
You must be signed in to change notification settings - Fork 0
/
databaseUtils.py
146 lines (122 loc) · 3.67 KB
/
databaseUtils.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import pymongo
from datetime import *
import time
#Remote declarations.
client = pymongo.MongoClient("mongodb://localhost:27017/")
print(client.list_database_names())
waifudb = client['waifu']
userdb = waifudb['user_data']
waifu_datadb = waifudb['waifu_data_db']
roll_statsdb = waifudb['roll_stats']
rate_limitdb = waifudb['rate_limits']
waifu_tierdb = waifudb['waifu_tier_db']
time_limit = 150
def waifu_roll_in_progress(user_id, is_in_progress):
insertion = {
"user_id" : user_id,
"is_in_progress" : is_in_progress
}
#checking if the entry for the user already exists on DB
if (len(list(roll_statsdb.find({"user_id" : user_id}))) == 0):
roll_statsdb.insert_one(insertion)
#otherwise, just finding and replacing
else:
roll_statsdb.find_one_and_replace({"user_id" : user_id}, insertion)
def is_waifu_roll_in_progress(user_id):
query = {
"user_id" : user_id
}
try:
return roll_statsdb.find_one(query)["is_in_progress"]
except:
return False
def list_hentai():
hentaidb = waifudb['hentaidigits']
for x in hentaidb.find():
print(x)
def insert_hentai(n):
insertion = {"id" : n}
hentaidb = waifudb['hentaidigits']
hentaidb.insert_one(insertion)
def claim_waifu(user_id, anilist_id):
insertion = {
"user_id" : user_id,
"anilist_id" : anilist_id
}
userdb.insert_one(insertion)
def remove_waifu(user_id, anilist_id):
removal = {
"user_id" : user_id,
"anilist_id" : anilist_id
}
userdb.find_one_and_delete(removal)
def get_waifu_list_for_user(user_id):
query = {
'user_id' : user_id
}
return list(userdb.find(query))
def insert_waifu_data_into_db(anilist_id, name, image_url, anime_name):
insertion = {
'anilist_id' : anilist_id,
'name' : name,
'anime_name' : anime_name,
'image_url' : image_url
}
if (len(list(waifu_datadb.find(insertion))) == 0):
waifu_datadb.insert_one(insertion)
def get_waifu_data_from_db(anilist_id):
query = {
'anilist_id' : anilist_id
}
return waifu_datadb.find_one(query)
def set_roll_rate_limit(user_id):
query = {
"user_id" : user_id
}
insertion = {
"user_id" : user_id,
"time_rolled_last" : datetime.now()
}
if (len(list(rate_limitdb.find(query))) == 0):
rate_limitdb.insert_one(insertion)
else:
rate_limitdb.find_one_and_replace(query, insertion)
def is_rate_limited(user_id):
query = {
"user_id" : user_id
}
try:
rate_time = rate_limitdb.find_one(query)["time_rolled_last"]
except:
return False
time_diff = int((datetime.now() - rate_time).total_seconds())
if(time_diff< time_limit):
return True
else:
return False
def get_time_left(user_id):
query = {
"user_id" : user_id
}
rate_time = rate_limitdb.find_one(query)["time_rolled_last"]
time_diff = int((datetime.now() - rate_time).total_seconds())
return str(time_limit-time_diff)
def reset_user_roll_stats():
rate_limitdb.drop()
roll_statsdb.drop()
def user_stats_from_db(user_id):
query = {
"user_id" : user_id
}
#TBD
def insert_waifu_pos_data(anilist_id, pos):
insertion = {
"anilist_id" : anilist_id,
"pos" : pos
}
waifu_tierdb.insert_one(insertion)
def get_user_stats(user_id):
query = {
"user_id" : user_id
}
user_data = {"number_of_waifus" : len(list(userdb.find(query)))}