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
Flanderlion
Minister
 
Posts: 2228
Founded: Nov 25, 2013
Psychotic Dictatorship

Postby Flanderlion » Sat Apr 29, 2023 3:08 am

https://www.nationstates.net/cgi-bin/ap ... 6;start=20 and just iterate through. Would be much nicer if they added at least the daily census in the daily dumps so there would be a much easier way of collecting the bulk data rather than a million requests. Re the actual coding, it's kind of more of something for you to figure out, API gives you a way to access the data, but it's for the user to put it together and edit it in their desired way. For non-technical users there is the existing site.

Also - https://www.nationstates.net/pages/api.html#terms - you need to set a userAgent when using the API (or you can just use your browser manually) and if you scrape there are significantly more stringent criteria - viewtopic.php?p=16394966#p16394966

I've got a feeling most of the sheets/excel things were illegal because they don't set a userAgent, but they might've added the ability to set those in the intervening years between the script rules changes/Elite being illegal and 2023.
As always, I'm representing myself.
Information
Wishlist

User avatar
Klaus Devestatorie
Minister
 
Posts: 2938
Founded: Aug 28, 2008
Capitalizt

Postby Klaus Devestatorie » Sat Apr 29, 2023 3:59 am

Fetching data via =IMPORTXML on google sheets has thus far not refused me access to any data I have requested, but after some fiddling around to try and see what my user agent actually is, I have determined that google sheets is only sending a non specific message indicating google sheets use for a user agent. Is there a way to specify a user agent directly in the API URL?

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

Postby Trotterdam » Sat Apr 29, 2023 4:30 am

Klaus Devestatorie wrote:I'm not trying to make 500 API calls, though. I'm just trying to make one API call that has all the data I want, with no intention of making this call more than once a day.
You can't. You'll have to either put in the work to process multiple API calls, or give up on your goals.

Klaus Devestatorie wrote:There doesn't appear to be an option to let me select any group of 20 nations other than the 20 highest rated nations for that census, so I can't request by region in successive calls.
You can: https://www.nationstates.net/cgi-bin/api.cgi?region=ordo_imperialia&q=censusranks;scale=1;start=21.

However, this is somewhat risky. If the ordering changed between API calls (such as from a nation answering an issue just as you're fetching the data, or from a nation entering or leaving the region), then you could get a particular nation listed twice, while another nation might get skipped over entirely. Doing it the way I suggested at least guarantees that you get data from approximately the same time on every nation in the region, even if it might not all be from exactly the same time.

User avatar
Klaus Devestatorie
Minister
 
Posts: 2938
Founded: Aug 28, 2008
Capitalizt

Postby Klaus Devestatorie » Sat Apr 29, 2023 5:27 am

Trotterdam wrote:
Klaus Devestatorie wrote:I'm not trying to make 500 API calls, though. I'm just trying to make one API call that has all the data I want, with no intention of making this call more than once a day.
You can't. You'll have to either put in the work to process multiple API calls, or give up on your goals.

Klaus Devestatorie wrote:There doesn't appear to be an option to let me select any group of 20 nations other than the 20 highest rated nations for that census, so I can't request by region in successive calls.
You can: https://www.nationstates.net/cgi-bin/api.cgi?region=ordo_imperialia&q=censusranks;scale=1;start=21.

However, this is somewhat risky. If the ordering changed between API calls (such as from a nation answering an issue just as you're fetching the data, or from a nation entering or leaving the region), then you could get a particular nation listed twice, while another nation might get skipped over entirely. Doing it the way I suggested at least guarantees that you get data from approximately the same time on every nation in the region, even if it might not all be from exactly the same time.

I reckon I've found a way to handle API calls at a decent clip via some manual spreadsheet data work, and I can resolve the nation movement mid-request issue by only bothering with specific nations of interest instead of trying to handle every nation in a region no matter what- but the user agent issue has me on hold for now. Hopefully there's either a way to either directly declare a user identifier in the API url, or that this would be added in the future- my research has confirmed that there's no function in google sheets for a user agent. I'm fiddling with the excel data import wizard instead in case this has the ability to set a user agent- is it possible to set this via the advanced power query editor, per this example?

Code: Select all
let
    Source = Csv.Document(Web.Contents("https://www.nationstates.net/cgi-bin/api.cgi?a=useragent", [Headers=[UserAgent="nation=Klaus Devestatorie"]]),[Delimiter=",", Columns=1, Encoding=1252]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}})
in
    #"Changed Type"
Last edited by Klaus Devestatorie on Sat Apr 29, 2023 6:22 am, edited 1 time in total.

User avatar
Bowzin
Envoy
 
Posts: 301
Founded: Aug 13, 2018
Libertarian Police State

