This repository has been archived by the owner on Feb 1, 2018. It is now read-only.
forked from vomz/swgoh_code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
starwars.py
172 lines (143 loc) · 5.75 KB
/
starwars.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
from __future__ import print_function
import requests
from bs4 import BeautifulSoup
import time
from sw_util import Collections
#Record beginning time
start_time = time.time()
# Start a session
session = requests.session()
# Try accessing a page that requires you to be logged in
r = session.get('https://swgoh.gg/u/vomz/collection')
# Translate the web page for use in BeautifulSoup
collection = BeautifulSoup(r.text,'html.parser')
print('Collecting characters.......')
# collect and organize the characters that are unlocked
toons=collection.find_all("div","col-xs-6 col-sm-3 col-md-3 col-lg-2")
user = Collections('vomz')
num_chars = len(user.owned_toons())
# missing_light = len(collection.find_all("div","collection-char collection-char-missing collection-char-light-side"))
# missing_dark = len(collection.find_all("div","collection-char collection-char-missing collection-char-dark-side"))
# num_chars = len(toons) - missing_dark - missing_light
# Create links for each character unlocked
links = []
links = [toon.link for toon in user.owned_toons()]
# for i in range(0,num_chars):
# # links.append(toons[i].find_all('a','char-portrait-full-link')[0].get('href'))
# links.append()
# Define needed lists
toons=[]
levels=[]
gear_level=[]
gear_needed=[]
number_needed=[]
stars=[]
skills=[]
skill_levels=[]
category=[]
print('Gathering character data.......')
# Collect information about each of the characters
for i in range(0,len(links)):
page=session.get('https://swgoh.gg/'+links[i])
character=BeautifulSoup(page.text,'html.parser')
# name
if 'Chirrut' in character.find_all('a','pc-char-overview-name')[0].text:
toons.append('Chirrut Imwe')
else:
toons.append(character.find_all('a','pc-char-overview-name')[0].text)
# gear needed and number of gear needed
numneed=[]
gearneed=[]
for j in range(0,len(character.find_all('div','pc-needed-gear-preview'))):
gearneed.append(character.find_all('div','pc-needed-gear-preview')[j].span.get('title'))
numneed.append(character.find_all('div','pc-needed-gear-count')[j].text)
gear_needed.append(gearneed)
number_needed.append(numneed)
# close session
page=page.close()
# Write gear and other information to text files
print('Writing data.......')
file = open('Data/toons.txt','w')
for i in range(0,len(toons)):
file.write(toons[i]+"\n")
file.close()
file = open('Data/gear_needed.txt','w')
for i in range(0,len(gear_needed)):
if len(gear_needed[i])==0:
file.write("\n")
for j in range(0,len(gear_needed[i])):
if j == len(gear_needed[i])-1:
file.write(gear_needed[i][j]+"\n")
else:
file.write(gear_needed[i][j]+", ")
file.close()
file = open('Data/number_needed.txt','w')
for i in range(0,len(number_needed)):
if len(number_needed[i])==0:
file.write("None\n")
for j in range(0,len(number_needed[i])):
if j == len(number_needed[i])-1:
file.write(number_needed[i][j]+"\n")
else:
file.write(number_needed[i][j]+", ")
file.close()
# # Collection of Mod data
# print 'Writing mod data.......'
# lookup = {'I':'1','II':'2','III':'3','IV':'4','V':'5'}
# # Try accessing a page that requires you to be logged in
# num = session.get('https://swgoh.gg/u/vomz/mods/')
# num = BeautifulSoup(num.text,'html.parser')
# page = num.find_all('ul','pagination m-t-0')[0].li.a.text[-1:]
# filex=open('data/mods.txt','w')
# # Collection of mod data for each character
# for i in range(1,int(page)+1):
# mods=session.get('https://swgoh.gg/u/vomz/mods/?page='+str(i))
# mods=BeautifulSoup(mods.text,'html.parser')
# mod_data = mods.find_all('div','collection-mod')
# for j in mod_data:
# mod_level = j.find_all('span','statmod-level')[0].text
# if mod_level != '15':
# continue
# else:
# mod_sum = j.find_all('img','statmod-img')[0].get('alt')
# mod_pip = lookup[mod_sum.split(' ')[1][0:1]]
# mod_group = mod_sum.split(' ')[2]
# mod_slot = mod_sum.split(' ')[-1]
# main_stat_value = j.find_all('span','statmod-stat-value')[0].text[1:]
# main_stat_text = j.find_all('span','statmod-stat-label')[0].text
# try:
# secondary_stat_1_text = j.find_all('span','statmod-stat-label')[1].text
# except:
# pass
# try:
# secondary_stat_2_text = j.find_all('span','statmod-stat-label')[2].text
# except:
# pass
# try:
# secondary_stat_3_text = j.find_all('span','statmod-stat-label')[3].text
# except:
# pass
# try:
# secondary_stat_4_text = j.find_all('span','statmod-stat-label')[4].text
# except:
# pass
# try:
# secondary_stat_1_value = j.find_all('span','statmod-stat-value')[1].text[1:]
# except:
# pass
# try:
# secondary_stat_2_value = j.find_all('span','statmod-stat-value')[2].text[1:]
# except:
# pass
# try:
# secondary_stat_3_value = j.find_all('span','statmod-stat-value')[3].text[1:]
# except:
# pass
# try:
# secondary_stat_4_value = j.find_all('span','statmod-stat-value')[4].text[1:]
# except:
# pass
# filex.write(mod_level+','+mod_pip+','+mod_group+','+mod_slot+','+main_stat_value+','+main_stat_text+','+secondary_stat_1_text+','+secondary_stat_2_text+','+secondary_stat_3_text+','+secondary_stat_4_text+','+secondary_stat_1_value+','+secondary_stat_2_value+','+secondary_stat_3_value+','+secondary_stat_4_value+'\n')
# filex.close()
# print length the file took to run
print("--- %s seconds ---" % (time.time() - start_time))