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
Eluvatar
Director of Technology
 
Posts: 3086
Founded: Mar 31, 2006
New York Times Democracy

Postby Eluvatar » Mon May 16, 2016 6:14 pm

Glen-Rhodes wrote:Got rate-blocked by the API (which was expected). The user-facing page for that has a small error:

Your IP address xxxx has sent more than 50 requests in 30 seconds. Access to the API has been blocked for the next 2343321006009 minutes. Please do not send bursts of traffic!


That would be about 4,458,373 years. :p


Are you going to do it again? :p
To Serve and Protect: UDL

Eluvatar - Taijitu member

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

Postby [violet] » Mon May 16, 2016 7:09 pm

Should be fixed now, thanks.

User avatar
Leppikania
Minister
 
Posts: 2332
Founded: Apr 13, 2015
Left-wing Utopia

Postby Leppikania » Thu May 19, 2016 3:33 pm

Can the poll shard be made to have a list of nations that voted in the poll?
INTP, -4.25 Economic Left/Right, -4.1 Social Libertarian/Authoritarian, tastes like chicken.
I do use NS stats, thank you very much.
Funny Quotes
Pie charts for industries
Request an Embassy

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

Postby [violet] » Thu May 19, 2016 4:55 pm

Sure! Added.

User avatar
HMS Unicorn
Spokesperson
 
Posts: 199
Founded: Jun 29, 2005
Ex-Nation

Postby HMS Unicorn » Tue May 24, 2016 1:23 pm

[violet] wrote:Added tgcanrecruit and tgcancampaign to the Nation API. These return 0 if the nation is currently blocking all Recruitment / Campaign telegrams, otherwise 1.

This allows API and manual recruiters to better target their messages.

Thanks a lot for this change, it has been incredibly helpful. The amount of telegrams sent by my new-nation API recruitment script that get blocked by category has fallen from about 20% to 5%.

I am curious where the other 5% comes from. I imagine it is nations that turn on the block after my script has queued a telegram to them, but before the telegram gets delivered.


Hoping that I'm not being too greedy, I was wondering whether it'd be possible to also add an API call that shows whether a recruitment telegram will be blocked because of "previous recruitment too recent".

This would help greatly reduce wasted telegrams for regions that combine more than one types of recruitment (any combination of stamps, API, and manual); or for regions that use the API to telegram nations from different but possibly overlapping lists of nations (e.g., newly founded nations, and nations that just joined the WA).

The API call could take the form of an optional argument to the existing TGCANRECRUIT call. For instance,

Code: Select all
http://www.nationstates.net/cgi-bin/api.cgi?nation=hms_unicorn&q=tgcanrecruit;fromregion=europeia

would return 0 if a recruitment for Europeia sent to HMS Unicorn would be blocked because of "previous recruitment too recent", and 1 otherwise. If the optional argument were skipped, the call would work same as now.
Last edited by HMS Unicorn on Tue May 24, 2016 1:25 pm, edited 2 times in total.

User avatar
Trotterdam
Postmaster-General
 
Posts: 10541
Founded: Jan 12, 2012
Left-Leaning College State

Postby Trotterdam » Tue May 24, 2016 3:36 pm

HMS Unicorn wrote:I am curious where the other 5% comes from. I imagine it is nations that turn on the block after my script has queued a telegram to them, but before the telegram gets delivered.
The nation could also be blocking "some"/"most" telegrams, rather than all, and has received a telegram in the same category from someone else recently enough for yours to get rejected.

User avatar
HMS Unicorn
Spokesperson
 
Posts: 199
Founded: Jun 29, 2005
Ex-Nation

Postby HMS Unicorn » Tue May 24, 2016 3:42 pm

Good point, I always forget about that intermediate option. That makes the 5% seem more reasonable

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

Postby [violet] » Tue May 24, 2016 8:29 pm

HMS Unicorn wrote:Hoping that I'm not being too greedy, I was wondering whether it'd be possible to also add an API call that shows whether a recruitment telegram will be blocked because of "previous recruitment too recent".

