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
[violet]
Executive Director
 
Posts: 16205
Founded: Antiquity

Postby [violet] » Fri Jan 27, 2012 8:48 pm

I'm not seeing any errors in the logs. What's the URL of the page that generates that error?
Last edited by [violet] on Fri Jan 27, 2012 8:48 pm, edited 1 time in total.

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

Postby [violet] » Fri Jan 27, 2012 9:05 pm

I just noticed that none of the code examples on the prev. page set the UserAgent. If possible, could the authors add this?

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

Postby Glen-Rhodes » Fri Jan 27, 2012 10:33 pm

[violet] wrote:I just noticed that none of the code examples on the prev. page set the UserAgent. If possible, could the authors add this?

The easiest way to do this in PHP is to use ini_set('user_agent', 'custom user agent'), but not all users will have access to that. The only other way is to use cURL, which is slightly more bulky than simple fetching. Here's that:

Code: Select all
<?php
   $file = 'http://www.nationstates.net/cgi-bin/api.cgi?nation=testlandia';
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $file);
   curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); //$user_agent would contain your agent.
   $fetched_xml = curl_exec($ch); //xml stored in the variable $fetched_xml
   curl_close($ch);

   $xml = simplexml_load_string($fetched_xml);
   
   // 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
?>

Code: Select all
<?php
   function get_data($nation, $shards = FALSE) {
      if($shards != FALSE) {
         $file = 'http://www.nationstates.net/cgi-bin/api.cgi?nation=' . $nation . '&q=' . $shards;
      }
      else {
         $file = 'http://www.nationstates.net/cgi-bin/api.cgi?nation=' . $nation;
      }
     
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $file);
      curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); //$user_agent would contain your agent.
      $fetched_xml = curl_exec($ch); //xml stored in the variable $fetched_xml
      curl_close($ch);

      $xml = simplexml_load_string($fetched_xml);
      return $xml;
   }
   
   function display_pop_civilrights($nation) {
      $data = get_data($nation, 'name+population+freedomscores');
     
      $name = (string) $data->NAME;
      $population = (string) $data->POPULATION;
      $civil_rights = (string) $data->FREEDOMSCORES->CIVILRIGHTS;

      echo '<p><b>' . $name . '</b><br />Population: ' . $population . '<br />Civil Rights: ' . $civil_rights . '</p>';
   }
   
   display_pop_civilrights('testlandia');
   display_pop_civilrights('glen-rhodes');
   
   
   // Outputs:
   //   (bold) Testlandia
   //     Population: 18245
   //     Civil Rights: 74
   //   (bold) Glen-Rhodes
   //     Population: 7738
   //     Civil Rights: 77
?>


If you can't use ini_set() or don't have cURL, I don't know how else you can set your user agent.

(P.s. I'll get around to setting all of my scripts' user-agents tomorrow!)

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

Postby Ballotonia » Sat Jan 28, 2012 5:31 am

I've noticed that in the regional shard "messages" the RMB messages are given including the BBCode tags. In the regional Daily Data Dump, the WFE's are inside a CDATA tag without BBCode markups.

Can we please get the BBCode markups in the Daily Data Dump? Would make restoring prior WFE's much easier.

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

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

Postby Glen-Rhodes » Sat Jan 28, 2012 2:44 pm

Some questions about the World Assembly API.

  • According to my count, there are only 579 delegates voting on the current GA resolution. Does the numdelegates shard represent the number of delegates voting in the World Assembly as a whole, even though the 'council' attribute is in the XML?
  • There are no new-line markers in the resolution text. Would it be possible to add those?

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

Postby [violet] » Sat Jan 28, 2012 3:27 pm

Glen-Rhodes wrote:Does the numdelegates shard represent the number of delegates voting in the World Assembly as a whole, even though the 'council' attribute is in the XML?

Correct. There's a note to this effect in the API doc:
API Documentation wrote:In the case of shards that return data for the overall World Assembly (e.g. numnations), it doesn't matter which ID you use: either ID will return the same result.

The only WA shards that specifically refer to the current at-vote resolution at the moment are 'resolution' and 'dellog'.
Glen-Rhodes wrote:There are no new-line markers in the resolution text.

There are, actually, but you may not realize this if you're viewing it in Firefox's XML viewer or similar.

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

Postby [violet] » Sat Jan 28, 2012 3:31 pm

Ballotonia wrote:Can we please get the BBCode markups in the Daily Data Dump?

These were stripped out in 2004 due to problems with bad BBCode corrupting the XML format... but I think we can work around that by simply encoding square brackets.

Edit: done.
Last edited by [violet] on Sat Jan 28, 2012 3:40 pm, edited 1 time in total.

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

Postby Glen-Rhodes » Sat Jan 28, 2012 3:37 pm

[violet] wrote:The only WA shards that specifically refer to the current at-vote resolution at the moment are 'resolution' and 'dellog'.

