-
Notifications
You must be signed in to change notification settings - Fork 13
/
database.py
56 lines (38 loc) · 926 Bytes
/
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
data = {}
def get_hash(player, ts):
return player + '|' + str(ts)
def get_item_hash(item):
return get_hash(item['player'], item['ts'])
def get(player, ts):
global data
return data[get_hash(player, ts)]
def put(item):
global data
data[get_item_hash(item)] = item
def delete(item):
global data
del data[get_item_hash(item)]
def find_if(if_fn):
global data
result = []
for item_hash in data:
item = data[item_hash]
if if_fn(item):
result.append(item)
return result
def query(**kwargs):
global data
result = []
for item_hash in data:
item = data[item_hash]
if matches(item, **kwargs):
result.append(item)
return result
def matches(item, **kwargs):
for key in kwargs:
if item[key] != kwargs[key]:
return False
return True
def reset():
global data
data = {}