NATION

PASSWORD

NationStates API (nationdata/regiondata)

Bug reports, general help, ideas for improvements, and questions about how things are meant to work.

Advertisement

Remove ads

User avatar
DWAsnia
Diplomat
 
Posts: 591
Founded: Dec 03, 2012
Ex-Nation

Postby DWAsnia » Tue Apr 08, 2014 12:01 pm

Dremaur wrote:I have a question about this. After trying to do this, I ended up getting this.
Code: Select all
<NATION id="controlled_interests">
<ENDORSEMENTS>
pappyusmc,valknot,great_kleomentia,polvinstrad,oplitia,alecabeta,mouni,the_rubber_duck_empire
</ENDORSEMENTS>
<REGION>Madrigal</REGION>
<FIRSTLOGIN>1375931535</FIRSTLOGIN>
<LASTLOGIN>1396018287</LASTLOGIN>
</NATION>

Most of this makes sense to me. But what i dont understand is how to read the login part.

The login is the timestamp when they first logged in. The second one is when their last login was. As I interpret it, the First login is the found date.
<Acario> it is Drasnia's job to shit in people's cheerios On a self-imposed forum hiatus.

User avatar
Dremaur
Ambassador
 
Posts: 1568
Founded: Jun 17, 2013
Left-Leaning College State

Postby Dremaur » Tue Apr 08, 2014 12:03 pm

But how would you interpret it. Like I don't get what a timestamp is. Bear with me. I'm trying to learn code.
The East Pacific
~~All opinions are my own unless otherwise specified~~


User avatar
DWAsnia
Diplomat
 
Posts: 591
Founded: Dec 03, 2012
Ex-Nation

Postby DWAsnia » Tue Apr 08, 2014 12:08 pm

Dremaur wrote:But how would you interpret it. Like I don't get what a timestamp is. Bear with me. I'm trying to learn code.

The timestamp is how many seconds have passed since January 1st, 1960.

Some reading on it.
<Acario> it is Drasnia's job to shit in people's cheerios On a self-imposed forum hiatus.

User avatar
Dremaur
Ambassador
 
Posts: 1568
Founded: Jun 17, 2013
Left-Leaning College State

Postby Dremaur » Tue Apr 08, 2014 12:14 pm

DWAsnia wrote:
Dremaur wrote:But how would you interpret it. Like I don't get what a timestamp is. Bear with me. I'm trying to learn code.

The timestamp is how many seconds have passed since January 1st, 1960.

Some reading on it.

Seems confusing :P But what i am trying to do is find how long this guy has been innactive.
The East Pacific
~~All opinions are my own unless otherwise specified~~


User avatar
DWAsnia
Diplomat
 
Posts: 591
Founded: Dec 03, 2012
Ex-Nation

Postby DWAsnia » Tue Apr 08, 2014 12:22 pm

Dremaur wrote:
DWAsnia wrote:The timestamp is how many seconds have passed since January 1st, 1960.

Some reading on it.

Seems confusing :P But what i am trying to do is find how long this guy has been innactive.

He was last on at Fri, 28 Mar 2014 14:51:27 GMT. There are quite a few sites that allow you to convert UNIX to real time. This one, for example.
<Acario> it is Drasnia's job to shit in people's cheerios On a self-imposed forum hiatus.

User avatar
Dremaur
Ambassador
 
Posts: 1568
Founded: Jun 17, 2013
Left-Leaning College State

Postby Dremaur » Tue Apr 08, 2014 1:13 pm

DWAsnia wrote:
Dremaur wrote:Seems confusing :P But what i am trying to do is find how long this guy has been innactive.

He was last on at Fri, 28 Mar 2014 14:51:27 GMT. There are quite a few sites that allow you to convert UNIX to real time. This one, for example.

that web site answers it for me.
The East Pacific
~~All opinions are my own unless otherwise specified~~


User avatar
The Blaatschapen
Technical Moderator
 
