This repository has been archived by the owner on Mar 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dictmaker.py
92 lines (82 loc) · 2.85 KB
/
dictmaker.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
from bs4 import BeautifulSoup
import re
import urllib2
from functions import namer,pretty,urlGrab
def souper(url): #takes the na.leagueoflegends.com url
champ = {}
soup = BeautifulSoup(urlGrab(url)) #string name, can build string from file
s = soup.find_all('table')[1] #this is the stats_table tag
for c in s.contents:
if str(c)[0] == '<':
key = namer(c.contents[1].string)
champ[key+'_base'] = float(c.contents[3].string)
if c.contents[5].span:
champ[key+'_ratio'] = float(re.search(r'\+([ 0-9\.]*)',c.contents[5].span.string).group(1))
return champ
def regexer(url): #takes the lolwiki url
s = urlGrab(url)
c = {}
for ab in ['P','Q','W','E','R']:
print 'ab is: '+ab
a = re.search(r'^{{Ability\|(?P<id>%s).*?^}}'%ab,s,re.M|re.DOTALL)
c[a.group('id').lower()] = {}
things = ['description','description2','name','cooldown','cost','costtype','range','leveling']
for t in things:
if t == 'leveling':
j = re.search(r'\|leveling *=([. \{\}A-Za-z\|0-9\(\)+%\n]*?)(?=\n^(\||\}))',a.group(0),re.M)
else:
j = re.search(r'^\|%s *= *(.+)'%t,a.group(0),re.M)
if j:
j = j.group(1).strip()
if (t == 'cooldown' or t == 'cost' or t == 'range'): #there's more here...
if ab == 'R':
j = pretty(j,ult=True)
elif t == 'range':
j = pretty(j,arange=True)
else:
j = pretty(j)
elif (t == 'leveling'):
#first ability ratio
try:
ratio = re.search(r'\{\{(ability scaling|as)\|\(\+([ 0-9]*)% ([A-Za-z]*)',j)
c[a.group('id').lower()]['damage_ratio'] = float(ratio.group(2).strip())/100.0
c[a.group('id').lower()]['damage_ratio_type'] = ratio.group(3).lower()
except:
print 'wait! the ratio in leveling throws and error!'
#ability's damage type
try:
damage_type = re.search(r'{{lc\|(.*?})',j).group(1)
if damage_type[0] == 'P':
c[a.group('id').lower()]['damage_type'] = 'physical'
elif damage_type[0] == 'M':
c[a.group('id').lower()]['damage_type'] = 'magic'
elif damage_type[0] == 'H':
print 'healing!'
damage = re.search(r'ap[\|0-9]*',j).group(0)
damage = pretty(damage)
c[a.group('id').lower()]['ally_heal_val'] = damage
else:
c[a.group('id').lower()]['damage_type'] = 'true'
except:
print 'damage type in leveling throws an error!'
try:
if damage_type[0] != 'H':
damage = re.search(r'ap[\|0-9]*',j).group(0)
damage = pretty(damage)
c[a.group('id').lower()]['damage'] = damage
except:
print 'still an error in here'
elif (t == 'description' or t == 'description2'):
if j[0] == '{':
if j[6] == 'A':
j = 'Active: '+j[15:]
else:
j = 'Passive: '+j[16:]
elif t == 'costtype':
t = 'cost_type'
try:
c[a.group('id').lower()][t] = j.lower()
except:
c[a.group('id').lower()][t] = j
return c
# print d