-
Notifications
You must be signed in to change notification settings - Fork 0
/
stsRuns.py
78 lines (73 loc) · 3.01 KB
/
stsRuns.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
import json
import os
import csv
# stsRuns class takes the directory of slay the spire .run files as an argument on instantiation
# ex: r"C:\Program Files (x86)\Steam\steamapps\common\SlayTheSpire\runs\IRONCLAD"
class stsRuns:
def __init__(self, dir):
self.dir = dir
self.runs = []
self.wins = []
# retrieve list of run files
runs = os.listdir(dir)
# loop through run files, find wins
for run in runs:
file = dir + "\\" + run
# open file
with open(file) as user_file:
file_contents = user_file.read()
# parse JSON into dict
parsed_json = json.loads(file_contents)
(self.runs).append(parsed_json)
# if win, add to self.wins
if (parsed_json["victory"] and parsed_json["victory"] == True):
(self.wins).append(parsed_json)
def write_to_csv(self, dataToWrite, fileName):
# open the file in the write mode
with open(fileName+'.csv', 'w+', newline='') as f:
#master headers list
csv_columns = []
print(dataToWrite)
for row in dataToWrite:
for key in row.keys():
if(key not in csv_columns):
csv_columns.append(key)
writer = csv.DictWriter(f, fieldnames=csv_columns)
writer.writeheader()
for row in (dataToWrite):
# write row to the csv file
writer.writerow(row)
# returns wins
def return_wins(self, deck=None, relics=None, allData=None):
for win in self.wins:
if (deck):
print("winning deck: ")
self.return_deck(win["master_deck"])
if (relics):
print("winning relics: ")
self.return_relics(win["relics"])
if (allData):
print(self.wins)
# return deck with card desciptions
def return_deck(self, deck):
deck_descriptions = []
with open("./cards.json", "r") as cards_list:
file_contents = cards_list.read()
master_cards = json.loads(file_contents)
for card in deck:
for k, v in master_cards.items():
if (card.__contains__(k)):
deck_descriptions.append({'name': card, 'description': v["DESCRIPTION"] })
print(deck_descriptions)
#return relics with descriptions
def return_relics(self, relics):
relics_descriptions = []
with open("./relics.json", "r") as relic_list:
file_contents = relic_list.read()
master_relics = json.loads(file_contents)
for relic in relics:
for k, v in master_relics.items():
if (relic == k):
s = " "
relics_descriptions.append({'name': k, 'description': s.join(v["DESCRIPTIONS"]) })
print(relics_descriptions)