-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbuildAdvGear.py
102 lines (87 loc) · 3.11 KB
/
buildAdvGear.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
from bs4 import BeautifulSoup
import requests
import datetime
import json
itemHolder = {}
itemHolder['name'] = 'Pathfinder 2.0 item list'
itemHolder['date'] = datetime.date.today().strftime("%B %d, %Y")
items = []
def get_details(link):
res3 = requests.get(link)
res3.raise_for_status()
soup3 = BeautifulSoup(res3.text, 'lxml')
itemDetails = soup3.find_all("div", {'class':'main'})
detail = soup3.find("span", {'id':'ctl00_MainContent_DetailedOutput'})
itemDetails = {}
children = detail.contents
reachedBreak = False
detailHolder = []
details = {}
tagType = ""
for child in children:
stringContents = str(child)
if stringContents.startswith("<"):
if child.name == "hr":
reachedBreak = True
if child.name == "b":
if child.text == "Source":
tagType = child.text.lower()
else:
tagType = ""
if child.name == "h2":
break
if child.name == "a":
details[tagType] = child.text
else:
if tagType != "":
details[tagType] = stringContents
if reachedBreak:
detailHolder.append(stringContents)
string = " "
details['text'] = string.join(detailHolder)
return details
def get_adv(link, category):
res2 = requests.get(link)
res2.raise_for_status()
soup2 = BeautifulSoup(res2.text, 'lxml')
item = soup2.find_all("div", {'class':'main'})
main = soup2.find("span", {'id':'ctl00_MainContent_DetailedOutput'})
#print(detail.contents)
table = soup2.find(lambda tag: tag.name=='table' and tag.has_attr('id') and tag['id']=="ctl00_MainContent_TreasureElement")
j = 0
rows = table.findAll(lambda tag: tag.name=='tr')
for row in rows:
j += 1
#print(row)
#print("-----------------------------------")
item = {}
entries = row.find_all(lambda tag: tag.name=='td')
if entries is not None:
if len(entries) > 0:
name = entries[0].find("a").text
itemLink = "https://2e.aonprd.com/"+entries[0].find("a")['href']
level = entries[1].text
price = entries[2].text
bulk = entries[3].text
item['name'] = name
item['link'] = itemLink
item['level'] = level
item['price'] = price
item['bulk'] = bulk
item['category'] = category
print("Getting item:", item['name'])
details = get_details(itemLink)
len(details.keys())
for key in details.keys():
item[key.lower()] = details[key]
items.append(item)
#if j > 5:
#break
return items
itemHolder['adventuringGear'] = get_adv("https://2e.aonprd.com/Equipment.aspx?Category=1", "Adventuring Gear")
json_data = json.dumps(itemHolder, indent=4)
#print(json_data)
filename = "advGear-pf2.json"
f = open(filename, "w")
f.write(json_data)
f.close