Posts: 63227
Founded: Antiquity
Anarchy

Postby The Blaatschapen » Tue Apr 08, 2014 1:20 pm

DWAsnia wrote:
Dremaur wrote:But how would you interpret it. Like I don't get what a timestamp is. Bear with me. I'm trying to learn code.

The timestamp is how many seconds have passed since January 1st, 1960.

Some reading on it.


Ummm, you mean January 1st, 1970.
The Blaatschapen should resign

User avatar
DWAsnia
Diplomat
 
Posts: 591
Founded: Dec 03, 2012
Ex-Nation

Postby DWAsnia » Tue Apr 08, 2014 1:34 pm

The Blaatschapen wrote:
DWAsnia wrote:The timestamp is how many seconds have passed since January 1st, 1960.

Some reading on it.


Ummm, you mean January 1st, 1970.

Oops, typo :blush:
<Acario> it is Drasnia's job to shit in people's cheerios On a self-imposed forum hiatus.

User avatar
Nephmir
Ambassador
 
Posts: 1760
Founded: Dec 30, 2013
Ex-Nation

Postby Nephmir » Thu Apr 10, 2014 6:31 pm

How do you get the API telegrams to send to new nations automatically (without NS++ or telegram stamps)? Yes, I know how to send them individually, and I know it'll only work when I'm logged in, but how do I send one to deliver automatically?
SC Resolutions
SC#165 | SC#173
_
_
The 300 Endorsements of Nephmir
"100 by land, 100 by air, 100 by sea."
Mercenary of The Sable Order
Commander in Project Soul

User avatar
Shadow Afforess
Ambassador
 
Posts: 1270
Founded: Nov 06, 2013
Ex-Nation

Postby Shadow Afforess » Thu Apr 10, 2014 6:34 pm

Nephmir wrote:How do you get the API telegrams to send to new nations automatically (without NS++ or telegram stamps)? Yes, I know how to send them individually, and I know it'll only work when I'm logged in, but how do I send one to deliver automatically?


Generally you write some kind of a program to use the api key, telegram id, and have the program check for new nations to send to. API's exist for software to use, hence the name "Application Programming Interface".
Last edited by Shadow Afforess on Thu Apr 10, 2014 6:34 pm, edited 1 time in total.
In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move.

User avatar
Nephmir
Ambassador
 
Posts: 1760
Founded: Dec 30, 2013
Ex-Nation

Postby Nephmir » Thu Apr 10, 2014 7:00 pm

So I have to write my own program? :?
SC Resolutions
SC#165 | SC#173
_
_
The 300 Endorsements of Nephmir
"100 by land, 100 by air, 100 by sea."
Mercenary of The Sable Order
Commander in Project Soul

User avatar
Pining for the Fjords
Political Columnist
 
Posts: 4
Founded: Mar 02, 2014
Ex-Nation

Postby Pining for the Fjords » Tue Apr 15, 2014 9:04 pm

I've never been able to figure this API stuff out. Could someone try their best to explain it for me? Thanks.

User avatar
Starrie
Attaché
 
Posts: 94
Founded: Jan 04, 2012
Ex-Nation

Postby Starrie » Thu Apr 17, 2014 6:09 pm

https://www.nationstates.net/cgi-bin/ap ... +delvotes'

so the last entry in delvotes_for is currently

Code: Select all
<DELEGATE>
<NATION>the_reformed_knights_templar</NATION>
<VOTES>7</VOTES>
<TIMESTAMP>1</TIMESTAMP>
</DELEGATE>


what's up with the timestamp
Last edited by Starrie on Thu Apr 17, 2014 6:09 pm, edited 1 time in total.

User avatar
The Black Hat Guy
Diplomat
 
Posts: 952
Founded: Feb 12, 2013
Ex-Nation

Postby The Black Hat Guy » Fri Apr 18, 2014 8:50 am

Nephmir wrote:So I have to write my own program? :?