Sure thing! Added in testing, needs to wait on some other Telegram stuff before it can go live in production. But should work soonish, using the "from" parameter. You could start using that today, since it will just be ignored until it's supported.

Code: Select all
http://www.nationstates.net/cgi-bin/api.cgi?nation=hms_unicorn&q=tgcanrecruit;from=europeia

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

Postby Zacherie » Wed May 25, 2016 3:59 pm

[violet] wrote:Should be fixed now, thanks.

(A little late) Fixed it for me, thanks.
WELCOME TO THE JUNTA BABY~!
Frisbeeteria wrote:This is spam hackery.

I'm Vleerian

User avatar
TRUMPALUMPUS
Political Columnist
 
Posts: 2
Founded: Mar 02, 2016
Ex-Nation

Population API Export

Postby TRUMPALUMPUS » Wed May 25, 2016 7:36 pm

Hey guys, I've been making a website for our region between myself and a number of friends. I've been trying to find a way to import the population of each nation and refresh daily with population increase, but haven't found anything promising. Any idea on how I can?

User avatar
Floor 448
Envoy
 
Posts: 282
Founded: Mar 05, 2016
Ex-Nation

Postby Floor 448 » Wed May 25, 2016 7:42 pm

TRUMPALUMPUS wrote:Hey guys, I've been making a website for our region between myself and a number of friends. I've been trying to find a way to import the population of each nation and refresh daily with population increase, but haven't found anything promising. Any idea on how I can?

Do you have a programming language in mind? (Were you even going to make it yourself?) How many nations are in question?
Guess who I am! Or, rather, was.
Speak of the Devil, and he shall appear. He gets a notification that someone mentioned him.
When posting an image for me, please don't use Imgur.
Cumberlanda wrote:I, for one, am currently happy with our robot oppressors.

Gest II wrote:Somehow that was interpreted to mean: those foreign devils and their squiggly languages are incapable of learning Her Majesty's Tongue.
And now that I've gotten used to StackOverflow, I can't seem to wrap my head around not being able to edit posts with terrible spelling and/or grammar.

User avatar
Trotterdam
Postmaster-General
 
Posts: 10541
Founded: Jan 12, 2012
Left-Leaning College State

Postby Trotterdam » Thu May 26, 2016 12:10 am

TRUMPALUMPUS wrote:Hey guys, I've been making a website for our region between myself and a number of friends. I've been trying to find a way to import the population of each nation and refresh daily with population increase, but haven't found anything promising. Any idea on how I can?
If you need to process a large number of nations, you may need to download the daily data dumps and parse them for the information you're looking for.

If you only need to follow a smaller number of nations, it's easier to make several calls to http://www.nationstates.net/cgi-bin/api.cgi?q=population&nation=trumpalumpus (replacing the nation name each time).

User avatar
HMS Unicorn
Spokesperson
 
Posts: 199
Founded: Jun 29, 2005
Ex-Nation

Postby HMS Unicorn » Thu May 26, 2016 7:04 am

[violet] wrote:Sure thing! Added in testing, needs to wait on some other Telegram stuff before it can go live in production. But should work soonish, using the "from" parameter. You could start using that today, since it will just be ignored until it's supported.

Code: Select all
http://www.nationstates.net/cgi-bin/api.cgi?nation=hms_unicorn&q=tgcanrecruit;from=europeia

Excellent, thanks a lot for adding this so fast!

One question for clarification: Does the new code check for both telegrams being blocked in preferences and telegrams being blocked from "previous recruitment too recent"? Or would I need to do two separate API calls, one with and one without the "from" argument, to check for both of these conditions?

User avatar
Nexexen
Bureaucrat
 
Posts: 42
Founded: Dec 14, 2007
Conservative Democracy

Postby Nexexen » Thu May 26, 2016 7:18 am

One can get sensibilities from the API, but is there any way to get a shard for the tax descriptor as well--"flat", "average", "average, and even higher for the wealthy", "unheard of" etcetera? (Not sure if there are any other possibilities there...)