Postby Bowzin » Sat Apr 29, 2023 2:25 pm

Klaus Devestatorie wrote:-snip-

Try User-Agent for the header key, instead of UserAgent.
Bowzin Vytherov-Skollvaldr
| On a Redemption Arc. |
We dropped a new resume dispatch!

User avatar
Klaus Devestatorie
Minister
 
Posts: 2938
Founded: Aug 28, 2008
Capitalizt

Postby Klaus Devestatorie » Sat Apr 29, 2023 8:19 pm

Bowzin wrote:
Klaus Devestatorie wrote:-snip-

Try User-Agent for the header key, instead of UserAgent.

Champion! Thank you, I'm in business :)

User avatar
Hesskin Empire
Attaché
 
Posts: 98
Founded: Jan 30, 2016
Democratic Socialists

Postby Hesskin Empire » Sat May 13, 2023 11:35 am

So I was messing about with some code and realized that the new WA nations shard has a comma (,) as a delimiter while the residents (NATION) shard has a colon (:) as a delimiter... was this on purpose to differentiate between shards in some way? I know it caused me some time debugging before realizing lmao.

(Note: I haven't checked other shards so I don't know if they tend to share delimiters or have unique ones)
Ghazia-Rahman Ammarah bint Rigel al-Asteorra
She/Her/Hers || Proud Queer Muslim
Trans rights are human rights.
||||||||||||||||||||
Queen of Tannborn and Kronenberg, Duchess of Ansrau, Helmfurt, and Fürstenzell, Margrave of Osterhausen and Delmenfingen, and Lady of Hügelstat and Kaiserin-Emeritus of Hartfelden
Her Grace the Duchess of Eprom, Marquis of Kammara, Earl of Upper Strathia, and Lady Mayor of Zelva of Sildoria
Taskmaster of the Brotherhood of Malice
Countess Sylvoria, Baroness Tybradia and Lady Marshal of Kantrias
Enforcer of Alcatraz
The Rt. Hon. Earl of Leinster, Viscountess of Dublin, Baroness of Greenwich, First Sea Lady (Ret.) in the Empire of Great Britain

User avatar
Bowzin
Envoy
 
Posts: 301
Founded: Aug 13, 2018
Libertarian Police State

Postby Bowzin » Sat May 13, 2023 12:26 pm

Hesskin Empire wrote:So I was messing about with some code and realized that the new WA nations shard has a comma (,) as a delimiter while the residents (NATION) shard has a colon (:) as a delimiter... was this on purpose to differentiate between shards in some way? I know it caused me some time debugging before realizing lmao.

(Note: I haven't checked other shards so I don't know if they tend to share delimiters or have unique ones)

Delegates are , delimited as welll
Bowzin Vytherov-Skollvaldr
| On a Redemption Arc. |
We dropped a new resume dispatch!

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

Postby Eluvatar » Sat May 13, 2023 9:31 pm

Hesskin Empire wrote:So I was messing about with some code and realized that the new WA nations shard has a comma (,) as a delimiter while the residents (NATION) shard has a colon (:) as a delimiter... was this on purpose to differentiate between shards in some way? I know it caused me some time debugging before realizing lmao.

(Note: I haven't checked other shards so I don't know if they tend to share delimiters or have unique ones)

It was intended to be consistent with the newer shards and with what is more common in the wider world of data.
To Serve and Protect: UDL

Eluvatar - Taijitu member

User avatar
Hesskin Empire
Attaché
 
Posts: 98
Founded: Jan 30, 2016
Democratic Socialists

Postby Hesskin Empire » Sun May 14, 2023 7:54 am

Eluvatar wrote:
Hesskin Empire wrote:So I was messing about with some code and realized that the new WA nations shard has a comma (,) as a delimiter while the residents (NATION) shard has a colon (:) as a delimiter... was this on purpose to differentiate between shards in some way? I know it caused me some time debugging before realizing lmao.

(Note: I haven't checked other shards so I don't know if they tend to share delimiters or have unique ones)

It was intended to be consistent with the newer shards and with what is more common in the wider world of data.

So will we see the delimiters changed on the shards to be consistent at some point? I don't know much on setting up APIs themselves so I have no idea how difficult that process would be.
Ghazia-Rahman Ammarah bint Rigel al-Asteorra
She/Her/Hers || Proud Queer Muslim
Trans rights are human rights.
||||||||||||||||||||
Queen of Tannborn and Kronenberg, Duchess of Ansrau, Helmfurt, and Fürstenzell, Margrave of Osterhausen and Delmenfingen, and Lady of Hügelstat and Kaiserin-Emeritus of Hartfelden
Her Grace the Duchess of Eprom, Marquis of Kammara, Earl of Upper Strathia, and Lady Mayor of Zelva of Sildoria
Taskmaster of the Brotherhood of Malice
Countess Sylvoria, Baroness Tybradia and Lady Marshal of Kantrias
Enforcer of Alcatraz
The Rt. Hon. Earl of Leinster, Viscountess of Dublin, Baroness of Greenwich, First Sea Lady (Ret.) in the Empire of Great Britain

