-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathused_codes.py
More file actions
70 lines (54 loc) · 1.46 KB
/
used_codes.py
File metadata and controls
70 lines (54 loc) · 1.46 KB
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
import json
import os
def read_codes(game='Borderlands 2', platform='PC'):
'''
Returns a list of all the codes of the specified game that have already been used.
'''
if not (os.path.exists("used_codes.json")):
create_json()
codeList = []
with open('used_codes.json', 'r') as json_file:
codes = json.load(json_file)
codeList = codes[game][platform]
return codeList
def write_codes(code, game='Borderlands 2', platform='PC'):
'''
Adds a code to the json file.
'''
if not (os.path.exists("used_codes.json")):
create_json()
codes = {}
with open('used_codes.json', 'r') as json_file:
codes = json.load(json_file)
if (code not in codes[game][platform]):
codes[game][platform].append(code)
with open('used_codes.json', 'w') as json_file:
json.dump(codes, json_file)
def create_json():
'''
Creates a new JSON file with the required layout.
'''
data = {}
data['Borderlands 1'] = {
'PC': [],
'PS4': [],
'xBox': []
}
data['Borderlands 2'] = {
'PC': [],
'PS4': [],
'xBox': []
}
data['Borderlands - Pre Sequel'] = {
'PC': [],
'PS4': [],
'xBox': []
}
data['Borderlands 3'] = {
'Multi': []
}
data['VIP'] = {
'Multi': []
}
with open('used_codes.json', 'w') as outfile:
json.dump(data, outfile)