-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequest_manager.py
59 lines (51 loc) · 1.89 KB
/
request_manager.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
import json
import utils.file_manager as files
import utils.utils as utils
def create(ctx, loc, rqname, time):
userid = ctx.message.author.id
request = ctx.message.id
if ctx.guild is None:
guild_name = ""
channel = 1
else:
guild_name = ctx.guild.name
channel = ctx.channel.id
data = {"user": userid, "request": request, "name": rqname, "time": time, "guild": guild_name, "channel": channel, "source": request, "wait": False, "added": 0}
files.make_json(loc + str(userid) + '_' + str(request) + '.json', data) # ./id_rq.json
return data
def remove(path, request_id, arr):
timer_task = arr[utils.return2DIndex(request_id, arr)][1]
timer_task.cancel()
del arr[utils.return2DIndex(request_id, arr)]
files.delete_json(path, request_id)
def retrieve_list(userid, path):
request_list = []
request_files = files.get_json(userid, path)
for file in request_files:
with open(file, 'r') as r:
request = json.load(r)
request_list.append(request)
return request_list
def retrieve_json_id(path, userid, request_id):
request_json = files.get_json(str(userid) + "_" + str(request_id), path)[0]
with open(request_json, 'r') as r:
rq_json = json.load(r)
return rq_json
def get_index(userid, path, rq_json):
arr = retrieve_list(userid, path)
return arr.index(rq_json)
def retrieve_json(userid, path, request):
request_files = files.get_json(userid, path)
request_json = request_files[request - 1]
with open(request_json, 'r') as r:
request = json.load(r)
return request
def edit_json_val(userid, path, request_id, key, value):
rq_json = files.get_json(str(userid) + "_" + str(request_id), path)[0]
with open(rq_json, 'r+') as w:
rq = json.load(w)
rq[key] = value
w.seek(0)
json.dump(rq, w, indent=4)
w.truncate()
return rq