API to access public galaxy data

update → API 2.1

Due to issues with old hosting, here is new link: NP API

old website https://cqproject.net/
new website https://qwerty.xyz/

BTW, I have improved the code and documentation a bit and I also added SSL (https) certificates for security. Now you can safely use your own login credentials to query your own fleet and star data!

Just keep in mind that I could read your password, so use a unique one!

API 1.0

http://nptriton.cqproject.net/
new url: http://nptriton.qry.me/

It returns JSON object

Usage:
/game/<game_number>[/(stars|players|fleets|full|basic)]

Example: http://nptriton.cqproject.net/game/1234567890123456/stars

Unfortunaly it won’t return fleets data unless the game has ended, because they are not publicly available, BUT I may add option to log in - at your own risk. (would you want that?)

5 Likes

#API2.0, The NP2 database
I’ve been collecting NP2 data of games I was in since 25.5.
14 games with more than 3 M items in a size of 170 MB.

If you use spread sheets reguralry for your games, have any programming skills or knowledge of plotting data to graphs, or if you are just bored or curious, contact me :wink:

“I am offering complete access to my API, if you make publicly available whatever you create.”

for example: The most desired functionality which started all this is to draw the stored data to a graph and then to switch between the ticks to provide a historical view without the need of making screenshots.

the database; sneak peak

recorded games

The data I record are

Once for every game

  1. games
  2. players
  3. stars

Every two hours

  1. stars_owners_rel
  2. players_data

These are the columns

I am storing pretty much everything except fleet moves.


So,… a script is run every two hours, which loads game numbers from my database and then one by one queries the NP2 servers (using my API) and stores the data back in a database.

It stores the immutable info once and the mutable every two hours.

  • Immutable: game info, player names, star coords, …
  • mutable: star owners, player stats

URL

http://nptriton.cqproject.net/ticks/<range>/<game_number>/<type>

Usage
If you understand regular expressions, this might be the best way to describe the possibilities:

^ticks?(?:/([-,0-9]+))?/([0-9]+)(?:/(stars|players|full)\b)?/?$

range:
/x/    number of tick to show
/x-/   from x
/-x/   to x
/x-y/  from x to y
//     empty for all
/x,y,z-a/  It will also soon accept commas. (not yet ready)

type:
stars, players
full  (not yet working)

Examples:

/ticks/1/1234567890123456/players # displays players data at tick 1
/ticks/72-/1234567890123456/stars
# displays the star data from tick 72 to the end for the game 1234..

Example: http://nptriton.cqproject.net/ticks/42/4610412414763008/stars

*You can see game numbers of stored games in a picture above.

1 Like

This is cool, I will be exploring it.

1 Like

Hi folks,
This seems like a super useful tool.
I try with this:
http://nptriton.cqproject.net/game/5880903038664704/full
but I get a “null”
am I doing something wrong?

@Qwerty 's code has not worked in almost a year. I think Jay told me it may have something to do with his NP2 change to https, and Qwerty has been afk and not maintaining his code.

1 Like

thanks!
is there anything else like it around?

Thanks for bumping! I fixed the issue with secured http.

1 Like

And now it works ! THANKS @Qwerty ! :slight_smile:

@Qwerty Cool! I first tougth this was Jay’s api too, but glad I found it out already… :wink:

I am using your api to track the 1v1 tournaments that are running requlary. Just tought I’d say thanks, it’s working like a charm!

http://np2stats.dysp.info/decembertournament.php

3 Likes

Wow :heart_eyes:, what an honor! I never thought people would be still using it.

I haven’t logged into that server since the last fix. Let me find my ftp client and do some statistics on the logs :slight_smile:

I’ve just checked your site and it’s awesome! Turns out I did have an account there already. My browser was kind enough to remind me :slight_smile:

2 Likes

So, I managed to find an old ftp client on my backups with my credentials and checked the server. I no longer understand the language it is written in :dizzy_face: (PHP). I have no idea what the scripts do any more :sweat_smile:

Anyway, there are 323447 hits on my api and the log is 22 MB. Some 9 games are being checked every 15 minutes :slight_smile:. Those seem to be the tournaments as there are only two players in those games. Seems like only you @Dysp are using it :slight_smile:

There wass also a database of some 700 in-game-player nicks in a database, but the database is no longer used as I stopped the API 2.0 project.

I am glad to see the main api still works though, wow!

And I have also noticed it is possible to provide own credentials to go around the public data limitation.

Welcome Back @Qwerty glad to see you again. Now get into a game. I think I owe you, or you owe me.

1 Like

In the end I spent more time hacking than playing… So, here it goes :slight_smile:

