-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added ranktier.Player - Updated long_description in setup.py
- Loading branch information
1 parent
7f250ab
commit 546257d
Showing
6 changed files
with
93 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
language: python | ||
python: | ||
- "2.7" | ||
- "3.3" | ||
- "3.4" | ||
- "3.5" | ||
- "3.6" | ||
- "3.7" | ||
|
||
script: | ||
- pip install . | ||
- "python test/test.py" | ||
- "python test/test.py $steam_id" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,83 @@ | ||
#!/usr/bin/env python | ||
import json | ||
import socket | ||
import sys | ||
import urllib.request | ||
|
||
VERSION = "1.4.1" | ||
USER_AGENT = "ranktier/{}".format(VERSION) | ||
|
||
|
||
class Rank(object): | ||
|
||
def __init__(self, rank): | ||
def __init__(self, rank, leaderboard=False): | ||
self.leaderboard = leaderboard | ||
|
||
if rank == 'null': | ||
print("This profile has not yet calibrated!") | ||
sys.stderr.write("This profile has not yet calibrated!\n") | ||
self.rank = None | ||
return | ||
|
||
if type(rank) is int or type(rank) is float: | ||
rank = str(rank) | ||
|
||
if not all([rank.isdigit(), len(rank) == 2]): | ||
print("Something went wrong!\nRank input: %s" % rank) | ||
if not all([rank.isdigit(), len(rank) == 2]) and not leaderboard: | ||
sys.stderr.write("Something went wrong!\nRank input: %s\n" % rank) | ||
self.rank = None | ||
return | ||
|
||
self.rank = rank | ||
|
||
|
||
def __str__(cls): | ||
return str(cls.name) | ||
|
||
def __str__(self): | ||
return str(self.name) | ||
|
||
@property | ||
def name(cls): | ||
if cls.rank is None: | ||
def name(self): | ||
if self.rank is None: | ||
return None | ||
|
||
if self.leaderboard: | ||
return "Immortal rank {}".format(self.rank) | ||
|
||
if self.rank[0] == "8": | ||
return "Immortal" | ||
|
||
ranks = {"1": "Herald", | ||
"2": "Guardian", | ||
"3": "Crusader", | ||
"4": "Archon", | ||
"5": "Legend", | ||
"6": "Ancient", | ||
"7": "Divine"} | ||
|
||
return "{} [{}]".format(ranks[self.rank[0]], self.rank[1]) | ||
|
||
|
||
class Player: | ||
|
||
def __init__(self, friend_id): | ||
|
||
self.friend_id = friend_id | ||
try: | ||
profile = self.get_profile_data() | ||
|
||
if profile["profile"]["name"]: # Name of pros | ||
self.name = profile["profile"]["name"] | ||
self.personaname = profile["profile"]["personaname"] # Steam handle | ||
if profile["leaderboard_rank"]: | ||
self.rank = Rank(profile["leaderboard_rank"], leaderboard=True) | ||
else: | ||
if not profile["rank_tier"]: | ||
self.rank = Rank("null") | ||
else: | ||
self.rank = Rank(profile["rank_tier"]) | ||
|
||
except socket.timeout: # API connection timed out | ||
sys.stderr.write("Connection to OpenDota API timed out!\n") | ||
|
||
ranks = { "1" : "Herald" | ||
, "2" : "Guardian" | ||
, "3" : "Crusader" | ||
, "4" : "Archon" | ||
, "5" : "Legend" | ||
, "6" : "Ancient" | ||
, "7" : "Divine" } | ||
def get_profile_data(self): | ||
req = urllib.request.Request(url="https://api.opendota.com/api/players/{}".format(self.friend_id), | ||
headers={"User-Agent": USER_AGENT}) | ||
|
||
return "{} [{}]".format(ranks[cls.rank[0]], cls.rank[1]) | ||
with urllib.request.urlopen(req, timeout=20) as resp: | ||
data = json.loads(resp.read().decode("utf-8")) | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[metadata] | ||
description-file = README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
#!/usr/bin/env python | ||
# -*- coding:utf-8 -*- | ||
|
||
import ranktier | ||
from setuptools import setup | ||
|
||
with open("README.md", "r") as f: | ||
readme = f.read() | ||
|
||
setup(name="ranktier", | ||
version="1.2", | ||
version=ranktier.VERSION, | ||
description="A Dota rank tier converter", | ||
long_description="Ranktier turns two-digit rank tier numbers into human-readable output.", | ||
long_description=readme, | ||
url="https://github.com/marcusmunch/ranktier", | ||
license="GPLv3", | ||
classifiers=[ | ||
|
@@ -16,13 +19,11 @@ | |
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)", | ||
"Natural Language :: English", | ||
"Operating System :: OS Independent", | ||
"Programming Language :: Python :: 2", | ||
"Programming Language :: Python :: 2.7", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.3", | ||
"Programming Language :: Python :: 3.4", | ||
"Programming Language :: Python :: 3.5", | ||
"Programming Language :: Python :: 3.6", | ||
"Programming Language :: Python :: 3.7" | ||
], | ||
author="Marcus Grünewald", | ||
author_email="[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
#!/usr/bin/env python | ||
import sys | ||
|
||
import ranktier | ||
|
||
for n in [42, '42', 'null', 404]: | ||
r = ranktier.Rank(n) | ||
|
||
print(r) | ||
print(r) | ||
|
||
for steamid in sys.argv[1:]: | ||
p = ranktier.Player(steamid) |