by Galiantus » Thu Mar 29, 2012 7:03 pm
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 ;)
by Devoted Decons » Thu Mar 29, 2012 7:23 pm
by Galiantus » Thu Mar 29, 2012 7:34 pm
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 ;)
by Fischistan » Thu Mar 29, 2012 7:49 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 Scoochi2 » Fri Mar 30, 2012 8:15 am
<?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>";
}
}
?>
by Letoilenoir » Sat Mar 31, 2012 1:02 pm
by Fischistan » Sat Mar 31, 2012 3:51 pm
<?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.
by 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
<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>
by Letoilenoir » Sun Apr 01, 2012 1:32 am
by Letoilenoir » Mon Oct 01, 2012 12:33 pm
by 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?
by Riemstagrad » Mon Oct 01, 2012 12:59 pm
by Letoilenoir » Mon Oct 01, 2012 1:39 pm
by Letoilenoir » Tue Mar 26, 2013 1:10 pm
by NewTexas » Wed Mar 27, 2013 5:06 pm
by Letoilenoir » Sat Aug 02, 2014 4:25 am
by The Blaatschapen » Sat Aug 02, 2014 4:51 am
#!/bin/bash
cd /directory/where/you/want/to/download
wget http://www.nationstates.net/pages/regions.xml.gz
tar -xzvf regions.xml.gz
Advertisement
Users browsing this forum: Antasca, Fotisdia, Hyponichtmallieturam, Tepertopia, Three Galaxies, Union of Zuid Afrika
Advertisement