Skip to content

Commit

Permalink
2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Maselkov committed Jul 11, 2018
1 parent 71dfa31 commit 7411110
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 108 deletions.
20 changes: 11 additions & 9 deletions config.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[API]
APIKey =

[Discord]
UpdateFrequency = 10

[Settings]
CloseWithGw2 = False
DisplayGuildTag = true
[API]
APIkey =

[Settings]
CloseWithGW2 = False
DisplayGuildTag = True

[PointsOfInterest]
DisableInWvW = False
DisableCompletely = False

22 changes: 17 additions & 5 deletions gw2rpc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@


class APIError(Exception):
pass
def __init__(self, code):
self.code = code


class GW2Api:
Expand All @@ -19,7 +20,9 @@ def check_key(key):
required_permissions = ["characters", "builds", "account"]
for p in required_permissions:
if p not in res["permissions"]:
log.warning("API key missing required permission: {}".format(p))
log.warning(
"API key missing required permission: {}".format(
p))
return False
log.info("API key verified")
return True
Expand Down Expand Up @@ -54,6 +57,11 @@ def get_account_and_world():
def get_map_info(self, map_id):
return self._call_api("maps/" + str(map_id))

def get_continent_info(self, map_info):
ep = ("continents/{continent_id}/floors/{default_floor}/regi"
"ons/{region_id}/maps/{id}".format(**map_info))
return self._call_api(ep)

def get_character(self, name):
if not self._authenticated:
return None
Expand All @@ -70,7 +78,7 @@ def _call_api(self, endpoint, *, key=None):
else:
r = self.__session.get(url)
if r.status_code != 200:
raise APIError("{0.status_code}: {0.reason}".format(r))
raise APIError(r.status_code)
return r.json()


Expand All @@ -81,11 +89,16 @@ def __init__(self, keys):
self._clients = [c for c in self._clients if c._authenticated]
self._authenticated = len(self._clients) != 0
self._last_used_client = None
self.account, self.world = (self._clients[0].account, self._clients[0].world) if self._authenticated else (None, None)
self.account, self.world = (
self._clients[0].account,
self._clients[0].world) if self._authenticated else (None, None)

def get_map_info(self, map_id):
return self._unauthenticated_client.get_map_info(map_id)

def get_continent_info(self, map_info):
return self._unauthenticated_client.get_continent_info(map_info)

def get_character(self, name):
if self._last_used_client:
try:
Expand All @@ -110,5 +123,4 @@ def get_guild(self, gid):
return self._unauthenticated_client.get_guild(gid)



api = MultiApi(config.api_keys)
Loading

0 comments on commit 7411110

Please sign in to comment.