Pining for the Fjords wrote:I've never been able to figure this API stuff out. Could someone try their best to explain it for me? Thanks.


Yes, you must write your own program if you'd like to send telegrams automatically. That's the entire point of an API - to allow applications to access data automatically. Alternatively, you can use a program that someone else has made - Afforess has one available, as does Auralia, though he has ceased development and support so far as I'm aware.

Unfortunately, creating one's own program isn't really something that can be explained in a forum post. It requires knowledge of programming, and that's something you learn over time, not in a forum post. If you would like to learn to code (and I suggest you do - it's an incredibly useful skill), CodeCademy is a great resource. Take the Python class, then move into the API section, which will teach you almost exactly the skills you'll need to use the NationStates API. It'll take a few hours at least, but it's definitely worth it, not just for NS.

User avatar
Me or PHP
Lobbyist
 
Posts: 11
Founded: Apr 19, 2014
Ex-Nation

PHP Script; Getting Data Dump Contents

Postby Me or PHP » Sat Apr 19, 2014 6:19 pm

Never mind, I figured it out. :P

/pages/region.xml returns a broken file, one has to use PHP's built in gzip decode on the gzip link to utilize the data dump.
Last edited by Me or PHP on Sun Apr 20, 2014 8:41 am, edited 4 times in total.

User avatar
Glen-Rhodes
Powerbroker
 
Posts: 9027
Founded: Jun 25, 2008
Ex-Nation

Postby Glen-Rhodes » Sat Apr 19, 2014 7:52 pm

The structures of the two files are completely different. There is an additional parent element you need to account for with the region dump.

Also, yes, it is probably too big for what you're doing. Why do you need data on all regions in the game?

User avatar
Me or PHP
Lobbyist
 
Posts: 11
Founded: Apr 19, 2014
Ex-Nation

Postby Me or PHP » Sat Apr 19, 2014 7:55 pm

Never mind
Last edited by Me or PHP on Sat Apr 19, 2014 9:04 pm, edited 1 time in total.

User avatar
Glen-Rhodes
Powerbroker
 
Posts: 9027
Founded: Jun 25, 2008
Ex-Nation

Postby Glen-Rhodes » Sat Apr 19, 2014 7:59 pm

I wrote the sample code you're using. ;)

SimpleXML can handle it. But the way you're going about it is going to get your server rate-limited. You should only be downloading the dumps once a day. It's very possible that the API has already blocked you for a bit.

The problem you're having here is that your code isn't matching the dump's XML structure. Open the XML file and examine the structure, and then you'll be able to see how to access everything.

User avatar
Southern Ageena
Bureaucrat
 
Posts: 56
Founded: Apr 16, 2013
Ex-Nation

Postby Southern Ageena » Sat Apr 26, 2014 4:04 pm

Code: Select all
<?php
   $file = 'http://www.nationstates.net/cgi-bin/api.cgi?nation=testlandia';
   $xml = simplexml_load_file($file);
   
   // Type-casting to convert object to string, so that it can be stored. May not be necessary here, but it's always better safe than sorry.
   $population = (string) $xml->POPULATION;
   $civil_rights = (string) $xml->FREEDOMSCORES->CIVILRIGHTS;

   echo 'Population: ' . $population . '<br />Civil Rights: ' . $civil_rights;
   // Outputs:
   //   Population: 18245
   //   Civil Rights: 74
?>


Hi guys. Hopefully you can help me. I'm using this code but I'm also fetching the "LEADER" tag. However if I have a nation with a leader that has strange letters in its name (eg. Slavoj Žižek) nothing is outputted.

Any Ideas?
Last edited by Southern Ageena on Sat Apr 26, 2014 4:05 pm, edited 1 time in total.
Head judge on the Genuan Rebirth supreme court (second term);
Current Minister of Law Genuan Rebirth (dree terme);
Former Minister of Foreign Affairs Genuan Rebirth;
Founder Beyond the Superpowers of Earth;
Founder Genua

