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
Cerb
Attaché
 
Posts: 80
Founded: Mar 15, 2013
Iron Fist Consumerists

Postby Cerb » Sat Feb 07, 2015 2:08 pm

I'm probably missing something obvious. I want to track current region of nation,WA status, endorsements, and wehther a nation is active (as in not CTE).

I figured I could just grab the nation daily data dump but it seems to be missing endorsements.
This means I'd have to make a ton of API calls to gather this information.

Even if I just restricted my interest to my region itt would take several hundred calls. I can't afford to do that with the current rate limits.

Ideally endorsements would be present in the daily data dump. I don't need the data to be dynamic, just gathered once a day.

If there is another obvious solution please feel free to suggest it.

Cheers!
cerb

TITO Knight - 10000_islands

User avatar
Laevendell
Envoy
 
Posts: 220
Founded: Jan 29, 2011
Left-wing Utopia

Postby Laevendell » Sun Feb 08, 2015 5:48 am

What does the "created" timestamp on resolutions signify?
How long after a resolution is created does it end? Or is there no set time? If not, could an end time perhaps be added to the resolution shard as well?
EDIT: I figured out I could use the "votetrack" shard to calculate it. A proposal vote lasts 4 days and the votetrack has one value for every elapsed hour.
Last edited by Laevendell on Sun Feb 08, 2015 12:15 pm, edited 1 time in total.

User avatar
Laevendell
Envoy
 
Posts: 220
Founded: Jan 29, 2011
Left-wing Utopia

Postby Laevendell » Tue Feb 10, 2015 1:36 pm

Another suggestion: The happenings shard for nations show when a nation logded a message on the RMB. Would it be possible to include when a nation mentioned you or liked your message (like in Notices)? If you don't want to disturb the main happenings shart, perhaps have it in a separate shard or as a filter in the world happenings shard?

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

Postby [violet] » Tue Feb 10, 2015 9:28 pm

Laevendell wrote:Sorry for triple-posting, but I found an issue with the text of (at least) one issue result.
It says "@@PL(ANIMAL)@@ are considered a delicacy". Shouldn't @@PL(ANIMAL)@@ have been parsed to the national animal (plural) in the text?
EDIT: Also in "the government funds large training centres to turn @@PL(ANIMAL)@@ into functioning members of society".

Should be fixed now. I assume you're talking about the "legislation" nation shard.

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

Postby [violet] » Tue Feb 10, 2015 9:31 pm

Laevendell wrote:Would it be possible to include when a nation mentioned you or liked your message (like in Notices)?