Thank you for doing it and letting it run! It’s awesome!

Yes, that’s me. :wink: @Qwerty does it cost extra for you if I ramp the update speed up? I wanted to go soft and only do updates between 15minutes. We can keep it at that or go as fast as you think is ok. I might also expand it to all games that are added to NP2Stats. NP2Stats is currently tracking 26 other games in addition of the current 8 tournament games.

Honestly, I have no idea :slight_smile:, I am not using that old PHP hosting for ages now and it only hosts few other projects that are used sparingly.

But why even more often anyway? Whatever can happen during that time that you would like to collect the data more often? Though I think you can try it.

I wonder, If you do all the 26 games at once, how long does it take?
BTW: The hosting only has 8 php processes with 30s timeout.

I would like to learn more about your tool, where do I start?
- I read some mentions here in forum, but not many
- I added a game, updated it after a tick and I can see the map. AMAZING!
But I would like to learn more - how does it work? What other features it has?
How is the API Code working . what does it allow you to do with the game?

Just to get more precision on when the turns run. I dont mind it at 15mins, but for example 5 minutes would be more 2021, I think… :wink: I have some experimental features like sending message to mobile when the new tick is available etc, they would slightly benefit from more up to date info. Ticks in turn based games run as soon as last player hits submit, so it can happen any time during the current 15 minutes.

One question back though. How often are you updating data from NP2? Obviously it doesn’t make any sense for me to use 5 minutes, if you update every 30 minutes or so.

I am fetching only one game a at time from your server. And it usually takes a lot less than 1 second for your server to deliver all the data for one game. I can also add “busy loop” to fetch next game only after at least 1000 milliseconds have passed from the start of last query. So it should not stress your resources at all as I wait for the previous query to finish and add some extra delay before fetching the next game.

Thanks. I’m sorry I don’t have an tutorial or manual for it, but using the old interface you use “see stats” to compare the game statistics between any tick against any other tick. Who built what at what tick etc. “See map” you already tested, once you have more ticks in database you will be able to replay the map development. “Set teams” will let you set teams in larger games and see the stats of your own team vs your predicted opposing alliance. You can also create links to share data with your allies etc.

I recommend that you add the game trough the new interface, which is still under work. But adding it from there you will get your game ticks updated automatically. The old system required you to push the “Update data” button each tick you wanted to follow. It’s a bit confusing as it’s mixed old and new UI, but ask if any confusion. :wink:

Parsing data about the tournament pages is pretty much what I use it for now.

You can try shorter intervals, and thank you for doing one at a time with the busy loop.
My API is just a proxy to triton’s server, so you’ll always get fresh data. I mimic the requests the game does on its own. The challenge was just that it needs an authentication cookie with every request, so doing it manually every time was not an option.

Haha, I figured the “Update data”. It indeed was confusing when I was just adding the game for the first time, but no other button did anything, so I pressed it to see what happens next :smiley:. I also did an early version analysis for teams, which my team used during the king of the hill game (it also had an overlay UI on top of the game), but I never finished it and ultimately abandoned it and stopped the API 2.0 project with database altogether.

I wonder, if you’ve done the hard work and you are storing the tick data, would you make your data accessible via API? I would like to build something with it.

Are you sure you wanted to show me this? :grin:
I wonder if I could simplify my code a bit with this, or provide users more data, since the public report of any game is limited.

Although quite the impressive goal, Dysp probably wanted to link one of these :smiley:

Thanks for the great work you two are doing!

@Qwerty Ooh, ok. It was easier to setup the tournament games with your api, which has no auth required. But I already have the “normal” games updated straight from the NP2 servers every 30minutes. I figured out the authentication cookie trick also, so I can use it directly. I was just concerned about the NP2 servers which are at times under heavy traffic and wanted to share the load with your api. But if it’s passthrough, I’ll just leave tournament updates for 15mins and others at 30mins.

Yes, all games which are added to NP2Stats are using Jay’s API and I am storing all the star data etc on my database. I don’t even know how many years of data is there, but DB is getting quite huge. Been meaning to write clean up code for anything older than 2-3 years. :wink:

I could do the API, but I’m kinda slow getting things done at the moment.

@Trucriot Thanks. Got my hobbies mixed a bit. Nothing secret there, but correcting the link. Thanks for the correct link. :wink:

Jay’s API? You mean something official/documented or just the endpoints taken straight from the game?

And as for the link, by what does it allow you to do I meant more like how to use it and what I can get from it. I couldn’t find much about it here in forum. I would like to use the API Code over having to authenticate with a cookie - if that’s for example what it allows one to do?