This repository was archived by the owner on Jul 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeck_stats.py
More file actions
executable file
·82 lines (63 loc) · 2.14 KB
/
deck_stats.py
File metadata and controls
executable file
·82 lines (63 loc) · 2.14 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
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
from bs4 import BeautifulSoup
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("hclass")
parser.add_argument("file")
args = parser.parse_args()
cards_collection = []
cards_deck = []
class_player = args.hclass
final_deck = {}
def get_deck(file_name):
with open(file_name) as f:
file_lines = f.readlines()
file_lines = map(lambda s: s.strip(), file_lines)
return file_lines
def get_collection():
with open("collection.html") as f:
collection_raw = f.read()
f.close()
return collection_raw
def parse_collection():
collection_raw_data = get_collection()
collection_data = BeautifulSoup(collection_raw_data, 'html.parser')
collection_items = collection_data.findAll("div", {"class": "owns-card"})
for item in collection_items:
if (item['data-card-class'] == "NONE") or (item['data-card-class'] == class_player):
card_collection_name = item['data-card-name']
card_collection_count = int(item.findAll("span")[-1]['data-card-count'])
if card_collection_count == 2:
cards_collection.append(card_collection_name)
cards_collection.append(card_collection_name)
def parse_deck():
deck = get_deck(args.file)
for item in deck:
if (item[0:1] == "#") or (item == ""):
break
elif item[0:1] == "2":
cards_deck.append(item[2:])
cards_deck.append(item[2:])
def compare_decks():
for item in cards_deck:
if item in cards_collection:
if (item in final_deck.keys()) and (final_deck[item] == "1"):
final_deck[item] = "2"
cards_collection.remove(item)
else:
final_deck[item] = "1"
cards_collection.remove(item)
elif item in final_deck.keys():
final_deck[item] = "="
else:
final_deck[item] = "-"
def print_deck():
for card, count in final_deck.iteritems():
print str(count) + " " + card
def main():
parse_collection()
parse_deck()
compare_decks()
print_deck()
if __name__ == '__main__':
main()