I thought so. I can get the number specific to the council using the dellog shard. But might I trouble you to change the formatting? Something like this:
Code: Select all
<DELLOG>
   <ENTRY>
      <TIMESTAMP>1327467682</TIMESTAMP>
      <NATION>euphysius</NATION>
      <ACTION>FOR</ACTION>
      <VOTES>3</VOTES>
   </ENTRY>
</DELLOG>


That way, it's easier to associate each timestamp, action and vote with their respective nations. Doesn't have to be that way. I'm just looking for a format that groups all that information together.

[violet] wrote:
Glen-Rhodes wrote:There are no new-line markers in the resolution text.

There are, actually, but you may not realize this if you're viewing it in Firefox's XML viewer or similar.

Yup, that would be it. I can definitely see the new lines when I view the XML source.

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

Postby [violet] » Sat Jan 28, 2012 3:41 pm

Glen-Rhodes wrote:I can get the number specific to the council using the dellog shard. But might I trouble you to change the formatting?

Oh! Sorry, I didn't notice they were all mooshed together like that. Will fix.

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

Postby [violet] » Sat Jan 28, 2012 4:21 pm

<DELLOG> is now formatted correctly.

Also, you no longer get the <VOTE_TRACK_*> data unless you specifically request it with the 'votetrack' shard.

Also, you can now fetch data on delegate votes with the 'delvotes' shard. This includes timestamp data, i.e. exactly when each Delegate voted, which I hope you will find handy. We've only just begun recording that, though, so the older timestamps are wrong (either "1" or a number similar to their # of votes).

Updated the API doc to reflect this.

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

Postby Glen-Rhodes » Sat Jan 28, 2012 6:19 pm

Thanks for that! For the dellog shard, is it displaying the delegates' vote value at the time of voting, or is it displaying whatever it is at the moment?

I'm trying to figure out the best way to count delegate voting power. It looks like delvotes might be the better shard, since it doesn't display a record of actions*, but that doesn't include the delegate's voting position.

* The dellog shard is awkward to use for this, since you have to exclude withdrawn votes, and compare the number of votes, if indeed it only shows the number of votes at the time of voting. (You'd do that, in case they got more votes in subsequent 'actions'.)
Last edited by Glen-Rhodes on Sat Jan 28, 2012 6:20 pm, edited 1 time in total.

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

Postby [violet] » Sat Jan 28, 2012 6:53 pm

Glen-Rhodes wrote:I'm trying to figure out the best way to count delegate voting power. It looks like delvotes might be the better shard, since it doesn't display a record of actions*, but that doesn't include the delegate's voting position.

Well, it does; some of them are listed under <DELVOTES_FOR> and others under <DELVOTES_AGAINST>. I did consider doing it the other way, with the whole lot under <DELVOTES> and each individual delegate having <VOTE>FOR</VOTE> or <VOTE>AGAINST</VOTE>, and still could if that makes more sense.

I would not expect you to use 'dellog' to calculate voting power.

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

Postby Glen-Rhodes » Sat Jan 28, 2012 8:04 pm

Hm. I must have not noticed that they were separated like that. This makes things much easier!

Thanks for doing all of this so quickly, by the way. :)

User avatar
Coffee and Crack
Bureaucrat
 
Posts: 59
Founded: Aug 17, 2008
Ex-Nation

Postby Coffee and Crack » Sat Feb 04, 2012 10:41 am

Quick thing with the regional happenings API..

Would it be possible for CTE to have <TEXT>@@paradalis@@ ceased to exist.</TEXT> instead of <TEXT>The Republic of Paradalis ceased to exist.</TEXT>

Right now I have to parse against the last index of "of" which isn't the most reliable way to go about it.

User avatar
Coffee and Crack
Bureaucrat
 
Posts: 59
Founded: Aug 17, 2008
Ex-Nation

Postby Coffee and Crack » Sun Feb 05, 2012 9:13 pm

Also with the happenings API, I was able to put together a quick chart detailing recruitment performance (founded nations moving to a new location, puppets included.. started tracking February 5th, 2pmish EST). I've been able to mine a nice treasure trove of data to continue with my earlier plans.

http://regioninc.com/metrics/created.php

Just another thanks for making the API available.

User avatar
Improving Wordiness
Diplomat
 
Posts: 641
Founded: Dec 05, 2009
Ex-Nation

Postby Improving Wordiness » Mon Feb 06, 2012 5:59 am

10K ranks as highest for the moment. We do not use automated script to recruit and I wonder if that is a reflection of that or if it is simply too soon to tell.
My guess is that in another six months those numbers may be quite difference. I expect a more even spread.
Klaus Devestatorie wrote:I'm a massive tool. ;)

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

Postby Glen-Rhodes » Mon Feb 06, 2012 2:44 pm