User avatar
Roavin
Admin
 
Posts: 1778
Founded: Apr 07, 2016
Democratic Socialists

Postby Roavin » Sun May 14, 2023 12:06 pm

No, because we don't want to break existing scripts. But going forward, we're going to stick to commas for new stuff.
Helpful Resources: One Stop Rules Shop | API documentation | NS Coders Discord
About me: Longest serving Prime Minister in TSP | Former First Warden of TGW | aka Curious Observations

Feel free to TG me, but not about moderation matters.

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

Postby Sandaoguo » Mon May 15, 2023 7:08 pm

Would it be possible to add a "Founded In" stat to the nation API, recording the region in which the nation was founded? Ideally within the default set of shards delivered by the base parameter.
Last edited by Sandaoguo on Mon May 15, 2023 7:11 pm, edited 1 time in total.

User avatar
Bowzin
Envoy
 
Posts: 301
Founded: Aug 13, 2018
Libertarian Police State

Postby Bowzin » Mon May 15, 2023 7:30 pm

Sandaoguo wrote:Would it be possible to add a "Founded In" stat to the nation API, recording the region in which the nation was founded? Ideally within the default set of shards delivered by the base parameter.

Seems like its marked as "in development"
Bowzin Vytherov-Skollvaldr
| On a Redemption Arc. |
We dropped a new resume dispatch!

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

Postby Trotterdam » Tue May 16, 2023 12:03 am

Why would we track that? I don't want a region that I stayed in for 1.5 seconds before moving out to be a permanent mark on my record.

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

Postby Sandaoguo » Tue May 16, 2023 6:12 am

Trotterdam wrote:Why would we track that? I don't want a region that I stayed in for 1.5 seconds before moving out to be a permanent mark on my record.

It’s an API call, not your government record… But anyways, it’s a data point worth collecting to monitor the impact of Frontiers and the new flow of newly founded nations around the game.

User avatar
Roavin
Admin
 
Posts: 1778
Founded: Apr 07, 2016
Democratic Socialists

Postby Roavin » Wed May 17, 2023 1:27 am

Not documented (yet), but check this out: api.cgi?q=newnationdetails
Helpful Resources: One Stop Rules Shop | API documentation | NS Coders Discord
About me: Longest serving Prime Minister in TSP | Former First Warden of TGW | aka Curious Observations

Feel free to TG me, but not about moderation matters.

User avatar
Darcania
Envoy
 
Posts: 205
Founded: Dec 29, 2014
Civil Rights Lovefest

Postby Darcania » Wed May 17, 2023 9:38 am

Roavin wrote:Not documented (yet), but check this out: api.cgi?q=newnationdetails

Thank you!

User avatar
Darcania
Envoy
 
Posts: 205
Founded: Dec 29, 2014
Civil Rights Lovefest

Postby Darcania » Wed May 17, 2023 4:03 pm

Apologies for the second post in a row, but is there a chance we could get a governortitle shard or something of the like? I notice some regions have custom names for their office of Governor but I can't find that info in the API.

User avatar
Merni
Ambassador
 
Posts: 1800
Founded: May 03, 2016
Democratic Socialists

Postby Merni » Thu May 18, 2023 11:18 am

The "governor" shard for regions doesn't seem to be documented.
2024: the year of democracy. Vote!
The Labyrinth | Donate your free time, help make free ebooks | Admins: Please let us block WACC TGs!
RIP Residency 3.5.16-18.11.21, killed by simplistic calculation
Political Compass: Economic -9.5 (Left) / Social -3.85 (Liberal)
Wrote issue 1523, GA resolutions 532 and 659
meth
When the people are being beaten with a stick, they are not much happier if it is called 'the People’s Stick.' — Mikhail Bakunin (to Karl Marx)
You're supposed to be employing the arts of diplomacy, not the ruddy great thumping sledgehammers of diplomacy. — Ardchoille
The West won the world not by the superiority of its ideas or values or religion [...] but rather by its superiority in applying organised violence. — Samuel P. Huntington (even he said that!)

User avatar
Udenstar
Civilian
 
Posts: 1
Founded: Apr 14, 2023
Left-wing Utopia

Activity Log via API

Postby Udenstar » Thu May 18, 2023 8:35 pm

