-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhades_wiki_parser.py
100 lines (82 loc) · 3.71 KB
/
hades_wiki_parser.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
from bs4 import BeautifulSoup
from consts import wiki_url
from hades_wiki_items import *
from wiki_matcher.wiki_parser import PageParser
class BoonParser(PageParser):
def find_items(self, soup: BeautifulSoup):
items = []
for body in soup.findAll('tbody'):
god_name = ' '.join(body.findParent().find('caption').text.strip().split(' ')[:-1])
for row in body.findAll('tr'):
data = row.findChildren('td', recursive=False)
if data:
items.append([god_name, *data])
return items
def create_item(self, data):
return Boon(data[0], data[1].find('p').text.strip(), data[2].text.strip())
class DuoBoonParser(PageParser):
def find_items(self, soup: BeautifulSoup):
items = []
for body in soup.findAll('tbody'):
god_name = body.findParent().find('caption').text.strip()[:-1]
for row in body.findAll('tr'):
data = row.findChildren('td', recursive=False)
if data:
items.append(data)
return items
def create_item(self, data):
return DuoBoon(data[0].text.replace('\n', ''), data[1].text, data[2].text.replace(' ', '').replace('\n', '').split('/'), data[3].text)
class KeepsakeParser(PageParser):
def find_items(self, soup: BeautifulSoup):
items = []
for row in soup.find('span', {'id':'List_of_keepsakes'}).findNext('tbody').findAll('tr'):
data = row.findChildren('td', recursive=False)
if data:
items.append(data)
return items
def create_item(self, data):
return Keepsake(data[0].text.strip(), data[1].text.strip(), data[2].text.strip())
class LegendaryBoonParser(PageParser):
def find_items(self, soup: BeautifulSoup):
items = []
body = soup.find('span', {'id':'Legendary_Boons'}).findNext('tbody')
rows = body.findAll('tr')
for row in body.findAll('tr')[1:]:
data = row.findChildren('td', recursive=False)
if data:
items.append(data)
return items
def create_item(self, data):
return LegendaryBoon(data[0].text.replace('\n', ''), data[1].text, data[2].text.replace(' ', '').replace('\n', ''), data[3].text)
class CharacterParser(PageParser):
def find_items(self, soup: BeautifulSoup):
items = []
table = soup.find('table', {'class':'navbox'})
for data in table.findChildren('a', recursive=True):
if data and 'title' in data.attrs and 'href' in data.attrs:
item = [data['title'], f'{wiki_url}{data["href"]}']
items.append(item)
return items[2:]
def create_item(self, data):
return Character(*data)
class CompanionParser(PageParser):
def find_items(self, soup: BeautifulSoup):
items = []
for row in soup.find('span', {'id':'List_of_Companions'}).findNext('tbody').findAll('tr'):
data = row.findChildren('td', recursive=False)
if data:
items.append(data)
return items
def create_item(self, data):
return Companion(data[0].text.strip(), data[1].text.strip(), data[2].text.strip())
class MirrorOfNightParser(PageParser):
def find_items(self, soup: BeautifulSoup):
items = []
for row in soup.find('span', {'id':'Talents'}).findNext('tbody').findAll('tr'):
data = row.findChildren('td', recursive=False)
if data:
items.append(data[:4])
items.append(data[4:])
return items
def create_item(self, data):
return MirrorOfNightTalents(data[0].text.replace('\n', ' ').strip(), data[1].text.strip(), data[2].text.replace('\n', ' ').strip())