NATION

PASSWORD

List of Regional Delegates

Bug reports, general help, ideas for improvements, and questions about how things are meant to work.
User avatar
Galiantus
Diplomat
 
Posts: 730
Founded: Feb 24, 2012
Ex-Nation

List of Regional Delegates

Postby Galiantus » Thu Mar 29, 2012 7:03 pm

I wanted to take an analysis of all the regional delegates, but I couldn't find a place where they are all listed. I tried clicking where it says "1,232 Regional Delegates" on the world assembly page but that just brings up a list of all the regions, whether or not they have a delegate. Is there anywhere I can go for such a list?

I would like to suggest a change so that when you click the button on the world assembly page saying "1,232 Regional Delegates" the site pulls up a list of all the regional delegates (sorted by name, world census and population). It would also be nice if I could sort them by # of endorsements and length of service, but that is a lower priority.
Last objected by The World Assembly on Wednesday, August 1, 2012, objected 400 times in total.
Benjamin Franklin wrote:"Democracy is two wolves and a lamb deciding what to have for lunch."
Ballotonia wrote:Testing is for sissies. The actual test is to see how many people complain when any change is made ;)


On NationStates, We are the Good Guys:Aretist NatSovs

User avatar
Devoted Decons
Bureaucrat
 
Posts: 43
Founded: May 21, 2007
Democratic Socialists

Postby Devoted Decons » Thu Mar 29, 2012 7:23 pm

If you click http://www.nationstates.net/page=list_regions, you can sort it by size of region, name, and today's census. It lists the WA delegate.

EDIT: I see that is the same link you posted. You want the population of the delegate's nation?

Edit AGAIN: The API may help you compile a list.
Last edited by Devoted Decons on Thu Mar 29, 2012 7:28 pm, edited 3 times in total.

User avatar
Galiantus
Diplomat
 
Posts: 730
Founded: Feb 24, 2012
Ex-Nation

Postby Galiantus » Thu Mar 29, 2012 7:34 pm

Devoted Decons wrote: It lists the WA delegate.



I know, but 88% of the regions have no delegate, so only 12% of the listed regions have a name next to them. I want to be able to list that 12%, the way "1,232 Regional Delegates" implies.
Last objected by The World Assembly on Wednesday, August 1, 2012, objected 400 times in total.
Benjamin Franklin wrote:"Democracy is two wolves and a lamb deciding what to have for lunch."
Ballotonia wrote:Testing is for sissies. The actual test is to see how many people complain when any change is made ;)


On NationStates, We are the Good Guys:Aretist NatSovs

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

Postby Fischistan » Thu Mar 29, 2012 7:49 pm

The WA API can be used to find all of the delegates that vote on a particular resolution. You'll need at least a little tech skills to parse it though.
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
Scoochi2
Envoy
 
Posts: 207
Founded: Antiquity
Ex-Nation

Postby Scoochi2 » Fri Mar 30, 2012 8:15 am

The regional daily data dump can be used in the morning (when it is accurate due to no delegate changes until the afternoon) to see which regions have a delegate.
A simple script could easily print out a list of all regions that contain a delegate.

