live games in progress / API

Hi All,

I would like to develop a python script to download all live games in progress, particularly I want to count user rankings so I can see a chart of when I have the best chance of getting games at different parts of the day.

My thoughts are to download the current list in progress every 10 minutes, build an array that counts the number of players at each K or Dan level and then work out the average per rank per hour over a 7 day period.

I have looked at the API documentation.

I have tried

https://online-go.com/api/v1/ui/overview/

But I am just getting the following back

HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "active_games": [],
    "challenges": []
}

Many Thanks

Overview is just your home page. As you can see from the api call, it’s mainly just returning (your) active games.

You might need to use websocket to query the games-in-progress list. Please see how OGS does it:


a chart of when I have the best chance of getting games at different parts of the day.

btw, this sounds super useful, please share what you find!

I have checked the docs again and it needs an auth token.
So far I have not managed to get my registered client / client secret to authorise.
I have raised various queries but have not seen any answers.

I will check again.

Even if you figure out the auth token, that endpoint doesn’t have the information you’re looking for.

Yes - so I have descovered.

I have managed to get the OGSclient import working.
Here’s my basic code:


from ogsapi.client import OGSClient

# change these 

client_id = 'xxx'
client_secret = 'xxx'
username = 'myogs_account_username'
password = 'myogs_account_password'

ogs = OGSClient(client_id, client_secret, username, password)

print(ogs)


vitals = ogs.user_vitals()
print(vitals)

endpoint = f'/ui/overview'
my_games = ogs.api.call_rest_endpoint('GET', endpoint=endpoint).json()

print(my_games)


Just need the right endpoint for giving me a list of all the current live games.

If you’re using OGSClient library, you’ll want to use its ogssocket class and send/observe “gamelist/query” and “gamelist/count” messages.

I’m not sure how to code the OGSClient to use a event handler for the sockets.
I have had a look at the example code.

What I dont understand is how I setup the socket and handler and then keep the python code running so that the handler gets called while the code keeps running.
Do I just do something like

ogs.socket_connect(ogs_event_handler)

sleep(1 hour) # allow handler to be called

ogs.socket_disconnect()
1 Like