Advertisement
by 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?
<?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
?>
<?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
?>
by Ballotonia » Sat Jan 28, 2012 5:31 am
by Glen-Rhodes » Sat Jan 28, 2012 2:44 pm
by [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?
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.
Glen-Rhodes wrote:There are no new-line markers in the resolution text.
by [violet] » Sat Jan 28, 2012 3:31 pm
Ballotonia wrote:Can we please get the BBCode markups in the Daily Data Dump?
by 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'.
<DELLOG>
<ENTRY>
<TIMESTAMP>1327467682</TIMESTAMP>
<NATION>euphysius</NATION>
<ACTION>FOR</ACTION>
<VOTES>3</VOTES>
</ENTRY>
</DELLOG>
by [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?
by [violet] » Sat Jan 28, 2012 4:21 pm
by Glen-Rhodes » Sat Jan 28, 2012 6:19 pm
by [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.
by Glen-Rhodes » Sat Jan 28, 2012 8:04 pm
by Coffee and Crack » Sat Feb 04, 2012 10:41 am
by Coffee and Crack » Sun Feb 05, 2012 9:13 pm
by Improving Wordiness » Mon Feb 06, 2012 5:59 am
Klaus Devestatorie wrote:I'm a massive tool. ;)
by Glen-Rhodes » Mon Feb 06, 2012 2:44 pm
by Coffee and Crack » Mon Feb 06, 2012 4:58 pm
by Glen-Rhodes » Mon Feb 06, 2012 6:12 pm
by Shizensky » Wed Mar 21, 2012 1:43 pm
by Fischistan » Wed Mar 21, 2012 1:58 pm
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.
by [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?
Fischistan wrote:And also, is there any reason that all the nodes are in CAPS?
by 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=tagsFischistan wrote:And also, is there any reason that all the nodes are in CAPS?
Nope. They just are.
by 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
by 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
Advertisement
Users browsing this forum: Domais, Google [Bot], Pashkan, Tekniania
Advertisement