I would like to have a record of my activity from when my nation was created to current. On the activities page, it seems to only show the past 6 or 7 days (possibly a specific number of events?) with no option to go back further. Instead of cluttering up that page, could it be possible to get more log entries via the API?

Data from Issues seem to be found on those individual issues. What isn't included is how World Assembly changes impact the nation or record of nation moves, gaining/losing endorsements, etc.

If these data points are kept in the NationStates database, why can't they be available to the player?

User avatar
United Calanworie
Technical Moderator
 
Posts: 3839
Founded: Dec 12, 2018
Democratic Socialists

Postby United Calanworie » Thu May 18, 2023 11:13 pm

Udenstar wrote:I would like to have a record of my activity from when my nation was created to current. On the activities page, it seems to only show the past 6 or 7 days (possibly a specific number of events?) with no option to go back further. Instead of cluttering up that page, could it be possible to get more log entries via the API?

Data from Issues seem to be found on those individual issues. What isn't included is how World Assembly changes impact the nation or record of nation moves, gaining/losing endorsements, etc.

If these data points are kept in the NationStates database, why can't they be available to the player?

We purge happenings logs after... I want to say seven days? If you wish to keep information about your nation, you need to poll the happenings API at a relatively constant rate, probably once per day, in order to retrieve all that information. The data structure is as follows:
Code: Select all
<NATION id="testlandia">
<HAPPENINGS>
<EVENT>
<TIMESTAMP>1683674301</TIMESTAMP>
<TEXT>
Following new legislation in @@testlandia@@, real power lies not in the debating room but with those who decide what is debated.
</TEXT>
</EVENT>
</HAPPENINGS>
</NATION>
Trans rights are human rights.
||||||||||||||||||||
Discord: Aav#7546 @queerlyfe
She/Her/Hers
My telegrams are not for Moderation enquiries, those belong in a GHR. Feel free to reach out if you want to just chat.

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

Postby Eluvatar » Thu Jun 01, 2023 7:00 am

Udenstar wrote:If these data points are kept in the NationStates database, why can't they be available to the player?

Happenings are not (currently) kept in the database, but in something custom. If we were to put them in the database, with an eye to longer term retention, we'd need to write a lot of code for converting between the text of the happenings and a more compressed record for storage.
To Serve and Protect: UDL

Eluvatar - Taijitu member

User avatar
Lemmingtopias
Diplomat
 
Posts: 607
Founded: Apr 03, 2007
Left-Leaning College State

Postby Lemmingtopias » Fri Jun 09, 2023 5:23 am

Does NS keep a log of the amount of unique issues answered, or options answered?

And if so, is that something that could be added as a shard alongside the current answered shard?
Last edited by Lemmingtopias on Fri Jun 09, 2023 5:24 am, edited 2 times in total.
LBC News:Lemmingtopias now de facto split between East and West | Junta forces fail to storm Palace of the Sages, withdrawal from West Lomapolis | COUP! Advised to stay at home! More Info coming soon | Prince of Lemmingtopias killed during summit with Tropican President| Invasion of The Tropican Islands cancelled. Diplomatic talks to resume

User avatar
Roavin
Admin
 
Posts: 1778
Founded: Apr 07, 2016
Democratic Socialists

Postby Roavin » Fri Jun 09, 2023 6:40 pm

Lemmingtopias wrote:Does NS keep a log of the amount of unique issues answered, or options answered?

And if so, is that something that could be added as a shard alongside the current answered shard?


Do you mean something like "issue 123 was answered 123321 times"?
Helpful Resources: One Stop Rules Shop | API documentation | NS Coders Discord
About me: Longest serving Prime Minister in TSP | Former First Warden of TGW | aka Curious Observations

Feel free to TG me, but not about moderation matters.

User avatar
Lemmingtopias
Diplomat
 
Posts: 607
Founded: Apr 03, 2007
Left-Leaning College State

Postby Lemmingtopias » Sat Jun 10, 2023 2:21 am

Roavin wrote:
Lemmingtopias wrote:Does NS keep a log of the amount of unique issues answered, or options answered?

And if so, is that something that could be added as a shard alongside the current answered shard?


Do you mean something like "issue 123 was answered 123321 times"?


No. I mean something like, Testlandia has answered 123 unique issues.
LBC News:Lemmingtopias now de facto split between East and West | Junta forces fail to storm Palace of the Sages, withdrawal from West Lomapolis | COUP! Advised to stay at home! More Info coming soon | Prince of Lemmingtopias killed during summit with Tropican President| Invasion of The Tropican Islands cancelled. Diplomatic talks to resume

PreviousNext

Advertisement

Remove ads

Return to Technical

Who is online

Users browsing this forum: Mechanocracy, Telnuhq

Advertisement

Remove ads