On a related note, would it be possible to get a shard for the government descriptors as well--"minute"/"tiny"/"relatively small"/"medium-sized"/"large"/etcetera, "outspoken", "community-minded", "socially-minded", "moralistic", "liberal", "corrupt", "pro-business", "well-organized", etcetera?

Thanks for any help on this.

User avatar
Greater Tern
Envoy
 
Posts: 331
Founded: Mar 04, 2010
Civil Rights Lovefest

Postby Greater Tern » Thu May 26, 2016 9:46 am

Nexexen wrote:One can get sensibilities from the API, but is there any way to get a shard for the tax descriptor as well--"flat", "average", "average, and even higher for the wealthy", "unheard of" etcetera? (Not sure if there are any other possibilities there...)

On a related note, would it be possible to get a shard for the government descriptors as well--"minute"/"tiny"/"relatively small"/"medium-sized"/"large"/etcetera, "outspoken", "community-minded", "socially-minded", "moralistic", "liberal", "corrupt", "pro-business", "well-organized", etcetera?

Thanks for any help on this.

I don't think the tax descriptors are available as a shard (good idea for a new one though!), but you can get the government descriptor from the govtdesc shard:

https://www.nationstates.net/cgi-bin/ap ... q=govtdesc

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

Postby [violet] » Thu May 26, 2016 6:52 pm

HMS Unicorn wrote:One question for clarification: Does the new code check for both telegrams being blocked in preferences and telegrams being blocked from "previous recruitment too recent"? Or would I need to do two separate API calls, one with and one without the "from" argument, to check for both of these conditions?

The "tgcanrecruit" shard always checks whether the nation is blocking Recruitment Telegrams. If you supply the optional parameter "from=<REGION>", it additionally checks whether messages from that region would be blocked under "Previous Recruitment Too Recent". (Or will, once it goes live.)

User avatar
TRUMPALUMPUS
Political Columnist
 
Posts: 2
Founded: Mar 02, 2016
Ex-Nation

Postby TRUMPALUMPUS » Thu May 26, 2016 7:47 pm

Floor 448 wrote:
TRUMPALUMPUS wrote:Hey guys, I've been making a website for our region between myself and a number of friends. I've been trying to find a way to import the population of each nation and refresh daily with population increase, but haven't found anything promising. Any idea on how I can?

Do you have a programming language in mind? (Were you even going to make it yourself?) How many nations are in question?

Honestly, I have no preference as to what language, and there's a steady population of 17 nations in our region.

User avatar
HMS Unicorn
Spokesperson
 
Posts: 199
Founded: Jun 29, 2005
Ex-Nation

Postby HMS Unicorn » Fri May 27, 2016 8:59 am

[violet] wrote:The "tgcanrecruit" shard always checks whether the nation is blocking Recruitment Telegrams. If you supply the optional parameter "from=<REGION>", it additionally checks whether messages from that region would be blocked under "Previous Recruitment Too Recent". (Or will, once it goes live.)

Thanks. That makes sense, as that way you can check whether your TG will be blocked, for any reason, with a single API call, rather than having to make two of them.

I've gone ahead and added this check to my scripts.

User avatar
Sandaoguo
Diplomat
 
Posts: 541
Founded: Apr 07, 2013
Left-Leaning College State

Postby Sandaoguo » Fri May 27, 2016 1:06 pm