Assuming you've already downloaded the dump and unzipped it to the script's folder, the following PHP code will give you a link to each and every delegate, and show you their region and the number of nations it contains for reference.
Code: Select all
<?php
$dump = file_get_contents('regions.xml'); // get the dump and read as a string
$array = explode('<REGION>',$dump); // create an array with each value being a string of an entire region's info
array_shift($array); // to get rid of the first result which we don't need or want
foreach ($array as $value) // iterate through the array
  {
  $delegatestart = strpos($value,'<DELEGATE>')+10;  // where the name of the delegate can be found
  $delegateend = strpos($value,'</DELEGATE>');  // where the end of the name of the delegate can be found
  $delegatename = $regionname = substr($value,$delegatestart,$delegateend-$delegatestart); // the name of the delegate
  if ($delegatename != "0") // if there isn't a delegate, '0' is listed as delegate.
    {// There is no nation named 0 (and cannot be) so we don't need to check that.
    $namestart = strpos($value,'<NAME>')+6;  // where the name of the region can be found
    $nameend = strpos($value,'</NAME>');     // where the end of the name of the region can be found
    $regionname = substr($value,$namestart,$nameend-$namestart); // the name of the region
    $nationsstart = strpos($value,'<NUMNATIONS>')+12;  // where the number of nations can be found
    $nationsend = strpos($value,'</NUMNATIONS>');  // where the end of the number of nations can be found
    $numnations = substr($value,$nationsstart,$nationsend-$nationsstart); // the number of nations in the region
    /*
    we now know that the name of the delegate, and if it has one, we also know the name of the region
    as well as how many nations are in the region. So long as we stay in this conditional block of code, we can output information.
    If we wanted to sort the regions/delegates somehow, we would need to create an array outside the foreach loop
    and add the data before sorting and outputting it AFTER the loop.
    There are many other pieces of information we could find out as well, such as how many endorsements the delegate has.
    But you should be able to figure out how to do that based on this example alone ;)
    */
    echo "<a href='http://www.nationstates.net/nation=$delegatename'>$delegatename</a> of the region $regionname, which contains $numnations nations.<br>";
    }
  }
?>
The problem with a UDP joke is that you have no idea if people got it.

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

Postby Letoilenoir » Sat Mar 31, 2012 1:02 pm

Many thanks Scoochi2

http://redstarone.site40.net/garnnet.php

How would one go about formatting the output to present it in a style like this:

http://redstarone.site40.net/mandarin3.html
KEEP THE BLOOD CAVE FREE

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

Postby Fischistan » Sat Mar 31, 2012 3:51 pm

I modified Scoochi's code a little to put everything in a nice little table. I believe it would be something like what you want. Correct me if I am wrong though, as PHP is completely foreign to me.

Code: Select all
<?php
echo "<table border='1'>"; // starts the table
echo "<tr style='background:blue;'><td>Delegate Name</td><td>Region Name</td><td>Number of Nations</td></tr>"; // first row that has the top part
$dump = file_get_contents('regions.xml'); // get the dump and read as a string
$array = explode('<REGION>',$dump); // create an array with each value being a string of an entire region's info
array_shift($array); // to get rid of the first result which we don't need or want
foreach ($array as $value) // iterate through the array
  {
  $delegatestart = strpos($value,'<DELEGATE>')+10;  // where the name of the delegate can be found
  $delegateend = strpos($value,'</DELEGATE>');  // where the end of the name of the delegate can be found
  $delegatename = $regionname = substr($value,$delegatestart,$delegateend-$delegatestart); // the name of the delegate
  if ($delegatename != "0") // if there isn't a delegate, '0' is listed as delegate.
    {// There is no nation named 0 (and cannot be) so we don't need to check that.
    $namestart = strpos($value,'<NAME>')+6;  // where the name of the region can be found
    $nameend = strpos($value,'</NAME>');     // where the end of the name of the region can be found
    $regionname = substr($value,$namestart,$nameend-$namestart); // the name of the region
    $nationsstart = strpos($value,'<NUMNATIONS>')+12;  // where the number of nations can be found
    $nationsend = strpos($value,'</NUMNATIONS>');  // where the end of the number of nations can be found
    $numnations = substr($value,$nationsstart,$nationsend-$nationsstart); // the number of nations in the region
    /*
    we now know that the name of the delegate, and if it has one, we also know the name of the region
    as well as how many nations are in the region. So long as we stay in this conditional block of code, we can output information.
    If we wanted to sort the regions/delegates somehow, we would need to create an array outside the foreach loop
    and add the data before sorting and outputting it AFTER the loop.
    There are many other pieces of information we could find out as well, such as how many endorsements the delegate has.
    But you should be able to figure out how to do that based on this example alone ;)
    */

    echo "<tr><td><a href='http://www.nationstates.net/nation=$delegatename'>$delegatename</a></td><td>$regionname</td> <td>$numnations</td>";
    }
  }