Pro Socialism

User avatar
NewTexas
Spokesperson
 
Posts: 181
Founded: Antiquity
Civil Rights Lovefest

Postby NewTexas » Tue Apr 29, 2014 4:52 pm

[violet], we can always tell when you change the API even if you do not post about it. We can almost guarantee our tool will break. It appears v4 converts all percentages in the feeds from integers to decimals. Interesting. What would be really nice is if you used actual numbers only (decimals or integers) versus putting a "%" in there and forcing us to strip it off to use it in calculations. But, that is not what we came to rant about.

We came to ask about API Versioning. It seems like you have made an effort to make previous versions backwardly compatible, however, all four versions all use the new decimal percentages. Is that really backward compatible?

http://www.nationstates.net/cgi-bin/api ... landia&v=1
http://www.nationstates.net/cgi-bin/api ... landia&v=2
http://www.nationstates.net/cgi-bin/api ... landia&v=3
http://www.nationstates.net/cgi-bin/api ... landia&v=4

:ugeek:
Big Tex
Governor of Texas

Author: NSDossier

User avatar
[violet]
Executive Director
 
Posts: 16206
Founded: Antiquity

Postby [violet] » Tue Apr 29, 2014 4:58 pm

Haha, you are totally right, Big Tex. In this case I decided that since the change was so minor, and didn't involve a format change (it was sending a string value before and it's sending a string value now), it wasn't worth bumping the versioning. But clearly I was wrong. Let me look at it.

User avatar
[violet]
Executive Director
 
Posts: 16206
Founded: Antiquity

Postby [violet] » Tue Apr 29, 2014 6:25 pm

New API Version: 5

Changes:
  1. Outputs as UTF-8. This will also affect all Daily Dumps from now on.
  2. Values under <PUBLICSECTOR>, <GOVT>, and <DEATHS> are displayed in the format "%.1f" (e.g. "21.1"), rather than "%d%%" (e.g. "21%"). Notice that's two differences: an extra decimal place, and no more percentage sign.

Examples: v4, v5.

API documentation

Note that going forward I will only be maintaining the three most recent API versions. If you depend on API version 1 or 2, it may stop working without notice.

User avatar
NewTexas
Spokesperson
 
Posts: 181
Founded: Antiquity
Civil Rights Lovefest

Postby NewTexas » Tue Apr 29, 2014 6:49 pm

WooHoo!

:bow:
Big Tex
Governor of Texas

Author: NSDossier

User avatar
Shadow Afforess
Ambassador
 
Posts: 1270
Founded: Nov 06, 2013
Ex-Nation

Postby Shadow Afforess » Tue Apr 29, 2014 8:18 pm

[violet] wrote:New API Version: 5

Changes:
  1. Outputs as UTF-8. This will also affect all Daily Dumps from now on.
  2. Values under <PUBLICSECTOR>, <GOVT>, and <DEATHS> are displayed in the format "%.1f" (e.g. "21.1"), rather than "%d%%" (e.g. "21%"). Notice that's two differences: an extra decimal place, and no more percentage sign.

Examples: v4, v5.

API documentation

Note that going forward I will only be maintaining the three most recent API versions. If you depend on API version 1 or 2, it may stop working without notice.

I note PUBLICSECTOR still has a hideous percent sign and no decimals... :(
In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move.

User avatar
[violet]
Executive Director
 
Posts: 16206
Founded: Antiquity

Postby [violet] » Tue Apr 29, 2014 8:36 pm

Fixed bug causing percentage signs to display when requesting a nation API with no shards and explicitly specifying a version number of 5 or higher, and a separate bug causing incorrect formatting in API version 5 when looking up nations with a public sector of 100% or 0%.

PreviousNext

Advertisement

Remove ads

Return to Technical

Who is online

Users browsing this forum: Haku, Mavenu, Nirvasyl, Zalta

Advertisement

Remove ads