-
Notifications
You must be signed in to change notification settings - Fork 0
/
cuberead.py
83 lines (68 loc) · 2.29 KB
/
cuberead.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
from HTMLParser import HTMLParser
import urllib
import re
import sys
import sqlite3
class card(object):
def __init__(self, attr):
lines = attr.split(u'\\n')
title_re = re.compile(r"([^\(]+)\(([^\)]+)\)(.*)", flags=re.UNICODE)
match = title_re.match(lines[0])
self.title = match.group(1).strip()
self.cost = match.group(2).strip()
self.pt = match.group(3).strip()
self.types = lines[1].strip()
self.body = "".join(lines[2:-3])
self.sets = lines[-3].strip()
global cards
cards = {}
class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
if tag == 'img':
for k,v in attrs:
if k == 'title':
title = v
break
the_card = card(title)
cards[the_card.title] = the_card
def handle_endtag(self, tag):
pass
def handle_data(self, data):
pass
vintage = "mtgo_vintage_cube_winter_20162017.txt"
vintage2 = "mtgo_vintage_cube_winter_201718.txt"
if __name__ == '__main__':
# instantiate the parser and fed it some HTML
parser = MyHTMLParser()
fi = ["proxies.htm",
"proxies2.htm",
"soi.htm",
"enm-consp2-kld.htm",
"commander.htm"]
for f in fi:
connection = urllib.urlopen(f)
encoding = connection.headers.getparam('charset')
page = connection.read().decode('utf-8')
parser.feed(page)
with open(vintage, "r") as f:
vint = set(unicode(li.strip()) for li in f.readlines())
with open(vintage2, "r") as f:
vint2 = set(unicode(li.strip()) for li in f.readlines())
cube = set(cards.iterkeys())
# print vint
# print cube
diff = vint2 - vint
for v in sorted(diff):
print "+", v
diff = vint - vint2
for v in sorted(diff):
print "-", v
# conn =sqlite3.connect("cube.db")
# c = conn.cursor()
# c.execute('''CREATE TABLE cards
# (date_added text, name text, mana text, power_toughness text, types text, body text, sets text)''')
# for k,v in cards.iteritems():
# t = ('2015-11-30', v.title, v.cost, v.pt, v.types, v.body, v.sets)
# c.execute("INSERT INTO cards VALUES (?, ?, ?, ?, ?, ?, ?)", t)
# conn.commit()
# conn.close()