I'm currently working on scraping influence data from The South Pacific (and potentially other regions). I'm using a token bucket algorithm to limit API calls, and this so far is working. (Though NS API's rate limiter is very sensitive, so I had to limit outgoing API calls to less than 50 per 30 seconds, because the algorithm was leading to 50 calls taking about a tenth of a second longer than 30 seconds, which led to a block. :( ) My question is: is it preferable on NS's end to make calls in bursts of 50, then wait so many seconds, or to space out individual calls every 1.x seconds like the algorithm currently does? To collect the influence data on all nations in TSP, I have to make several hundred calls.

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

Postby [violet] » Sun May 29, 2016 10:13 pm

Sandaoguo wrote:My question is: is it preferable on NS's end to make calls in bursts of 50, then wait so many seconds, or to space out individual calls every 1.x seconds like the algorithm currently does? To collect the influence data on all nations in TSP, I have to make several hundred calls.

Spaced out is better.

User avatar
HMS Unicorn
Spokesperson
 
Posts: 199
Founded: Jun 29, 2005
Ex-Nation

Postby HMS Unicorn » Thu Jun 09, 2016 9:08 pm

Would it be possible to add an API call that, given a telegram ID, returns its type (recruitment, campaign, none)?

I run a service that allows members of the region to submit a telegram ID, key, and list of nations; then sends copies of this telegram to these nations using the regional client key.

The page allows its users to specify whether the telegram is recruitment or not, and uses this to determine the rate at which the telegrams will be sent (1 every 30 or 180 seconds).

However, I have found that users often make mistakes, resulting either in the client being blocked for long periods of time, or in enormous amounts of wasted telegram bandwidth (unnecessarily setting recruitment for a 1000-nation telegram job...).

These issues would be resolved if there were an API call to determine the type of telegram automatically and set the rate limit accordingly.

Thanks in advance.

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

Postby [violet] » Wed Jun 15, 2016 7:08 pm

[violet] wrote:
HMS Unicorn wrote:Hoping that I'm not being too greedy, I was wondering whether it'd be possible to also add an API call that shows whether a recruitment telegram will be blocked because of "previous recruitment too recent".

Sure thing! Added in testing, needs to wait on some other Telegram stuff before it can go live in production. But should work soonish, using the "from" parameter. You could start using that today, since it will just be ignored until it's supported.

Code: Select all
http://www.nationstates.net/cgi-bin/api.cgi?nation=hms_unicorn&q=tgcanrecruit;from=europeia

Now implemented.

User avatar
HMS Unicorn
Spokesperson
 
Posts: 199
Founded: Jun 29, 2005
Ex-Nation

Postby HMS Unicorn » Wed Jun 15, 2016 10:14 pm

Thanks! Tested on my end, seems to work fine so far.

User avatar
Imperium Anglorum
GA Secretariat
 
Posts: 12655
Founded: Aug 26, 2013
Left-Leaning College State

Postby Imperium Anglorum » Thu Jun 16, 2016 10:05 pm

A few questions, I hope they aren't too much to ask.

Is there any way to get the BBCode that made the GA resolution? Or, if possible, at least preserve line breaks.

Would it be possible to trawl passed resolutions using the API? I maintain the Passed Resolutions thread. It would be much easier to get passed resolutions from the API than it is to copy and paste them into my parser as I do now, manually.

And finally, is there an established format in which the API information is saved? For example, if one calls the region API, you get nation names separated by colons instead of commas.
Last edited by Imperium Anglorum on Thu Jun 16, 2016 10:06 pm, edited 1 time in total.

Author: 1 SC and 56+ GA resolutions
Maintainer: GA Passed Resolutions
Developer: Communiqué and InfoEurope
GenSec (24 Dec 2021 –); posts not official unless so indicated
Delegate for Europe
Elsie Mortimer Wellesley
Ideological Bulwark 285, WALL delegate
Twice-commended toxic villainous globalist kittehs

User avatar
HMS Unicorn
Spokesperson
 
Posts: 199
Founded: Jun 29, 2005
Ex-Nation

Postby HMS Unicorn » Fri Jun 17, 2016 3:54 am

Imperium Anglorum wrote:Is there any way to get the BBCode that made the GA resolution? Or, if possible, at least preserve line breaks.

Would it be possible to trawl passed resolutions using the API? I maintain the Passed Resolutions thread. It would be much easier to get passed resolutions from the API than it is to copy and paste them into my parser as I do now, manually.

This old feature request is related to this.

PreviousNext

Advertisement

Remove ads

Return to Technical

Who is online

Users browsing this forum: Baiddsound, Blaat, Fengate, Norwegian Socialist Republic, Notricia, Reyo, Shirahime, Snorlaxia, The Endless Eventide

Advertisement

Remove ads