dota2wins: add screename identifier
Add the ability for a user to define a screenname or for the name to be dynamically discovered from the API.
This commit is contained in:
parent
3ce9c13a8a
commit
a1a4127eed
@ -32,7 +32,9 @@ MOCK_MODULES = [
|
|||||||
"requests",
|
"requests",
|
||||||
"bs4",
|
"bs4",
|
||||||
"novaclient.v2",
|
"novaclient.v2",
|
||||||
"dota2py"
|
"dota2py",
|
||||||
|
"urllib",
|
||||||
|
"json"
|
||||||
]
|
]
|
||||||
|
|
||||||
for mod_name in MOCK_MODULES:
|
for mod_name in MOCK_MODULES:
|
||||||
|
@ -24,6 +24,9 @@ class Dota2wins(IntervalModule):
|
|||||||
"bad_threshold"),
|
"bad_threshold"),
|
||||||
("cation_color", "Color of text while win precentage is between good "
|
("cation_color", "Color of text while win precentage is between good "
|
||||||
"and bad thresholds"),
|
"and bad thresholds"),
|
||||||
|
("screenname", "If set to 'retrieve', requests for the users's "
|
||||||
|
"screenname via API calls. Else, use the supplied string as the "
|
||||||
|
"user's screename"),
|
||||||
"format"
|
"format"
|
||||||
)
|
)
|
||||||
required = ("steamid", "steam_api_key")
|
required = ("steamid", "steam_api_key")
|
||||||
@ -34,7 +37,8 @@ class Dota2wins(IntervalModule):
|
|||||||
bad_threshold = 45
|
bad_threshold = 45
|
||||||
matches = 25
|
matches = 25
|
||||||
interval = 1800
|
interval = 1800
|
||||||
format = "{wins}W:{losses}L {win_percent}%"
|
screenname = 'retrieve'
|
||||||
|
format = "{screenname} {wins}W:{losses}L {win_percent}%"
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
api.set_api_key(self.steam_api_key)
|
api.set_api_key(self.steam_api_key)
|
||||||
@ -78,7 +82,18 @@ class Dota2wins(IntervalModule):
|
|||||||
else:
|
else:
|
||||||
color = self.caution_color
|
color = self.caution_color
|
||||||
|
|
||||||
|
if self.screenname == 'retrieve':
|
||||||
|
from urllib.request import urlopen
|
||||||
|
import json
|
||||||
|
response = urlopen(
|
||||||
|
'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s' %
|
||||||
|
(self.steam_api_key, self.steamid))
|
||||||
|
screenname = json.loads(bytes.decode(response.read()))['response']['players'][0]['personaname']
|
||||||
|
else:
|
||||||
|
screenname = self.screenname
|
||||||
|
|
||||||
cdict = {
|
cdict = {
|
||||||
|
"screenname": screenname,
|
||||||
"wins": wins,
|
"wins": wins,
|
||||||
"losses": losses,
|
"losses": losses,
|
||||||
"win_percent": win_percent,
|
"win_percent": win_percent,
|
||||||
|
Loading…
Reference in New Issue
Block a user