If that script is just checking for entrances, then it's using a flawed metric for recruitment. I imagine 10KI's defender army routinely leaves and enters the region, for example. (That's been my experience with defending, at least.) Can't tell you certainly, as C&C doesn't have the source code up.

If I were to evaluate the performance of recruitment for my region, I would keep track of who is sent a message and when they enter the region. The API can be used for that second one. Then at regular intervals, I would conduct a survey using a randomly selected group from those nations, asking them if how heavily the message affected their migration.

User avatar
Coffee and Crack
Bureaucrat
 
Posts: 59
Founded: Aug 17, 2008
Ex-Nation

Postby Coffee and Crack » Mon Feb 06, 2012 4:58 pm

Semi-flawed. There's no way to check for puppets, but I only track nations that I have flagged as being founded and where they go after leaving the pacifics. Nations that have already been created, enter and leave are not tracked.

As for tracking people that have been sent a message, that doesn't apply into a global sense. I have other internal metrics to handle arrived/recruited/departed nations for the region that I need to put into an actionable format (needs to quit job for moar NS).

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

Postby Glen-Rhodes » Mon Feb 06, 2012 6:12 pm

Tracking recruitment would be difficult if you're trying to create a global index yourself, yeah. But it would probably be much more accurate, and even more accurate if surveys are conducted. Not impossible, but certainly not automatic. :[

User avatar
Shizensky
Diplomat
 
Posts: 602
Founded: Mar 29, 2004
New York Times Democracy

Postby Shizensky » Wed Mar 21, 2012 1:43 pm

This is gravedigging a little, but I was wondering how hard it would be to add a <TAGS></TAGS> shard to the API? It could be fun to organize regions by type, like Silly, Defender, Invader, etc.

Thanks for your time.
"Look, that's why there's rules, understand?
So that you think before you break 'em."
My favorite thing about UDP jokes
is I don't care if you get them or not.

User avatar
Fischistan
Ambassador
 
Posts: 1384
Founded: Oct 16, 2011
Ex-Nation

Postby Fischistan » Wed Mar 21, 2012 1:58 pm

And also, is there any reason that all the nodes are in CAPS?
Xavier D'Montagne
Fischistani Ambassador to the WA
Unibot II wrote:It's Carta. He CANNOT Fail. Only successes in reverse.
The Matthew Islands wrote:Knowledge is knowing the Tomato is a fruit. Wisdom is knowing not to put it in a fruit salad.
Anthony Delasanta wrote:its was not genocide it was ethnic cleansing...
Socorra wrote:A religion-free abortion thread is like a meat-free hamburger.
Help is on its Way: UDL
Never forget 11 September.
Never look off the edge of cliff on a segway.

11 September 1973, of course.

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

Postby [violet] » Wed Mar 21, 2012 6:24 pm

Shizensky wrote:This is gravedigging a little, but I was wondering how hard it would be to add a <TAGS></TAGS> shard to the API?

Not hard at all!

http://www.nationstates.net/cgi-bin/api ... lms&q=tags

Fischistan wrote:And also, is there any reason that all the nodes are in CAPS?

Nope. They just are.

User avatar
Zemnaya Svoboda
Diplomat
 
Posts: 867
Founded: Jan 06, 2004
Civil Rights Lovefest

Postby Zemnaya Svoboda » Wed Mar 21, 2012 6:40 pm

[violet] wrote:
Shizensky wrote:This is gravedigging a little, but I was wondering how hard it would be to add a <TAGS></TAGS> shard to the API?

Not hard at all!

http://www.nationstates.net/cgi-bin/api ... lms&q=tags

Fischistan wrote:And also, is there any reason that all the nodes are in CAPS?

Nope. They just are.


THANK YOU THANK YOU THANK YOU. :bow:

User avatar
Shizensky
Diplomat
 
Posts: 602
Founded: Mar 29, 2004
New York Times Democracy

Postby Shizensky » Wed Mar 21, 2012 7:51 pm

[violet] wrote:
Shizensky wrote:This is gravedigging a little, but I was wondering how hard it would be to add a <TAGS></TAGS> shard to the API?

Not hard at all!

http://www.nationstates.net/cgi-bin/api ... lms&q=tags



Thank you! :)
"Look, that's why there's rules, understand?
So that you think before you break 'em."
My favorite thing about UDP jokes
is I don't care if you get them or not.

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

Postby The Blaatschapen » Wed Mar 21, 2012 8:32 pm

[violet] wrote:
Shizensky wrote:This is gravedigging a little, but I was wondering how hard it would be to add a <TAGS></TAGS> shard to the API?

Not hard at all!

http://www.nationstates.net/cgi-bin/api ... lms&q=tags


Is it also possible to have it the other way around? Ie. An API that shows which regions have @@TAG@@ ?

Either way, I see now a possibility to do some multiple tag searches on a daily db dump(it is/will be included in the dump right?) to do some multiple TAG searches (eg. combining Democratic and Founderless). *goes off to sleep and sees some nice coding ahead* :)
Last edited by The Blaatschapen on Wed Mar 21, 2012 8:33 pm, edited 1 time in total.
The Blaatschapen should resign

PreviousNext

Advertisement

Remove ads

Return to Technical

Who is online

Users browsing this forum: Addy and Arielle, All are Equal, Bali Kingdom, Boreale, Celinova, Doughworld, IC-Water, Inferior, Ioudaia, Kirkas, Lumaterra, Montrandec, Radicalania, The Brosketeers, The Controlist Ferwerter Union

Advertisement

Remove ads