echo "</table>;" // ends the table
?>
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
Scoochi2
Envoy
 
Posts: 207
Founded: Antiquity
Ex-Nation

Postby Scoochi2 » Sat Mar 31, 2012 3:55 pm

Letoilenoir wrote:How would one go about formatting the output to present it in a style like this:

http://redstarone.site40.net/mandarin3.html

My example pretty much already does. I said in it that you should be able to figure out how to get the number of endorsements.
The only other difference is the layout. It's basic HTML, you should be able to do a simple table.
Normally at this point I'd walk off, but because it literally takes 30 seconds to do, here's the code you want. It does look different for 2 reasons: I haven't styled it. You might want to add a style sheet to make it look how you want it, or leave it as it is. The other reason is because the page you linked to lists regions without delegates (rather unstylishly by listing the delegate as '0' :p ) If you comment out the only line that has an if statement, my example code will also list them (I recommend replacing that 0 with an empty string though, or 'there is no delegate').
Also, for oneupmanship my code also provides a direct link to both the region and the delegate.
Code: Select all
<HTML><HEAD></HEAD><BODY>
<table><tr><th>Region<th>Delegate<th>Endorsements<th>Population
<?php
// I removed the comments from this one. See other example for those :p
$dump = file_get_contents('regions.xml');
$array = explode('<REGION>',$dump);
array_shift($array);
foreach ($array as $value)
  {
  $delegatestart = strpos($value,'<DELEGATE>')+10;
  $delegateend = strpos($value,'</DELEGATE>');
  $delegatename = $regionname = substr($value,$delegatestart,$delegateend-$delegatestart);
  if ($delegatename != "0")
    {
    $namestart = strpos($value,'<NAME>')+6;
    $nameend = strpos($value,'</NAME>');
    $regionname = substr($value,$namestart,$nameend-$namestart);
    $nationsstart = strpos($value,'<NUMNATIONS>')+12;
    $nationsend = strpos($value,'</NUMNATIONS>');
    $numnations = substr($value,$nationsstart,$nationsend-$nationsstart);
    $endosstart = strpos($value,'<DELEGATEVOTES>')+15;
    $endosend = strpos($value,'</DELEGATEVOTES>');
    $endos = substr($value,$endosstart,$endosend-$endosstart);
 
    echo "<tr><td><a href='http://www.nationstates.net/region=$regionname'>$regionname</a>";
    echo "<td><a href='http://www.nationstates.net/nation=$delegatename'>$delegatename</a>";
    echo "<td>$endos<td>$numnations";
    }
  }
?></table></BODY></HTML>

EDIT: bah, ninja'd. Both codes work. I recommend mine though: it's blank for you to create your own custom styling (or copy from Ficsh's modification), includes a delegate link and also shows endorsements.
Last edited by Scoochi2 on Sat Mar 31, 2012 3:59 pm, edited 1 time in total.
The problem with a UDP joke is that you have no idea if people got it.

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

Postby Letoilenoir » Sun Apr 01, 2012 1:32 am

Many thanks to both of you - if this forum had a karma option I would be sending you the maximum quota allowed!

I gave away all me shares as soon as I got them, but I'll see if I can pull in some favours to get you some, if if it is just a token
KEEP THE BLOOD CAVE FREE

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

Postby Letoilenoir » Mon Oct 01, 2012 12:33 pm

Sorry to re-visit this but would anyone know how to output the data from this:

http://moruna.comoj.com/delegate7.html

Into a csv, excel or similar?

Basically rather than just producing a listing, I would like to be able to extract the values for use elsewhere

Is it just a case of adjusting the echo to print to a cell?
KEEP THE BLOOD CAVE FREE

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

Postby Ballotonia » Mon Oct 01, 2012 12:57 pm

Letoilenoir wrote:Sorry to re-visit this but would anyone know how to output the data from this:

http://moruna.comoj.com/delegate7.html

Into a csv, excel or similar?

Basically rather than just producing a listing, I would like to be able to extract the values for use elsewhere

Is it just a case of adjusting the echo to print to a cell?


Displaying that page in a browser (in my case, Firefox), I managed to simply do a CTRL-A (select all) then CTRL-C (copy) and within Excel CTRL-V (paste). The data ends up nicely formatted.

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

User avatar
Riemstagrad
Ambassador
 
Posts: 1089
Founded: Antiquity
Left-Leaning College State

Postby Riemstagrad » Mon Oct 01, 2012 12:59 pm

just did a quick test and apparently i could just select it, copy and paste it in to a LibreOffice spreadsheet, where everything ended up in the 4 columns just as the original.

OpenOffice will probably give the same result. don't know what others will do with it, but you can give it a try...


EDIT: ballotonia was faster. so Excel works and LibreOffice works :)

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

