-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
139 lines (121 loc) · 4.74 KB
/
utils.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from tokenize import String
import json
import os
import re
from copy import deepcopy
import requests
from bs4 import BeautifulSoup #https://www.crummy.com/software/BeautifulSoup/bs4/doc/#navigating-the-tree
import html
import random
def printJson(j):
print(json.dumps(j, indent=4))
def printBanner(websiteName): # Implemented => (moxfield, mtggoldfish). Doom font
if websiteName == "moxfield":
print(
r"""
___ ___ __ _ _ _
| \/ | / _(_) | | | |
| . . | _____ _| |_ _ ___| | __| |
| |\/| |/ _ \ \/ / _| |/ _ \ |/ _` |
| | | | (_) > <| | | | __/ | (_| |
\_| |_/\___/_/\_\_| |_|\___|_|\__,_|
""")
elif websiteName == "mtggoldfish":
print(
r"""
___ ____ _____ _ _ __ _ _
| \/ | | | __ \ | | | |/ _(_) | |
| . . | |_ __ _| | \/ ___ | | __| | |_ _ ___| |__
| |\/| | __/ _` | | __ / _ \| |/ _` | _| / __| '_ \
| | | | || (_| | |_\ \ (_) | | (_| | | | \__ \ | | |
\_| |_/\__\__, |\____/\___/|_|\__,_|_| |_|___/_| |_|
__/ |
|___/
""")
elif websiteName == "archidekt":
print(
r"""
___ _ _ _ _ _
/ _ \ | | (_) | | | | | |
/ /_\ \_ __ ___| |__ _ __| | ___| | _| |_
| _ | '__/ __| '_ \| |/ _` |/ _ \ |/ / __|
| | | | | | (__| | | | | (_| | __/ <| |_
\_| |_/_| \___|_| |_|_|\__,_|\___|_|\_\\__|
""")
elif websiteName == "tappedout":
print(
r"""
_____ _ _____ _
|_ _| | | _ | | |
| | __ _ _ __ _ __ ___ __| | | | |_ _| |_
| |/ _` | '_ \| '_ \ / _ \/ _` | | | | | | | __|
| | (_| | |_) | |_) | __/ (_| \ \_/ / |_| | |_
\_/\__,_| .__/| .__/ \___|\__,_|\___/ \__,_|\__|
| | | |
|_| |_|
""")
def logResponse(name, r): # Logs the request to a .html file for reviewing
f = open(name, "w")
text = str(r.status_code) + "\n" + \
str(r.headers) + "\n\n\n\n" + str(r.text)
text = text.replace("', '", "',\n'")
f.write(text)
f.close()
DeckListTemplate = { # Remember to deepcopy() when copying this template
"format": "", # Format
"companions": [], # List of <CardFormatTemplate>
"commanders": [], # List of <CardFormatTemplate>
"mainboard": [], # List of <CardFormatTemplate>
"sideboard": [] # List of <CardFormatTemplate>
}
CardFormatTemplate = {
"quantity": 0,
"name": "", # Lightning Bolt
"set": "", # M12
"setNr": "1", # 65
"layout": "normal" # normal (transform, adventure, split, modal_dfc) (Only split cards have names with //, Fire // Ice)
}
def convertDeckToXmage(deckList):
# If the format is EDH, make the Commander the only sideboard card
if deckList["format"] == "commander":
deckList["sideboard"] = []
for cmdr in deckList["commanders"]:
deckList["sideboard"].append(cmdr)
xDeck = "" #Add NAME tag NAME:Arcades Aggro
problematicCards = []
for card in deckList["mainboard"]:
quantity = card["quantity"]
name = card["name"]
set = card["set"]
setNr = card["setNr"]
layout = card["layout"]
if "//" in name and layout != "split": # Fix adventure cards e.g. Bonecrusher Giant // Stomp => Bonecrusher Giant
problematicCards.append(name)
name = name[:name.index("//")-1]
line = f"{quantity} [{set}:{setNr}] {name}\n"
xDeck += line
for card in deckList["sideboard"]:
quantity = card["quantity"]
name = card["name"]
set = card["set"]
setNr = card["setNr"]
layout = card["layout"]
if "//" in name and layout != "split":
problematicCards.append(name)
name = name[:name.index("//")-1]
line = f"SB: {quantity} [{set}:{setNr}] {name}\n"
xDeck += line
if len(problematicCards) != 0:
print(" [!]", len(problematicCards), "card(s) might not have been imported correctly, check your deck.")
# logging the problematic cards here
return xDeck
def writeXmageToPath(xmageFolderPath, deckName, format, deckContent):
#print(xmageFolderPath + "\\" + deckName + ".dck") #Logging
xmageFolderPath = os.path.join(xmageFolderPath, format)
if not (os.path.exists(xmageFolderPath)):
os.makedirs(xmageFolderPath)
# Remove bad characters
deckName = "".join(i for i in deckName if i not in r"\/:*?<>|")
f = open(os.path.join(xmageFolderPath, deckName) + ".dck", "w", encoding='utf-8')
f.write(deckContent)
f.close()