-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.rb
81 lines (76 loc) · 2.43 KB
/
helpers.rb
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
require 'open-uri'
require 'json'
def parse(hash, i)
r = "nil"
if hash['LeaderboardRankings'][i] != nil
r = hash['LeaderboardRankings'][i]["CurrentMMR"]
end
return r
end
def get_player_info(user)
if user == "\n"
return
end
if user =~ /#/ || user =~ /_/
path = "https://api.hotslogs.com/Public/Players/1/#{user.gsub(/#/, '_')}"
data_from_web = open(path).read
hash = JSON.parse(data_from_web)
if hash['Message'] =~ /error/
results = "Could not find player #{user} \nTry using their player ID"
else
results = "#{hash['Name']} | QM: #{parse(hash, 0)} | UR: #{parse(hash, 1)} | HL: #{parse(hash, 2)} | TL: #{parse(hash, 3)} | URL:\nhttps://www.hotslogs.com/Player/Profile?PlayerID=#{hash["PlayerID"]}"
end
else
path = "https://api.hotslogs.com/Public/Players/#{user}"
data_from_web = open(path).read
hash = JSON.parse(data_from_web)
if hash['Message'] =~ /error/
results = "Could not find player #{user}"
else
results = "#{hash['Name']} | QM: #{parse(hash, 0)} | UR: #{parse(hash, 1)} | HL: #{parse(hash, 2)} | TL: #{parse(hash, 3)} | URL:\nhttps://www.hotslogs.com/Player/Profile?PlayerID=#{hash["PlayerID"]}"
end
end
return results
end
def get_team_info(p1, p2, p3, p4, p5)
results = "#{get_player_info(p1)}\n#{get_player_info(p2)}\n#{get_player_info(p3)}\n#{get_player_info(p4)}\n#{get_player_info(p5)}"
return results
end
def get_masterleague(path)
results = Array.new
data_from_web = open(path).read
hash = JSON.parse(data_from_web)
results[0] = hash['results']
i = 1
while hash['next'] != nil
path = hash['next']
data_from_web = open(path).read
hash = JSON.parse(data_from_web)
results[i] = hash['results']
i += 1
end
return results
end
def get_hero_info(hero)
path = "https://api.masterleague.net/heroes.json"
mldata = get_masterleague(path)
mldata.each do |page|
page.each do |h|
if h['name'].casecmp(hero) == 0
path = "https://api.masterleague.net/heroes/#{h['id']}.json"
data_from_web = open(path).read
hash = JSON.parse(data_from_web)
puts "#{hash['name']} #{hash['url']}"
tier = 1
puts "\nTier: #{tier}"
hash['talents'].each do |talent|
if talent['tier'] > tier
tier = talent['tier']
puts "\nTier: #{tier}"
end
puts "__#{talent['name']}__: #{talent['description']}"
end
end
end
end
end