-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharchideckt.py
78 lines (67 loc) · 2.98 KB
/
archideckt.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
from utils import *
class Archidekt:
archidektUrl = "https://archidekt.com"
username = ""
xmageFolderPath = ""
def __init__(self, username, xmageFolderPath):
self.username = username
self.xmageFolderPath = xmageFolderPath + "\\Archidekt"
def __getUserDecks(self):
# https://archidekt.com/search/decks?orderBy=-createdAt&owner=FastHandsTam&ownerexact=true
url = (
"https://archidekt.com/api/decks/cards/?orderBy=-createdAt&owner=" +
self.username + "&ownerexact=true&pageSize=48"
)
#print("Getting user decks at = " + url) #Logging
r = requests.get(url)
j = json.loads(r.text)
#f = open("archidektDecks.out", "w"); f.write(json.dumps(j)); f.close()
userDecks = {}
for e in j["results"]:
# {"Kalamax Control": "123567"}
userDecks[e["name"]] = str(e["id"])
# printJson(userDecks)
return userDecks
def __getDecklist(self, deckId):
# https://archidekt.com/api/decks/ ID /small/
url = f"https://archidekt.com/api/decks/{deckId}/small/"
# print(f"Grabbing decklist <{deckId}> {url}") #Logging
r = requests.get(url)
jsonGet = json.loads(r.text)
formatsDict = { # deckFormat comes in id, it has to be translated
1: "idk1",
3: "commander",
15: "pioneer",
16: "historic"
}
deckList = deepcopy(DeckListTemplate)
# Skal konverteres fra tal til string
deckList["format"] = formatsDict[jsonGet["deckFormat"]]
for card in jsonGet["cards"]:
cardFormat = deepcopy(CardFormatTemplate)
cardFormat["name"] = card["card"]["oracleCard"]["name"]
cardFormat["quantity"] = card["quantity"]
cardFormat["set"] = card["card"]["edition"]["editioncode"].upper()
cardFormat["setNr"] = "-1"
if card["categories"][0] == "Commander":
deckList["commanders"].append(cardFormat)
elif card["categories"][0] == "Companion":
deckList["companions"].append(cardFormat)
elif card["categories"][0] == "Sideboard":
deckList["sideboard"].append(cardFormat)
else:
deckList["mainboard"].append(cardFormat)
return deckList
def Download(self):
printBanner("archidekt")
print("Only public decks are searchable in Archidekt")
userDecks = self.__getUserDecks()
i, total = 1, len(userDecks)
for deckName in userDecks:
print(f"({i}/{total}) " + deckName + " " * (50 - len(deckName) -
len(str(i))) + self.archidektUrl + "/decks/" + userDecks[deckName])
i = i + 1
deckList = self.__getDecklist(userDecks[deckName])
xDeck = convertDeckToXmage(deckList)
writeXmageToPath(self.xmageFolderPath, deckName,
str(deckList["format"]), xDeck)