-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhots.py
217 lines (197 loc) · 8.9 KB
/
hots.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import requests
import bs4
import webbrowser
import sys
import os
class Hero():
def __init__(self, name):
self.name = name.title()
self.primaries = {}
self.heroics = {}
self.url = 'https://heroesofthestorm.com/en-us/heroes/' + self.name.lower()
self.build = 'https://www.icy-veins.com/heroes/' + self.name.lower() + '-build-guide'
self.wiki = 'https://heroesofthestorm.gamepedia.com/' + self.name.lower()
site = requests.get(self.url)
soup = bs4.BeautifulSoup(site.text, 'html.parser')
self.role = soup.find('h4' , {'class':'summaryCard-secondaryHeadline'}).text
self.description = soup.find('div' , {'class':'heroDesc paragraph__description'}).text
abilitylist = soup.find('div' , {'class':'heroAbilities heroAbilities--primary'})
moves = abilitylist.find_all('div' , {'class':'heroAbility'})
for x in moves:
move = x.find('span' , {'class':'heroAbility-name-text'}).text
desc = x.find('span' , {'class':'heroAbility-description'}).text
self.primaries[move] = desc
heroiclist = soup.find('div' , {'class':'heroAbilities heroAbilities--heroic'})
moves = heroiclist.find_all('div' , {'class':'heroAbility'})
for x in moves:
move = x.find('span' , {'class':'heroAbility-name-text'}).text
desc = x.find('span' , {'class':'heroAbility-description'}).text
self.heroics[move] = desc
def showprimaries(self):
for k,v in self.primaries.items():
print('\n' + k + ':\n' + v)
def showheroics(self):
for k,v in self.heroics.items():
print('\n' + k + ':\n' + v)
def showdescription(self):
print('\n"' + self.description + '"')
def info(self):
print('\n' + '-'*80 + '\n')
print('Name: ' + self.name)
print('Role: ' + self.role)
self.showdescription()
print('\n' + '-'*80 + '\n')
print('Primaries:\n')
self.showprimaries()
print('\n' + '-'*80 + '\n')
print('Heroics:\n')
self.showheroics()
print('\n' + '-'*80 + '\n')
#--------------------------------------------------------------------
def hots():
flag = 0
task = 0
while True:
while flag == 0:
try:
if len(sys.argv) <= 2:
request = str(sys.argv[1])
flag += 1
if len(sys.argv) > 2:
request = str(sys.argv[1])
task = str(sys.argv[2])
flag += 2
except:
request = input('Enter the name of a hero: ')
flag += 1
continue
while flag == 1:
try:
hero = Hero(request.strip())
flag = 2
except:
print('\nSomething went wrong, did you enter the hero\'s name correctly?')
print('You entered: ' + '"' + request + '"\n')
flag = 0
sys.argv = []
continue
while flag == 2:
if task != 0:
try:
if task.lower().strip() == 'b':
if request.lower() == 'butcher':
request = 'the-butcher'
if request.lower() == 'etc':
request = 'e-t-c'
if request.lower() == 'hammer':
request = 'sgt-hammer'
if request.lower() == 'morales':
request = 'lt-morales'
if request.lower() == 'vikings':
request = 'the-lost-vikings'
if request.lower() == 'liming':
request = 'li-ming'
if request.lower() == "kelthuzad":
request = "kel-thuzad"
if request.lower() == 'lili':
request = 'li-li'
build = 'https://www.icy-veins.com/heroes/' + request + '-build-guide'
test = requests.get(build)
if test.status_code < 400:
webbrowser.open(build)
flag = 4
continue
if test.status_code >= 400:
print('Page not found. Try again.')
task = 0
flag = 0
sys.argv = []
continue
if task.lower().strip() == 'w':
if request.lower() == 'butcher':
request = 'The_Butcher'
if request.lower() == 'dva':
request = 'D.va'
if request.lower() == 'guldan':
request = "Gul'dan"
if request.lower() == 'kaelthas':
request = "Kael'thas"
if request.lower() == 'kelthuzad':
request = "Kel'thuzad"
if request.lower() == 'liming':
request = 'Li-Ming'
if request.lower() == 'hammer':
request = 'Sgt._Hammer'
if request.lower() == 'zuljin':
request = "Zul'jin"
if request.lower() == 'vikings':
request = 'The_Lost_Vikings'
if request.lower() == 'anubarak':
request = "Anub'arak"
if request.lower() == 'etc':
request = 'E.T.C.'
if request.lower() == 'malganis':
request = "Mal'ganis"
if request.lower() == 'morales':
request = 'Lt._Morales'
if request.lower() == 'lili':
request = 'Li_Li'
wiki = 'https://heroesofthestorm.gamepedia.com/' + request
test = requests.get(wiki)
if test.status_code < 400:
webbrowser.open(wiki)
flag = 4
continue
if test.status_code >= 400:
print('Page not found. Try again.')
task = 0
flag = 0
sys.argv = []
continue
continue
if task != 'b' or 'w':
print('Error! You can only type "B" or "W" after a hero\'s name!\n')
flag = 0
task = 0
sys.argv = []
continue
except:
print(f'Something went wrong, you typed "{request}".')
flag = 0
task = 0
sys.argv = []
continue
if task == 0:
if flag == 4:
break
os.system('cls')
hero.info()
flag += 1
while flag == 3:
request = input('\nEnter "b" for builds, "w" for wiki, the name of a new hero, or hit "Enter" to exit: ')
try:
if request.strip() == '':
flag += 1
continue
if request.lower().strip() == 'b':
print('\nBuild for ' + hero.name + ' requested!')
webbrowser.open(hero.build)
print('Build for ' + hero.name + ' opened!')
continue
if request.lower().strip() == 'w':
print('\nWiki for ' + hero.name + ' requested!')
webbrowser.open(hero.wiki)
print('Wiki for ' + hero.name + ' opened!')
continue
else:
hero = Hero(request.strip())
flag = 1
continue
except:
print('\nSomething went wrong. Did you misspell anything?.')
print('You entered: "' + request + '"')
continue
if flag == 4:
exit()
if __name__ == '__main__':
hots()