khazhyk / osuapi Goto Github PK
View Code? Open in Web Editor NEWSimple osu api wrapper that I can use with both requests and aiohttp
Home Page: http://osuapi.readthedocs.io/en/latest/index.html
License: MIT License
Simple osu api wrapper that I can use with both requests and aiohttp
Home Page: http://osuapi.readthedocs.io/en/latest/index.html
License: MIT License
get_user_best seems to only return user_id, beatmap_id and date. accessing other attributes such as PP only returns with attribute error, not found
similar to this is get_beatmaps only returning title, creator and id
When retrieving user scores using api.get_match(match_id)
, a warning is emitted indicating a missing attribute enabled_mods
in the TeamScore object.
For example, I initialized api = OsuApi(API_KEY, connector=ReqConnector())
and then called match = api.get_match(73235514)
The following warnings were output:
C:\Users\....: Warning: Unknown attribute enabled_mods ("0") in API response for type <class
'osuapi.model.TeamScore'>
warnings.warn("Unknown attribute {} (\"{}\") in API response for type {}".format(k, v, type(self)), Warning)
C:\Users\....: Warning: Unknown attribute enabled_mods ("8") in API response for type <class
'osuapi.model.TeamScore'>
warnings.warn("Unknown attribute {} (\"{}\") in API response for type {}".format(k, v, type(self)), Warning)
C:\Users\....: Warning: Unknown attribute enabled_mods ("2") in API response for type <class
'osuapi.model.TeamScore'>
warnings.warn("Unknown attribute {} (\"{}\") in API response for type {}".format(k, v, type(self)), Warning)
As a result of this, I cannot find a way to get the mods used by each player in a Game
's scores when freemod is enabled in multiplayer.
I needed to store scores in a set, so I added this to SoloScore
:
def __hash__(self):
return hash(self.score_id)
def __eq__(self, other):
return self.score_id == other.score_id
which works as it should for my purposes. Would a PR with that be fine, or is this too specific to my use-case?
{
"accuracy": null,
"count100": null,
"count300": null,
"count50": null,
"count_rank_a": null,
"count_rank_s": null,
"count_rank_sh": null,
"count_rank_ss": null,
"count_rank_ssh": null,
"country": "CL",
"events": [],
"join_date": "2013-03-04 02:28:40",
"level": null,
"playcount": null,
"pp_country_rank": null,
"pp_rank": null,
"pp_raw": null,
"ranked_score": null,
"total_score": null,
"total_seconds_played": null,
"user_id": "2419181",
"username": "nigga"
}
Haven't looked into this much but here's the output:
>>> api.get_user("peppy")
/home/degraafc/.virtualenvs/osubot/lib/python3.6/site-packages/osuapi/dictmodel.py:49: Warning: Unknown attribute count_rank_ssh in API response for type <class 'osuapi.model.User'>
warnings.warn("Unknown attribute {} in API response for type {}".format(k, type(self)), Warning)
/home/degraafc/.virtualenvs/osubot/lib/python3.6/site-packages/osuapi/dictmodel.py:49: Warning: Unknown attribute count_rank_sh in API response for type <class 'osuapi.model.User'>
warnings.warn("Unknown attribute {} in API response for type {}".format(k, type(self)), Warning)
[<osuapi.model.User username=peppy user_id=2>]
How i can get user avatar image or image url?
New attribute needs mapping
I simply can't import ReqConnector due to a circular import ...
Traceback (most recent call last):
File "UsoDiscord.py", line 21, in
from osuapi import OsuMode, BeatmapStatus, OsuApi, ReqConnector
ImportError: cannot import name 'ReqConnector'
(It was working fine on an old machine)
api.get_beatmaps(beatmap_id=975667)
Traceback (most recent call last):
File "./main.py", line 31, in <module>
asyncio.get_event_loop().run_until_complete(f2())
File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "./main.py", line 28, in f2
await api.get_beatmaps(beatmap_id=975667)
File "/usr/lib/python3.7/site-packages/osuapi/connectors.py", line 61, in process_request
return type_(data)
File "/usr/lib/python3.7/site-packages/osuapi/dictmodel.py", line 67, in _
return [oftype(entry) for entry in lst]
File "/usr/lib/python3.7/site-packages/osuapi/dictmodel.py", line 67, in <listcomp>
return [oftype(entry) for entry in lst]
File "/usr/lib/python3.7/site-packages/osuapi/dictmodel.py", line 51, in __init__
setattr(self, attr.field_name, attr.parse(v))
File "/usr/lib/python3.7/site-packages/osuapi/dictmodel.py", line 20, in parse
return self.type(value)
TypeError: float() argument must be a string or a number, not 'NoneType'
Lines 47 to 62 in 19cb80a
I believe your logic was that
raise HTTPError(resp.status, resp.reason, (yield from resp.text()))
Would return existing response text even if the response object is closed.
However, this is not the case with the empty body:
https://github.com/aio-libs/aiohttp/blob/master/aiohttp/client_reqrep.py#L913-L922
Forcing a read on a closed object.
elif resp.status == 504 and retries:
the loop wouldn't run if the retries variable was negative or 0, so this is unnecessary.
The official docs state:
Use string for usernames or id for user_ids.
UnboundLocalError: local variable 'error_text' referenced before assignment gets raised every time osu! servers are timing out/acting up.
Library version: v0.0.32
Python version: 3.6.4
Error when attempting to list the mods of a score using the "Mirror" mod, or at least that's what I assume.
>>> score.enabled_mods
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\taiiwo\Anaconda3\lib\site-packages\osuapi\flags.py", line 68, in __repr__
return "<%s %s>" % (type(self).__name__, " | ".join((tpl.name for tpl in self.enabled_flags)))
File "C:\Users\taiiwo\Anaconda3\lib\site-packages\osuapi\flags.py", line 68, in <genexpr>
return "<%s %s>" % (type(self).__name__, " | ".join((tpl.name for tpl in self.enabled_flags)))
File "C:\Users\taiiwo\Anaconda3\lib\site-packages\osuapi\flags.py", line 88, in enabled_flags
yield self.__flags_members__[lowest_bit]
KeyError: 1073741824
Song: only my railgun (TV Size)
Difficulty: 1.25*
Line 24 in 89a00b5
countGeki = rainbow 300
countKatu = 200
Whatever i'm doing, there is no way to fix thoses errors ...
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/discord/client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "UsoDiscord.py", line 325, in on_ready
update_stats.update_all_stats(conn, cursor)
File "/root/UsoBot/update_stats.py", line 107, in update_all_stats
update_stats(0, conn, api, osuId = osu_id[0])
File "/root/UsoBot/update_stats.py", line 51, in update_stats
apiResults = api.get_user_best(osuId, limit = scores)
File "/usr/local/lib/python3.5/site-packages/osuapi-0.0.15-py3.5.egg/osuapi/osu.py", line 71, in get_user_best
), JsonList(SoloScore))
File "/usr/local/lib/python3.5/site-packages/osuapi-0.0.15-py3.5.egg/osuapi/osu.py", line 34, in _make_req
return self.connector.processrequest(endpoint, {k: v for k, v in data.items() if v is not None}, type)
File "/usr/local/lib/python3.5/site-packages/osuapi-0.0.15-py3.5.egg/osuapi/connectors.py", line 77, in process_request
raise HTTPError(resp.status_code, resp.reason, resp.text)
osuapi.errors.HTTPError: (504, 'Gateway Time-out',
There seems to be new difficulty attributes e.g. 'diff_aim'
My code is making a get_user
call, I'm using the requests
backend. This only happens when my connection drops out.
Note that anywhere you see files in /home/degraafc/code/api/
, they're this module -- I'm working off a symlinked install.
>>> ctx = osubot.context.build_ctx("WindyS | xi - Blue Zenith [Bluanother II (Ascension)]")
Traceback (most recent call last):
File "/home/degraafc/.local/lib/python3.6/site-packages/urllib3/connection.py", line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "/home/degraafc/.local/lib/python3.6/site-packages/urllib3/util/connection.py", line 60, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/usr/lib/python3.6/socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/degraafc/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/home/degraafc/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 346, in _make_request
self._validate_conn(conn)
File "/home/degraafc/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 850, in _validate_conn
conn.connect()
File "/home/degraafc/.local/lib/python3.6/site-packages/urllib3/connection.py", line 284, in connect
conn = self._new_conn()
File "/home/degraafc/.local/lib/python3.6/site-packages/urllib3/connection.py", line 150, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7f981d090828>: Failed to establish a new connection: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/degraafc/.local/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/home/degraafc/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/home/degraafc/.local/lib/python3.6/site-packages/urllib3/util/retry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='osu.ppy.sh', port=443): Max retries exceeded with url: /api/get_user?k=####&u=WindyS&type=string&m=0&event_days=31 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f981d090828>: Failed to establish a new connection: [Errno -2] Name or service not known',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/degraafc/code/api/osuapi/connectors.py", line 90, in process_request
resp = self.sess.get(endpoint, params=data)
File "/home/degraafc/.local/lib/python3.6/site-packages/requests/sessions.py", line 521, in get
return self.request('GET', url, **kwargs)
File "/home/degraafc/.local/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/home/degraafc/.local/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/home/degraafc/.local/lib/python3.6/site-packages/requests/adapters.py", line 508, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='osu.ppy.sh', port=443): Max retries exceeded with url: /api/get_user?k=####&u=WindyS&type=string&m=0&event_days=31 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f981d090828>: Failed to establish a new connection: [Errno -2] Name or service not known',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/degraafc/code/osu-bot-serverless/osubot/context.py", line 27, in build_ctx
player = getplayer(title)
File "/home/degraafc/code/osu-bot-serverless/osubot/context.py", line 53, in getplayer
player = consts.osu_api.get_user(name)
File "/home/degraafc/code/api/osuapi/osu.py", line 51, in get_user
), JsonList(User))
File "/home/degraafc/code/api/osuapi/osu.py", line 31, in _make_req
return self.connector.process_request(endpoint, {k: v for k, v in data.items() if v is not None}, type_)
File "/home/degraafc/code/api/osuapi/connectors.py", line 99, in process_request
resp.close()
UnboundLocalError: local variable 'resp' referenced before assignment
I'll look into this a bit more when I have time but here's a stack trace:
>>> osu = osuapi.OsuApi(k, connector=osuapi.ReqConnector())
>>> p = osu.get_user("cookiezi")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/degraafc/code/osu-bot/venv/lib/python3.6/site-packages/osuapi/osu.py", line 51, in get_user
), JsonList(User))
File "/home/degraafc/code/osu-bot/venv/lib/python3.6/site-packages/osuapi/osu.py", line 31, in _make_req
return self.connector.process_request(endpoint, {k: v for k, v in data.items() if v is not None}, type_)
File "/home/degraafc/code/osu-bot/venv/lib/python3.6/site-packages/osuapi/connectors.py", line 98, in process_request
return type_(resp.json())
File "/home/degraafc/code/osu-bot/venv/lib/python3.6/site-packages/osuapi/dictmodel.py", line 67, in _
return [oftype(entry) for entry in lst]
File "/home/degraafc/code/osu-bot/venv/lib/python3.6/site-packages/osuapi/dictmodel.py", line 67, in <listcomp>
return [oftype(entry) for entry in lst]
File "/home/degraafc/code/osu-bot/venv/lib/python3.6/site-packages/osuapi/dictmodel.py", line 51, in __init__
setattr(self, attr.field_name, attr.parse(v))
File "/home/degraafc/code/osu-bot/venv/lib/python3.6/site-packages/osuapi/dictmodel.py", line 20, in parse
return self.type(value)
File "/home/degraafc/code/osu-bot/venv/lib/python3.6/site-packages/osuapi/dictmodel.py", line 67, in _
return [oftype(entry) for entry in lst]
File "/home/degraafc/code/osu-bot/venv/lib/python3.6/site-packages/osuapi/dictmodel.py", line 67, in <listcomp>
return [oftype(entry) for entry in lst]
File "/home/degraafc/code/osu-bot/venv/lib/python3.6/site-packages/osuapi/dictmodel.py", line 51, in __init__
setattr(self, attr.field_name, attr.parse(v))
File "/home/degraafc/code/osu-bot/venv/lib/python3.6/site-packages/osuapi/dictmodel.py", line 20, in parse
return self.type(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
>>> osuapi.__version__
'0.0.28'
>>> sys.version
'3.6.5 (default, May 11 2018, 04:00:52) \n[GCC 8.1.0]'
How i can get PP from last recent game?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.