-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathareas.py
110 lines (94 loc) · 4.14 KB
/
areas.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
import re
import requests
from lxml import html
from lxml.etree import tostring
from item import *
from attribute import *
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30'}
class Monster():
def __init__(self, name, act, mlvls, tcs):
self.name = name
#self.monster_type = mtype
#self.loc = loc
self.act = act
self.mlvls = {"normal": int(mlvls[0]), "nightmare": int(mlvls[1]), "hell": int(mlvls[2])}
self.tcs = {"normal": int(tcs[0]), "nightmare": int(tcs[1]), "hell": int(tcs[2])}
def __str__(self):
return "{}".format(self.name)
def __repr__(self):
return self.__str__()
def scrape_monster_levels():
superuniques = []
with open('raw/d2jsp_tcs.txt', 'r') as lfile:
cur_act = None
i = 0
for line in lfile:
#print("Line:", line)
#print(len(line.strip()))
if i == 0 or len(line.strip()) == 0:
i += 1
continue
if 'Act ' in line and 'Act Boss' not in line:
cur_act = line[:10].strip()
#print(cur_act)
continue
line = line.replace("(Act Boss)", "")
data = re.match(r'([a-zA-Z ]+)[\s]*(\d+)[\s]*\((\d+)\)[\s]*(\d+)[\s]*\((\d+)\)[\s]*(\d+)[\s]*\((\d+)\)', line)
#print(data)
if data is None:
#input("")
continue
#print(data.group(1))
lvls = [data.group(i) for i in range(2, 8)]
#print(lvls)
superuniques.append(Monster(data.group(1).strip(), cur_act, [lvls[0], lvls[2], lvls[4]], [lvls[1], lvls[3], lvls[5]]))
#print(x)
print(superuniques[-1])
print(len(superuniques))
return superuniques
def add_qlvls(items):
qlvls = {}
tcs = {}
with open('raw/TC 1.10 - Diablo Wiki.html', 'r') as lfile:
cur_tc = None
for line in lfile:
tc_match = re.findall(r'TC (\d+)', line)
if len(tc_match) > 0:
print("Cur tc:", tc_match)
cur_tc = int(tc_match[0])
continue
matches = re.findall(r'\d\d\) ([^(\n<]*) \(qlvl (\d+)\)', line) + re.findall(r'<a href=[^\n<>]*>([^(\n<]*)<\/a> \(qlvl (\d+)\)', line)
#page = lfile.read()
#matches = re.findall(r'\d\d\) ([^(\n<]*) \(qlvl (\d+)\)', page) + re.findall(r'<a href=[^\n<>]*>([^(\n<]*)<\/a> \(qlvl (\d+)\)', page)
for item, qlvl in matches:
qlvls[item.lower().replace("'", "").replace(" ", "")] = int(qlvl)
tcs[item.lower().replace("'", "").replace(" ", "")] = cur_tc
#print(qlvls)
tc_attrmatch, qlvl_attrmatch = None, None
for attr_match in attribute_matches:
if attr_match.name == 'Treasure Class':
tc_attrmatch = attr_match
elif attr_match.name == 'Quality Level':
qlvl_attrmatch = attr_match
assert tc_attrmatch is not None and qlvl_attrmatch is not None
for item in items:
if not isinstance(item, (WhiteItem, UniqueItem, SetItem)):
continue
if 'Rainbow Facet' in item.name:
item.qlvl = 85
item.tc = 0
elif 'Annihilus' in item.name or 'Hellfire Torch' in item.name:
item.qlvl = 110
item.tc = 110
else:
item.qlvl = qlvls[item.name.lower().replace("'", "").replace(" ", "")]
item.tc = tcs[item.name.lower().replace("'", "").replace(" ", "")]
if item.eth_item is not None:
item.eth_item.qlvl = item.qlvl
item.eth_item.tc = item.tc
print(item.name, item.qlvl, item.tc)
# insert base attributes for qlvl/tc
item.attr_dict[tc_attrmatch] = Attribute(tc_attrmatch.name, {'v': str(item.tc)}, "treasure class: {}".format(item.tc), False)
item.attr_dict[qlvl_attrmatch] = Attribute(qlvl_attrmatch.name, {'v': str(item.qlvl)}, "quality level: {}".format(item.qlvl), False)
if __name__ == '__main__':
add_qlvls([])