forked from breyr/Destiny-Dump
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
97 lines (71 loc) · 3.13 KB
/
main.py
File metadata and controls
97 lines (71 loc) · 3.13 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# ---- Workspace setup instructions: ----
# pip install requests
# pip install beautifulsoup4
# pip install lxml
from bs4 import BeautifulSoup
import requests
# appends a file with links to every weapon on light.gg
def getWeaponLinks():
f = open("weaponLinks.txt", "a")
counter = 1
while (counter <= 1154):
print(counter)
url = 'https://www.light.gg/db/category/1?page='+ str(counter)
response = requests.get(url)
soup = BeautifulSoup(response.content, 'lxml')
for link in soup.find_all('a'):
if '/db/items/' in link.get('href') and 'compare' not in link.get('href'):
f.write('https://www.light.gg' + link.get('href') + '\n')
counter += 1
f.close()
lines = open('weaponLinks.txt', 'r').readlines()
lines_set = set(lines)
out = open('weaponLinks.txt', 'a')
for line in lines_set:
out.write(line)
lines.close()
return
# appends a file with an array of dictionaries containing stats about each weapon on light.gg
def getWeaponStats():
weaponLinksFile = open('weaponLinks.txt', 'r')
links = weaponLinksFile.readlines()
weaponStatsFile = open('weaponStats-Dec6.txt', 'a')
weaponStatsFile.write("[\n")
tempDict = {}
counter = 0
for link in links:
print(str(counter) + ' -----------------------------------------------------------------------------')
counter += 1
response = requests.get(link.strip())
soup = BeautifulSoup(response.content, 'lxml')
if len(soup.find_all('span', class_="weapon-type")[0].text.strip().split('/')) >= 2:
if soup.find_all('span', class_="weapon-type")[0].text.strip().split('/')[2].strip() == 'Weapon Ornament':
continue
tempDict['weapon_id'] = link.split('items/')[1].strip()
tempDict['Name'] = soup.find_all('h2')[0].text.strip()
tempDict['Rarity'] = soup.find_all('span', class_="weapon-type")[0].text.strip().split('/')[0].strip()
if len(soup.find_all('span', class_="weapon-type")[0].text.strip().split('/')) == 4:
tempDict['Class'] = soup.find_all('span', class_="weapon-type")[0].text.strip().split('/')[1].strip()
tempDict['Element'] = soup.find_all('span', class_="weapon-type")[0].text.strip().split('/')[2].strip()
tempDict['Type'] = soup.find_all('span', class_="weapon-type")[0].text.strip().split('/')[3].strip()
else:
tempDict['Class'] = 'Any'
tempDict['Element'] = soup.find_all('span', class_="weapon-type")[0].text.strip().split('/')[1].strip()
tempDict['Type'] = soup.find_all('span', class_="weapon-type")[0].text.strip().split('/')[2].strip()
for linkTable in soup.find_all('table', class_="stat-visualizer"):
for row in linkTable.find_all('tr'):
tds = row.find_all('td')
tempDict[tds[0].text.strip()] = tds[-1].text.strip()
perksArray = []
for img in soup.find_all("img", {"class": "mod"}):
if 'Ornament' not in img.get('alt') and img.get('alt').isascii():
perksArray.append(img.get('alt'))
tempDict['Perks'] = perksArray
perksArray = []
print(str(tempDict))
weaponStatsFile.write(str(tempDict) + ",\n")
tempDict = {}
weaponStatsFile.write("]")
return
# getWeaponLinks()
getWeaponStats()