Skip to content

Commit 3dabdc4

Browse files
committed
cleaning up script
1 parent 2d83c54 commit 3dabdc4

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

helpers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ def listToStr(list):
2727
2828
'''
2929
output_string = ""
30-
for element in list:
31-
output_string += element + " / "
30+
for i in range(0, len(list)):
31+
if i == 0:
32+
output_string += list[i]
33+
else:
34+
output_string += "/" + list[i]
3235

3336
return output_string
3437

@@ -57,7 +60,7 @@ def outputCSV(filename, card_list, delimiter):
5760
for card in card_list:
5861
f.write(f"{card.card_passcode}{delimiter}{card.name}{delimiter}"
5962
f"{card.card_status}{delimiter}{card.attribute}{delimiter}"
60-
f"{card.type}{delimiter}{card.link}{delimiter}{card.link_arrows}{delimiter}"
63+
f"{card.type}{delimiter}{card.link}{delimiter}{listToStr(card.link_arrows)}{delimiter}"
6164
f"{card.rank}{delimiter}{card.pend_scale}{delimiter}"
6265
f"{card.level}{delimiter}{card.attack}{delimiter}{card.defense}"
6366
f"{delimiter}{card.spell_attribute}{delimiter}{card.summoning_condition}{delimiter}{card.pend_effect}"

main.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@
137137
tic = time.perf_counter()
138138
if re.search('Passcode', ind_card_info.text):
139139
lists = ind_card_info.find_all("td", class_="cardtablerowdata")
140-
passcode = lists[0]
141-
tmp_card.card_passcode = helpers.cleanStr(passcode.text, [("\n", ""), ("\t", ""), ("\r", "")])
140+
if len(lists) != 0:
141+
passcode = lists[0]
142+
tmp_card.card_passcode = helpers.cleanStr(passcode.text, [("\n", ""), ("\t", ""), ("\r", "")])
142143

143144
if re.search('Link Arrows', ind_card_info.text):
144145
lists = ind_card_info.find_all("td", class_="cardtablerowdata")
@@ -152,17 +153,21 @@
152153

153154
if re.search('Card effect types', ind_card_info.text):
154155
lists = ind_card_info.find_all("td", class_="cardtablerowdata")
155-
card_effect_types = lists[0]
156-
effect_types = []
157-
for effect_type in card_effect_types:
158-
if not isinstance(effect_type, NavigableString) and effect_type.text != '\n':
159-
effect_types.append(helpers.cleanStr(effect_type.text, [("\n", "")]))
160-
tmp_card.effect_types = effect_types
156+
if len(lists) != 0:
157+
card_effect_types = lists[0]
158+
effect_types = []
159+
for effect_type in card_effect_types:
160+
if not isinstance(effect_type, NavigableString) and effect_type.text != '\n':
161+
for effect in effect_type:
162+
if effect.text not in effect_types and not re.search('\n', effect.text):
163+
effect_types.append(effect.text)
164+
tmp_card.effect_types = effect_types
161165

162166
if re.search('Statuses', ind_card_info.text):
163167
lists = ind_card_info.find_all("td", class_="cardtablerowdata")
164-
card_status = lists[0]
165-
tmp_card.card_status = helpers.cleanStr(card_status.text, [(" ", "")])
168+
if len(lists) != 0:
169+
card_status = lists[0]
170+
tmp_card.card_status = helpers.cleanStr(card_status.text, [(" ", "")])
166171

167172
if re.search('Card search categories', ind_card_info.text):
168173
lists = ind_card_info.find_all("div", class_="hlist")
@@ -192,7 +197,7 @@
192197
tmp_card.card_actions = card_actions
193198

194199
toc = time.perf_counter()
195-
bar.text = f'-> Processing pack: {pack_name}, {tmp_card.name} processed in {toc - tic:0.4f} seconds'
200+
bar.text = f'-> Processing pack: {pack_name}, {tmp_card.name} processed in {toc - tic:0.4f} seconds'
196201

197202

198203
# Store the card structure into the list of cards

0 commit comments

Comments
 (0)