Postby Letoilenoir » Mon Oct 01, 2012 1:39 pm

Cool, saves me having to wade through this
KEEP THE BLOOD CAVE FREE

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

Postby Letoilenoir » Tue Mar 26, 2013 1:10 pm

Again keeping it all in one place, would the <EMBASSIES> tag have to be "exploded" before the list of embassies could be extracted?

Or should I be talking to New Texas?
Last edited by Letoilenoir on Tue Mar 26, 2013 1:10 pm, edited 1 time in total.
KEEP THE BLOOD CAVE FREE

User avatar
NewTexas
Spokesperson
 
Posts: 181
Founded: Antiquity
Civil Rights Lovefest

Postby NewTexas » Wed Mar 27, 2013 5:06 pm

You are just all over the place Letoilenoir! :unsure:

Our NSStatistics tool has a section called "The World" where, if you select "View All Regions", does everything you are asking for (including sorting them by Delegate Endorsements). Plus, there is a handy-dandy "Export to Excel" button so you can take the data home with you and crunch it however you want.

Hope that helps.

:geek:
Big Tex
Governor of Texas

Author: NSDossier

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

Postby Letoilenoir » Sat Aug 02, 2014 4:25 am

No this is not a gravedig but a development of the original

From the above it is clear that the data is downloaded to my local from:
http://www.nationstates.net/pages/regions.xml.gz

uploaded to the hosting site, then the php is applied to produce

http://moruna.comoj.com/delegate01.html

However this is reliant on me physically downloading from the API then loading the new file to the host

The question I wish to pose is this : is there away of automating those two steps, effectively replacing the xml file with the latest (major) update -

Could a perl script, similar to Ballo's auto login, dowload the gz file, extract it.upload it to the server, all wrapped up on a CRON scheduled to actoivate just after update?

Or is there an easier way? Bear in mind that we are not looking at any script that dials in directly to the API as I would imagine that would take a hell of a long time to execute, but utilises the available daily data?!

PS BT - your "World" facility seems to be out of sync - you have Kyzikos showing 17406 at the when its actually 15137!
Last edited by Letoilenoir on Sat Aug 02, 2014 4:36 am, edited 3 times in total.
KEEP THE BLOOD CAVE FREE

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

Postby The Blaatschapen » Sat Aug 02, 2014 4:51 am

A shell script would be your best bet I think?

Something akin to

Code: Select all
#!/bin/bash
cd /directory/where/you/want/to/download
wget http://www.nationstates.net/pages/regions.xml.gz
tar -xzvf regions.xml.gz


And probably something more. I'm currently on a Windows machine so I can't test my bash script (and too lazy to ssh into my server to test :ugeek: )

Edit: And then put said script into your crontab (crontab -e). Look on the internet how to set up a cronjob that way.

Second Edit: I'm assuming your server has bash, tar and wget. And generally runs something Linux-y (or BSD :))
Last edited by The Blaatschapen on Sat Aug 02, 2014 5:00 am, edited 2 times in total.
The Blaatschapen should resign


Advertisement

Remove ads

Return to Technical

Who is online

Users browsing this forum: Antasca, Fotisdia, Hyponichtmallieturam, Tepertopia, Three Galaxies, Union of Zuid Afrika

Advertisement

Remove ads