Java Script Command For Club Invites - Any Coding Professionals Here?

Sort:
Colby-Covington

Hello, a very helpful and friendly member named @APISTOTELHS recently helped us figure out a script, to be entered in the Firefox Console, which returns all usernames in a club.

var request = new XMLHttpRequest();
request.open('GET','https://api.chess.com/pub/club/the-chess-elite/members',false);
request.send();
var response = JSON.parse(request.responseText);
var list = '';
for(type in response)for(member of response[type])list += member.username + '\r\n';
console.log(list);

We are now facing a new problem, and require a minor modification to the previous code.

What we would like to achieve:

Extract all usernames, but from those who were "Most Recently Online"

You can display only the members who were most recently online via this box:

Here an example in full view, from this club:


How could we do that with the script?

antisunechess

just change the link in the second line of the code

antisunechess

add this at the end of the link, where it says members: ?sortType=last_online_date, so that the link becomes 'https://api.chess.com/pub/club/the-chess-elite/members?sortType=last_online_date

antisunechess

at least I think this should work

msd238
antisunechess wrote:

add this at the end of the link, where it says members: ?sortType=last_online_date, so that the link becomes 'https://api.chess.com/pub/club/the-chess-elite/members?sortType=last_online_date

^

stephen_33

I'm intrigued to see if that suggestion works because I very much doubt it will. As I understand it, the REST type of API provided by the site gives only the data contained within the endpoints. It's a case of either downloading the entire endpoint or not - there isn't a way of selecting particular fields or elements within the data.

It seems to me as if you're trying to use the API in an interactive way & I can't see that working but I'll be happy if I'm wrong.

Tricky_Dicky

Afraid that will not work. If you look at the specification for the club member end point it states that the member list is returned in three categories based on club activity, (defined in the spec). The query suggested above is just ignored.

Th only way to achieve your goal is to go through the member list returned and obtain their last logon date using the member profile endpoint.

https://api.chess.com/pub/player/{username} 

One of the items returned is

 "last_online": 1500661803

The time stamp then needs to be isolated and converted.
This is a number calculated as the time measured in the number of seconds
since the Unix Epoch (January 1 1970 00:00:00 GMT).
stephen_33
antisunechess wrote:

add this at the end of the link, where it says members: ?sortType=last_online_date, so that the link becomes 'https://api.chess.com/pub/club/the-chess-elite/members?sortType=last_online_date

I may be missing a trick here but have you tried simply entering that URL into the address bar of your browser & seeing what's returned?

https://api.chess.com/pub/club/the-chess-elite/members?sortType=last_online_date

I did & only the members list is returned as for the endpoint. You can't interrogate the chess.com API if that's what you're trying to do.

Tricky_Dicky

Actually just realised unless you actually need the logon date then you just need to sort the logons by highest timestamp number i.e latest date. but you would need to combine the three category lists first and append the time stamp number to each member name.

antisunechess

Well I haven't worked with the chess.com api, just gave a suggestion, so yeah I'm not surprised it doesn't work

stephen_33
Tricky_Dicky wrote:

Actually just realised unless you actually need the logon date then you just need to sort the logons by highest timestamp number i.e latest date. but you would need to combine the three category lists first and append the time stamp number to each member name.

But if you mean this endpoint...

https://api.chess.com/pub/club/{url-ID}/members

..that provides only the member joined-date, not any online or club activity data.

I don't see a way around having to use at least two different endpoint types & making separate requests for every single player login required.

{
  "weekly": [
    {
        "username": "string", //username
        "joined": "integer",  //timestamp
    }
  ],
  "monthly": [
    {
        "username": "string", //username
        "joined": "integer",  //timestamp

etc..

Tricky_Dicky

Correct. It needs to combine the Club members end point with the member profiles.

Colby-Covington

Hey guys, thank you so much for your engagement and interest!

OK I see it can't be done, but still thanks a bunch for your efforts. 

If there's anything we can offer you in return, please feel free to ask! happy.pngthumbup.png

Nevfy

@Colby-Covington It can be done and @Tricky_Dicky gave you the idea of realization:

  1. You get list of all players in the club with no regard to its level of activity in this club (one request to API, you have this part done);
  2. For each player you get its "last_online" timestamp from player's endpoint (one additional request to API per player);
  3. Sort your list by this value.
stephen_33
Colby-Covington wrote:

Hey guys, thank you so much for your engagement and interest!

OK I see it can't be done, but still thanks a bunch for your efforts. 

If there's anything we can offer you in return, please feel free to ask!

It can certainly be done (I collect, sort & process all kinds of data from the site's endpoints), just not the way you want to.

One word of caution though - downloading player endpoints is becoming very time consuming!

Colby-Covington
Nevfy wrote:

@Colby-Covington It can be done and @Tricky_Dicky gave you the idea of realization:

  1. You get list of all players in the club with no regard to its level of activity in this club (one request to API, you have this part done);
  2. For each player you get its "last_online" timestamp from player's endpoint (one additional request to API per player);
  3. Sort your list by this value.

Ah, that's great news then!happy.png

I'm personally not qualified to write that code, I must admit. If any of you are able and willing to put that down, I'd of course compensate you for your work.

stephen_33

You might try asking around, starting in your club, to see if any keen coders want the challenge? It's not really that difficult & a reasonably competent amateur programmer would probably be able to obtain a list for you on a fairly short timescale.

Colby-Covington

Does the API offer an option for "Most Recently Active" by any chance?

 

Nevfy

No. However, players are grouped by activity.

https://www.chess.com/news/view/published-data-api#pubapi-endpoint-club-members

stephen_33
Colby-Covington wrote:

Does the API offer an option for "Most Recently Active" by any chance?

 

No. As we've explained there's no choice but to obtain the list of players you're interested in & then downloading the endpoint for each one in order to find their last login.

I'd question if club-player-activity is of much use to you because participation in club matches, for example, is not regarded as actual activity!