Notices are considered private to the nation (same as which issues it's currently facing), so won't be added to a public API. I'm not sure there's a good way to duplicate the RMB part just for the API.

User avatar
Laevendell
Envoy
 
Posts: 220
Founded: Jan 29, 2011
Left-wing Utopia

Postby Laevendell » Wed Feb 11, 2015 1:44 am

[violet] wrote:Notices are considered private to the nation (same as which issues it's currently facing), so won't be added to a public API. I'm not sure there's a good way to duplicate the RMB part just for the API.

I see, the fact that a nation was mentioned by another nation isn't really very interesting to nations other than the one mentioned.
Is there any consideration of a logged-in API, e.g. along my previous suggestion, using session tokens for very good security?

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

Postby [violet] » Wed Feb 11, 2015 1:04 pm

Laevendell wrote:Is there any consideration of a logged-in API, e.g. along my previous suggestion, using session tokens for very good security?

Which one is that? We're open to the concept. It's something I've been hoping to get one of our more security-aware devs to look at, since the last time I tried to mess in that area, it didn't work out so well.

User avatar
Laevendell
Envoy
 
Posts: 220
Founded: Jan 29, 2011
Left-wing Utopia

Postby Laevendell » Wed Feb 11, 2015 1:33 pm

[violet] wrote:Which one is that? We're open to the concept. It's something I've been hoping to get one of our more security-aware devs to look at, since the last time I tried to mess in that area, it didn't work out so well.

This is the basic idea, that I've seen used for several API:s I've worked with (e.g. the Norwegian Postal service).
You have an API endpoint where you can send in the following:
* nation name
* nation password (or an extra password set in settings that would only work for the API)
* an application token (optional; to identify the calling application)

The caller receives a short-lived access token (valid for perhaps 3 minutes?) and a refresh token.
You can use the refresh token to refresh your access token via another API call (you also get a new refresh token when you do this).

When calling the logged-in API endpoints you have to supply a valid (non-expired) access token rather than your password. This way you only send the password once (and the endpoint could be using SSL).
You could then receive information that is currently only available by fetching the web site and scraping it, on e.g. your dossier, as well as do actions like endorse/unendorse and move between regions. Possibly also telegrams (that would be really great), if you could put in limits so that it would not be abused by scripts. It could certainly reduce the need for web scraping.

User avatar
Unibot III
Negotiator
 
Posts: 7110
Founded: Mar 11, 2011
Democratic Socialists

Postby Unibot III » Wed Feb 18, 2015 9:56 am

This GDP and income information is pretty useful, [violet] - could we get shards for that, please?
[violet] wrote:I mean this in the best possible way,
but Unibot is not a typical NS player.
Milograd wrote:You're a caring, resolute lunatic
with the best of intentions.
Org. Join Date: 25-05-2008 | Former Delegate of TRR

Factbook // Collected works // Gameplay Alignment Test //
9 GA Res., 14 SC Res. // Headlines from Unibot // WASC HQ: A Guide

▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
✯ Duty is Eternal, Justice is Imminent: UDL

User avatar
Aurum Rider
Envoy
 
Posts: 297
Founded: Dec 23, 2013
Corporate Police State

Postby Aurum Rider » Sun Mar 01, 2015 1:19 am

+1 for GDP and income shards
Also, although the national data dump can be helpful, it can be massive and unweidly at the best of times.
Would it be possible for an API call that returns a national data-dump style output for a single region?
Last edited by Aurum Rider on Sun Mar 01, 2015 1:20 am, edited 1 time in total.

User avatar
Eluvatar
Director of Technology
 
Posts: 3086
Founded: Mar 31, 2006
New York Times Democracy

Postby Eluvatar » Thu Mar 05, 2015 12:58 am

Cerb wrote:I'm probably missing something obvious. I want to track current region of nation,WA status, endorsements, and wehther a nation is active (as in not CTE).

I figured I could just grab the nation daily data dump but it seems to be missing endorsements.
This means I'd have to make a ton of API calls to gather this information.

Even if I just restricted my interest to my region itt would take several hundred calls. I can't afford to do that with the current rate limits.

Ideally endorsements would be present in the daily data dump. I don't need the data to be dynamic, just gathered once a day.

If there is another obvious solution please feel free to suggest it.

Cheers!


If you don't mind your endorsement data being generally about 30 seconds out of date, use the NS++ API.
To Serve and Protect: UDL

Eluvatar - Taijitu member

User avatar
Athretvari
Diplomat
 
Posts: 574
Founded: Apr 29, 2012
New York Times Democracy

Postby Athretvari » Sat Mar 28, 2015 2:31 pm

Unibot III wrote:This GDP and income information is pretty useful, [violet] - could we get shards for that, please?


+1 on this! (Pretty please!)
Athretvari
The Realms Banner (flag)
Yeah… I know. It’s a tough one. You can skip

User avatar
Eluvatar
Director of Technology
 
Posts: 3086
Founded: Mar 31, 2006
New York Times Democracy

Postby Eluvatar » Sun Mar 29, 2015 11:13 am

Eluvatar wrote:
[violet] wrote:If you can't set the UserAgent, putting something informative in the URL's query string is definitely better than nothing.

I'm updating all the active gdocs I have edit privileges in to add the below to all API request URLs: :)
Code: Select all
"&gdoc="+SpreadsheetApp.getActiveSpreadsheet().getId()+"&useremail="+Session.getUser().getUserLoginId()


Because getUserLoginId() is being deprecated I would suggest changing the above code to something like:

Code: Select all
  var url = "http://www.nationstates.net/cgi-bin/api.cgi?param_name1=" + param_value1
    + ...
    + "&gdoc=" + SpreadsheetApp.getActiveSpreadsheet().getId() + "&useremail="
    + Session.getUser().getEmail();


For scripts triggered by anonymous user action, I would suggest either not having them, or substituting the sheet owner's email instead:

Code: Select all
  var url = "http://www.nationstates.net/cgi-bin/api.cgi?param_name1=" + param_value1
    + ...
    + "&gdoc=" + SpreadsheetApp.getActiveSpreadsheet().getId() + "&owneremail="
    + SpreadsheetApp.getActiveSpreadsheet().getOwner().getEmail();
Last edited by Eluvatar on Sun Mar 29, 2015 1:09 pm, edited 1 time in total.
To Serve and Protect: UDL

Eluvatar - Taijitu member

User avatar
Vancouvia
Minister
 
Posts: 3043
Founded: Sep 19, 2014
Liberal Democratic Socialists

Postby Vancouvia » Wed Apr 08, 2015 12:20 pm

Hello, I was hoping someone could help me out.

I'm very inexperienced with coding but have a simple request. I currently have https://www.nationstates.net/cgi-bin/ap ... newnations

I would like to have that format but instead of new nations be based on WA joinings (http://www.nationstates.net/page=activi ... ter=member)

Could someone please link me to this?

Thank you

User avatar
Laevendell
Envoy
 
Posts: 220
Founded: Jan 29, 2011
Left-wing Utopia

Postby Laevendell » Wed Apr 08, 2015 12:33 pm

There are two easy ways of getting the information.
The older way is using the WA memberlog shard: https://www.nationstates.net/cgi-bin/ap ... =memberlog
The newer way is using the World happenings shard with a member filter: https://www.nationstates.net/cgi-bin/ap ... ter=member
You'll have to filter yourself with some kind of XML parser if you only want admitted nations e.g.
Last edited by Laevendell on Wed Apr 08, 2015 12:34 pm, edited 1 time in total.

User avatar
Vancouvia
Minister
 
Posts: 3043
Founded: Sep 19, 2014
Liberal Democratic Socialists

Postby Vancouvia » Wed Apr 08, 2015 12:47 pm

Laevendell wrote:There are two easy ways of getting the information.
The older way is using the WA memberlog shard: https://www.nationstates.net/cgi-bin/ap ... =memberlog
The newer way is using the World happenings shard with a member filter: https://www.nationstates.net/cgi-bin/ap ... ter=member
You'll have to filter yourself with some kind of XML parser if you only want admitted nations e.g.



Any way to get it in the same format so it's just separated by commas? I have no idea what a XML parser is, haha.

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

Postby Nephmir » Wed Apr 08, 2015 5:51 pm

Vancouvia wrote:
Laevendell wrote:There are two easy ways of getting the information.
The older way is using the WA memberlog shard: https://www.nationstates.net/cgi-bin/ap ... =memberlog
The newer way is using the World happenings shard with a member filter: https://www.nationstates.net/cgi-bin/ap ... ter=member
You'll have to filter yourself with some kind of XML parser if you only want admitted nations e.g.



Any way to get it in the same format so it's just separated by commas? I have no idea what a XML parser is, haha.

Not sure if it helps, but if you're looking for times such events happened you can go to the activity page filtered on members and click the timestamp next to an event (IE- "seconds ago") and it'll show all the times the events happened instead of the vague timestamp (after the information is available on the API, which I believe has a 28 second delay).

If you're looking to recruit from a list of new members you can use the shard that shows all WA members, and copy and paste what you need out of it. There's also a tag for telegrams (if you're willing to purchase stamps from the store) for new delegates. Otherwise I'm afraid the only option is to use the activity page, unless you can somehow extract what you need through scraping or xml.
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
Vancouvia
Minister
 
Posts: 3043
Founded: Sep 19, 2014
Liberal Democratic Socialists

Postby Vancouvia » Wed Apr 08, 2015 6:10 pm

Nephmir wrote:
Vancouvia wrote:

Any way to get it in the same format so it's just separated by commas? I have no idea what a XML parser is, haha.

Not sure if it helps, but if you're looking for times such events happened you can go to the activity page filtered on members and click the timestamp next to an event (IE- "seconds ago") and it'll show all the times the events happened instead of the vague timestamp (after the information is available on the API, which I believe has a 28 second delay).

If you're looking to recruit from a list of new members you can use the shard that shows all WA members, and copy and paste what you need out of it. There's also a tag for telegrams (if you're willing to purchase stamps from the store) for new delegates. Otherwise I'm afraid the only option is to use the activity page, unless you can somehow extract what you need through scraping or xml.


Ah okay thanks, I was hoping someone already had what I needed, but I guess not. I'm clueless when it comes to coding.

User avatar
Zocra
Diplomat
 
Posts: 874
Founded: Feb 21, 2013
Inoffensive Centrist Democracy

Postby Zocra » Tue Apr 21, 2015 7:55 am

Is there a way to use the api to find range of rmb posts? Like if I wanted to search for posts from the first post ever to the 100th post or something...
Last edited by Zocra on Tue Apr 21, 2015 7:58 am, edited 1 time in total.
Last edited by Google Bot today, edited 1 time in total. | I exist for your benefit.

Founder: United Alliances
Timezone: US Eastern

User avatar
Ever-Wandering Souls
Negotiator
 
Posts: 7267
Founded: Jan 01, 2014
Father Knows Best State

Postby Ever-Wandering Souls » Tue Apr 21, 2015 5:17 pm

If you're just talking about searching for a specific word or phrase, you can do that in the game itself, by going to the RMB in forum view (little link near the top) and searching there :)
Proud Raider; General of The Black Hawks, Ret.
TG me anytime; I'm always happy to talk about anything!

The Alicorns (Equestria) wrote:Let them stay, no need to badmouth them...From our view a bunch of nations just came in, seized the delegate position, and changed a few superficial things...we play NationStates differently...there's really no reason for us to be butthurt.
http://www.nationstates.net/page=rmb/postid=8944227
http://www.nationstates.net/page=rmb/postid=8951258

Misley wrote:
Hobbesistan wrote:Don't think I understand the question.
The color or what?..

Jesus, Hobbes, it's 2015. You can't just call someone "the color".

Reploid Productions wrote:Raiders are endlessly creative

How Do I Telegram API?

Omnis delenda est.

User avatar
Phydios
Minister
 
Posts: 2568
Founded: Dec 06, 2014
Left-Leaning College State

Postby Phydios » Tue Apr 21, 2015 6:41 pm

Ever-Wandering Souls wrote:If you're just talking about searching for a specific word or phrase, you can do that in the game itself, by going to the RMB in forum view (little link near the top) and searching there :)

I think they mean pulling a specific range of RMB posts using the post ID. In their example, it would be getting the API to return the 100 oldest RMB posts that are saved.
If you claim to be religious but don’t control your tongue, you are fooling yourself, and your religion is worthless. Pure and genuine religion in the sight of God the Father means caring for orphans and widows in their distress and refusing to let the world corrupt you. | Not everyone who calls out to me, ‘Lord! Lord!’ will enter the Kingdom of Heaven. Only those who actually do the will of my Father in heaven will enter. On judgment day many will say to me, ‘Lord! Lord! We prophesied in your name and cast out demons in your name and performed many miracles in your name.’ But I will reply, ‘I never knew you. Get away from me, you who break God’s laws.’
James 1:26-27, Matthew 7:21-23

User avatar
Zacherie
Spokesperson
 
Posts: 160
Founded: Apr 29, 2015
Iron Fist Consumerists

Postby Zacherie » Sun May 03, 2015 10:45 am

On the Telegram API: When the script breaks the API script limit, it doesn't give much useful information other than that you broke it.
I think in the style of the "queued" message, it'd be more helpful if it returned something along the lines of "@@Rate Limit Hit@@ by &&CLIENT&& wait @@X@@ seconds to send" to allow easy error checking.

EDIT
Zocra wrote:Is there a way to use the api to find range of rmb posts? Like if I wanted to search for posts from the first post ever to the 100th post or something...

http://www.nationstates.net/cgi-bin/api ... gion=(name)&q=messages;offset=OFFSET

grab offset 0
grab offset 10
grab offset 20
..
grab offset 90

EDIT 2:
using the nation happenings tag tends to not be incredibly useful. Extra parameters, like that on the world happenings, would add to the usability of the shard. At current, the happenings tag is only good if you want to try print the nation's happenings, however if you want to find a list of regions nations previously moved to, or who they've most recently endorsed, it is a chore at best. And offset or range tag on the happenings would be appreciate as well.
Last edited by Zacherie on Mon May 04, 2015 9:25 am, edited 4 times in total.
WELCOME TO THE JUNTA BABY~!
Frisbeeteria wrote:This is spam hackery.

I'm Vleerian

User avatar
Letoilenoir
Chargé d'Affaires
 
Posts: 424
Founded: Nov 26, 2010
Ex-Nation

Postby Letoilenoir » Mon May 25, 2015 1:58 am

Question: When using the shards this
Code: Select all
http://www.nationstates.net/cgi-bin/api.cgi?nation=letoilenoir&q=name

counts as one call to the API, correct?

Does this:
Code: Select all
http://www.nationstates.net/cgi-bin/api.cgi?nation=letoilenoir&q=name+wa

constitute two calls, or does it still qualify as 1?
KEEP THE BLOOD CAVE FREE

User avatar
Letoilenoir
Chargé d'Affaires
 
Posts: 424
Founded: Nov 26, 2010
Ex-Nation

Postby Letoilenoir » Mon May 25, 2015 2:35 am

Cerb wrote:I'm probably missing something obvious. I want to track current region of nation,WA status, endorsements, and wehther a nation is active (as in not CTE).

I figured I could just grab the nation daily data dump but it seems to be missing endorsements.
This means I'd have to make a ton of API calls to gather this information.

Even if I just restricted my interest to my region itt would take several hundred calls. I can't afford to do that with the current rate limits.

Ideally endorsements would be present in the daily data dump. I don't need the data to be dynamic, just gathered once a day.

If there is another obvious solution please feel free to suggest it.

Cheers!


Okay, this is the list of nations in you region via http://www.nationstates.net/cgi-bin/api ... numnations

REGION id="asia">
<NUMNATIONS>169</NUMNATIONS>
<NATIONS>
sebytania:lady_rose:qudrath:the_derrak_quadrant:etc,etc...........
</NATIONS>
</REGION>

This this is the list of all WA members pulled from the API:
<WA council="1">
<NUMNATIONS>22475</NUMNATIONS>
<MEMBERS>
--camila--,--neo-america--,--the_united_kingdom,-adipose_3,-aeros-,-arstotzka,-ebola-,-echolilia-,etc, etc............
</MEMBERS>
</WA>

Logically if you compare the two lists(populate 2 seperate arrays and use the a match function), any nation that is not on both is not in the WA.

As a result if you are tracking who is endorsing who then you only need to make calls on those that match, which shold reduce the number of calls made

Populate a third array with the nations that match and you're mostly there

You could then do something similar using the memberlog as suggested above

The first question is whether a php script can process this first task quick enough for your needs, assuming that you want to go the script route of course.
Last edited by Letoilenoir on Mon May 25, 2015 2:36 am, edited 1 time in total.
KEEP THE BLOOD CAVE FREE

User avatar
Ballotonia
Senior Admin
 
Posts: 5494
Founded: Antiquity
Liberal Democratic Socialists

Postby Ballotonia » Mon May 25, 2015 3:03 am

Letoilenoir wrote:Question: When using the shards this
Code: Select all
http://www.nationstates.net/cgi-bin/api.cgi?nation=letoilenoir&q=name

counts as one call to the API, correct?

Does this:
Code: Select all
http://www.nationstates.net/cgi-bin/api.cgi?nation=letoilenoir&q=name+wa

constitute two calls, or does it still qualify as 1?


Each http call qualifies as one call, regardless of how many + blah blah you tack onto it to get more information within that one call.

Ballotonia
"Een volk dat voor tirannen zwicht zal meer dan lijf en goed verliezen, dan dooft het licht…" -- H.M. van Randwijk

PreviousNext

Advertisement

Remove ads

Return to Technical

Who is online

Users browsing this forum: Bookment, Inferior, Knights of LUSITANIA, La Xinga, Meadrin, Micro Gettysburg, Montandi-Cisalpina, Pacfican States, Pauriun, Pygania, Sicias, The Micro Union, The Xolbarian Opposition

Advertisement

Remove ads