NATION

PASSWORD

Update Time Tool - A PHP Script for region update times

Bug reports, general help, ideas for improvements, and questions about how things are meant to work.
User avatar
Lordieth
Post Czar
 
Posts: 31603
Founded: Jun 18, 2010
New York Times Democracy

Update Time Tool - A PHP Script for region update times

Postby Lordieth » Fri Jul 03, 2015 12:59 pm

This is a script I've been working on in PHP, in response to this thread.

As work is continuing on the script, it seemed appropriate to move it to its own thread. The latest version of the script can be obtained below.

Code: Select all
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>

<?php
//======================================================================
// Update Time Tool 1.1 - Written by Lordieth
//======================================================================
//
//I take no responsibility for the use (or misuse) of this script. Use at your own risk.

ini_set("user_agent","Nation update time checker, ran by [nation] - see https://forum.nationstates.net/viewtopic.php?f=15&t=345458");
//set your timezone here to get the correct returned update times
date_default_timezone_set("Europe/London");
//here we'll store any errors
$errors = array();

//this is where we'll store the results, if any
$results = array();
if(isset($_POST['submit'])){
    //print_r($_POST['nation']);
    if(empty($_POST['nation'][0])){
        $errors[] = "Nation 1 has not been entered";
    }
    if(empty($_POST['nation'][1])){
        $errors[] = "Nation 2 has not been entered";
    }
    if(empty($_POST['nation'][2])){
        $errors[] = "Nation 3 has not been entered";
    }
    if(empty($_POST['nation'][3])){
        $errors[] = "Nation 4 has not been entered";
    }
    if(empty($errors)){
       
        //no errors, now we can run.
        $i = 0;
        $j = 0;
        $events = array();
        $array = array();
        foreach($_POST['nation'] as $nation){
           
            //replace spaces with underscores to make nation name url-friendly
            $nation = str_replace(" ", "_", trim($nation));
           
            //stores the xml contents in $page, if the nation exists
            $page = @file_get_contents("http://www.nationstates.net/cgi-bin/api.cgi?nation=".trim($nation)."&q=happenings+region");
            //var_dump($http_response_header);
           
            //check response from file_get_contents that the nation exists
            if(strpos($http_response_header[0], "HTTP/1.1 404 Not Found") === false){
                $xml = simplexml_load_string($page);
                $json = json_encode($xml);
                $array = json_decode($json,TRUE);
               
                //delay timer. Comment out or set to 0 if you want the script to run faster
                sleep(5);
            }
            else{
                $errors[] = "API has returned a 'HTTP/1.1 404 Not Found' response for ".$nation." <br>";
                $array = array(); // empty the array
            }
           
            //echo "<pre>";
            //print_r($array);
            //echo "</pre>";
            //die();
            if($array){
               $events = $array['HAPPENINGS']['EVENT'];
               $events['REGION'] = $array['REGION'];
               
                //echo "<pre>";
                //print_r($events);
                //echo "</pre>";
                //die();
            }
            else{
                $errors[] = $nation. " could not be found.<br>";
            }
           
            //print_r($events);
            //die();
            if($events){ // if any events have been found
                $region = $events['REGION']; //store the region this nation belongs to
                foreach($events as $event){
               
                    //echo "<pre>";
                    //print_r($event);
                    //echo "</pre>";
                //echo $event['TEXT']."<br>";
                    // store the shards for the nations in an array that have a "Following new legislation..." string in the XML
                    // We break out of the loop on the first legislation it finds for that nation
                    if(@strpos($event['TEXT'], "Following new legislation") !== false){
                       
                        $results[$i]['REGION'] = "<a href='http://www.nationstates.net/region=".$region."' target='_blank'>$region</a>";
                        $results[$i]['TEXT'] = preg_replace("/@@(\S+)@@/", "<a href='http://www.nationstates.net/nation=$1' target='_blank'>$1</a>", $event['TEXT']);
                        $results[$i]['TIMESTAMP'] = $event['TIMESTAMP'];

                        $i++;
                        break;
                    }
                }
               
            }
           
           
        }
    }
       
}
        if($errors){
            foreach($errors as $error){
            echo $error."<br>";
            }
            echo "<br>";
        }
       
        ?>
         <form action="index.php" method="post">
        Nation 1: <input type="text" name="nation[]"><br>
        Nation 2: <input type="text" name="nation[]"><br>
        Nation 3: <input type="text" name="nation[]"><br>
        Nation 4: <input type="text" name="nation[]"><br>
        <input type="submit" name ="submit" value="Submit">
        </form>
        <?php
        if($results){
            //echo "<pre>";
            //print_r($results);
            //echo "</pre>";
           
            //sorts the $results array by date
            usort($results, 'date_compare');
           
            //echo "<pre>";
            //print_r($results);
            //echo "</pre>";
            //die();
           
            //loops through $results away and prints out return nation data
            foreach($results as $result){
                echo $result['REGION']."<br>";
                echo date("D M j G:i:s", $result['TIMESTAMP'])."<br>";
                echo $result['TEXT']."<br>";

            }
            echo "<br><br>";
        }
        ?>
    </body>
</html>
<?php

// function to sort dates from earliest to latest
function date_compare($a, $b)
{
    return $a['TIMESTAMP'] < $b['TIMESTAMP'];
}   


?>
Last edited by Lordieth on Fri Jul 03, 2015 1:07 pm, edited 1 time in total.
There was a signature here. It's gone now.

User avatar
Lordieth
Post Czar
 
Posts: 31603
Founded: Jun 18, 2010
New York Times Democracy

Postby Lordieth » Fri Jul 03, 2015 1:04 pm

Letoilenoir wrote:Could the timezone be a user input via a dropdown box:

Code: Select all
<?php
 
function get_timezones()
{
    $o = array();
     
    $t_zones = timezone_identifiers_list();
     
    foreach($t_zones as $a)
    {
        $t = '';
         
        try
        {
            //this throws exception for 'US/Pacific-New'
            $zone = new DateTimeZone($a);
             
            $seconds = $zone->getOffset( new DateTime("now" , $zone) );
            $hours = sprintf( "%+02d" , intval($seconds/3600));
            $minutes = sprintf( "%02d" , ($seconds%3600)/60 );
     
            $t = $a ."  [ $hours:$minutes ]" ;
             
            $o[$a] = $t;
        }
         
        //exceptions must be catched, else a blank page
        catch(Exception $e)
        {
            //die("Exception : " . $e->getMessage() . '<br />');
            //what to do in catch ? , nothing just relax
        }
    }
     
    ksort($o);
     
    return $o;
}
 
$o = get_timezones();
?>
 
<html>
<body>
<select name="time_zone">
<?php
    foreach($o as $tz => $label)
    {
        echo "<option value="$tz">$label</option>";
    }
?>
</select>
</body>
</html>


source: http://www.binarytides.com/dropdown-list-timezones-php/


That would be rather useful. I'll look into it.

I've updated the script to pull in region names, and both regions/nations now display as hyperlinks for convenience. I've also bolstered the error checking to check the API for 404 errors when it can't find a nation.
There was a signature here. It's gone now.

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

Postby Letoilenoir » Fri Jul 03, 2015 1:20 pm

Input:
Nation 1: Letoilenoir
Nation 2:Letoilenoire
Nation 3: Lordieth
Nation 4: Lordeith


API has returned a 'HTTP/1.1 404 Not Found' response for Letoilenoire

Letoilenoire could not be found.

API has returned a 'HTTP/1.1 404 Not Found' response for Lordeith

Lordeith could not be found.


Nation 1:
Nation 2:
Nation 3:
Nation 4:

The Blood Cave
Sun Mar 1 5:54:59
Following new legislation in letoilenoir, foreign 'investors' have been taking a great interest in the new secret shuttle.
The Blood Cave
Sun Mar 1 5:54:59
Following new legislation in letoilenoir, foreign 'investors' have been taking a great interest in the new secret shuttle.
The Blood Cave
Sun Mar 1 5:54:59
Following new legislation in letoilenoir, foreign 'investors' have been taking a great interest in the new secret shuttle.
KEEP THE BLOOD CAVE FREE

User avatar
Lordieth
Post Czar
 
Posts: 31603
Founded: Jun 18, 2010
New York Times Democracy

Postby Lordieth » Fri Jul 03, 2015 1:27 pm

Letoilenoir wrote:Input:
Nation 1: Letoilenoir
Nation 2:Letoilenoire
Nation 3: Lordieth
Nation 4: Lordeith


API has returned a 'HTTP/1.1 404 Not Found' response for Letoilenoire

Letoilenoire could not be found.

API has returned a 'HTTP/1.1 404 Not Found' response for Lordeith

Lordeith could not be found.


Nation 1:
Nation 2:
Nation 3:
Nation 4:

The Blood Cave
Sun Mar 1 5:54:59
Following new legislation in letoilenoir, foreign 'investors' have been taking a great interest in the new secret shuttle.
The Blood Cave
Sun Mar 1 5:54:59
Following new legislation in letoilenoir, foreign 'investors' have been taking a great interest in the new secret shuttle.
The Blood Cave
Sun Mar 1 5:54:59
Following new legislation in letoilenoir, foreign 'investors' have been taking a great interest in the new secret shuttle.


Looking much better now! :)

Although, it should really only be displaying your legislation once. I'll fix that for the next update.
Last edited by Lordieth on Fri Jul 03, 2015 1:28 pm, edited 1 time in total.
There was a signature here. It's gone now.

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

Postby Letoilenoir » Fri Jul 03, 2015 2:02 pm

Just a thought

If this is widely adopted then the site I am using for testing would be quickly overloaded, obviously with my user agent nation being pointed to as the culpable party

However could the user agent be set via a user input field?

I am also thinking that the form should be a stand alone document, separated from the results to allow a more logical flow
Last edited by Letoilenoir on Fri Jul 03, 2015 2:48 pm, edited 1 time in total.
KEEP THE BLOOD CAVE FREE

User avatar
Lordieth
Post Czar
 
Posts: 31603
Founded: Jun 18, 2010
New York Times Democracy

Postby Lordieth » Fri Jul 03, 2015 3:02 pm

Letoilenoir wrote:Just a thought

If this is widely adopted then the site I am using for testing would be quickly overloaded, obviously with my user agent nation being pointed to as the culpable party

However could the user agent be set via a user input field?


I believe the API limit is against the target I.P, and as it's a server-side script, If you host it, then yeah, without putting in restrictions, your I.P could get locked out.

I think the user agent could be changed that way, but it wouldn't get around the API limit. If I were hosting it, I'd either implement a queue-based approach for script calls during high traffic, or move the API calls front-end using JavaScript, which would then move the API calls onto the local user's machine.

A queue would be more robust, but it would need a database to track API calls.

I"d be interested in hearing any other solutions, though.

Letoilenoir wrote:I am also thinking that the form should be a stand alone document, separated from the results to allow a more logical flow


Yes, it would be cleaner, and it's normally something I do when a stand-alone script reaches a certain size, so I probably will do that.

If the interest is there for this, I could go one step further and put it into an MVC framework, but if I go down that road I might decide to host the system myself.
Last edited by Lordieth on Fri Jul 03, 2015 3:11 pm, edited 2 times in total.
There was a signature here. It's gone now.

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

Postby Letoilenoir » Fri Jul 03, 2015 3:40 pm

Lordieth wrote: If I were hosting it, I'd either implement a queue-based approach for script calls during high traffic, or move the API calls front-end using JavaScript, which would then move the API calls onto the local user's machine.

A queue would be more robust, but it would need a database to track API calls.


Would MySQL fit the bill? - I have toyed with an implementation but have not yet had a project that would warrant investing the time to investigate it properly .

Lordieth wrote: If the interest is there for this, I could go one step further and put it into an MVC framework, but if I go down that road I might decide to host the system myself.


Now you have completely lost me!

But............if you do go this route a blog/tutorial documenting the process might provide a valuable resources for myself and others that find themselves slipping further down the rabbit hole! I know i might be being a bit forward, but if you don't ask questions how will you ever learn anything?
KEEP THE BLOOD CAVE FREE

User avatar
King Nephmir II
Chargé d'Affaires
 
Posts: 400
Founded: Jun 04, 2015
Benevolent Dictatorship

Postby King Nephmir II » Fri Jul 03, 2015 4:51 pm

Not to blow down this tool, but the activity page does this already (I believe it was implemented a few months ago)... and in less steps. Just click the timestamp "x hours ago" on the desired world, region, or nation activity page and it returns the exact date and time of all recent events.

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

Postby Letoilenoir » Fri Jul 03, 2015 5:27 pm

King Nephmir II wrote:Not to blow down this tool, but the activity page does this already (I believe it was implemented a few months ago)... and in less steps. Just click the timestamp "x hours ago" on the desired world, region, or nation activity page and it returns the exact date and time of all recent events.


So it does

I guess you could put the "tracker" nations into a dossier, but given the number of puppets/allies/enemies that one tracks you would then have to filter out the "background" noise to zoom in on the times you are actually interested in:
7/3/2015, 1:41:27 PM: King Nephmir II created a new poll in Auralia: "Regional Chat Interest".
7/3/2015, 1:27:09 PM: King Nephmir II updated the World Factbook entry in Auralia.
7/3/2015, 4:01:32 AM: King Nephmir II updated the World Factbook entry in Auralia.
7/3/2015, 4:01:17 AM: King Nephmir II updated the World Factbook entry in Auralia.
7/2/2015, 5:02:23 PM: Following new legislation in Minoa, almost all of Minoa's water is piped into the country from abroad for exorbitant prices.
7/2/2015, 5:02:23 PM: Following new legislation in Minoa, surrealist houses shaped like mushrooms and volcanoes dominate the wealthiest neighborhoods.
7/2/2015, 1:50:58 PM: Minoa created a custom banner.
7/2/2015, 1:43:20 PM: Minoa created a custom banner.
7/2/2015, 1:37:07 PM: Minoa created a custom banner.
7/2/2015, 5:02:41 AM: Minoa was reclassified from "Left-wing Utopia" to "Civil Rights Lovefest".
7/2/2015, 5:02:41 AM: Following new legislation in Minoa, corporations donate huge sums of money to favored politicians.
7/2/2015, 2:40:47 AM: King Nephmir II lodged a message on the Auralia Regional Message Board.
7/2/2015, 2:39:47 AM: King Nephmir II updated the World Factbook entry in Auralia.
7/2/2015, 1:23:50 AM: King Nephmir II lodged a message on the Auralia Regional Message Board.
7/1/2015, 6:55:58 PM: King Nephmir II lodged a message on the Auralia Regional Message Board.
7/1/2015, 1:47:37 PM: King Nephmir II updated the World Factbook entry in Auralia.
7/1/2015, 1:46:17 PM: King Nephmir II updated the World Factbook entry in Auralia.
7/1/2015, 5:25:58 AM: Following new legislation in King Nephmir II, the nation has welcomed its expats back with open arms.
7/1/2015, 4:42:26 AM: King Nephmir II lodged a message on the Auralia Regional Message Board.
7/1/2015, 1:20:46 AM: King Nephmir II lodged a message on the Auralia Regional Message Board.
6/30/2015, 2:18:31 PM: King Nephmir II lodged a message on the Auralia Regional Message Board.
6/30/2015, 2:17:59 PM: King Nephmir II published "Auralian Map #1: Archipelago" (Meta: Gameplay).


After further investigation, using the "law" filter gets us the relevant data:
7/2/2015, 5:02:23 PM: Following new legislation in Minoa, almost all of Minoa's water is piped into the country from abroad for exorbitant prices.
7/2/2015, 5:02:23 PM: Following new legislation in Minoa, surrealist houses shaped like mushrooms and volcanoes dominate the wealthiest neighborhoods.
7/2/2015, 5:02:41 AM: Following new legislation in Minoa, corporations donate huge sums of money to favored politicians.
7/1/2015, 5:25:58 AM: Following new legislation in King Nephmir II, the nation has welcomed its expats back with open arms.
6/30/2015, 5:26:02 AM: Following new legislation in King Nephmir II, the nation is currently revamping its entire education system.
6/30/2015, 5:26:02 AM: Following new legislation in King Nephmir II, thousands of former welfare recipients are in a revolutionary uproar as the rest of society is enjoying a hefty tax break.
6/30/2015, 5:26:02 AM: Following new legislation in King Nephmir II, fur coats have become the latest fashion trend.
6/28/2015, 5:21:55 PM: Following new legislation in King Nephmir II, corporations cut costs by taking away safety-features on their products.
6/28/2015, 5:27:38 AM: Following new legislation in King Nephmir II, education and welfare spending are on the rise.
6/28/2015, 5:27:38 AM: Following new legislation in King Nephmir II, a typical fast food menu item could serve a small army.
6/28/2015, 5:27:38 AM: Following new legislation in King Nephmir II, the military invades any neighboring nation with the gall to criticize its policies.
6/28/2015, 5:27:38 AM: Following new legislation in King Nephmir II, tightly packed choir-boys sing the god-given joys of heterosexuality on public transport.


In fact maybe that could be the basis for a tutorial - the more accessible we make GP the more participants we get, and the more fun that can be had

Maybe this"tool" is the "space pen" versus the "pencil", however just having this correspondence with Lordieth has expanded my understanding of PHP, as well as you highlighting some of the existing functionality of NS itself

There was a couple of enhancements I was going to look into though, one being whether, once the timestamps for the subject nations had been obtained, php could be used to calculate the difference between the trigger and the target.

After all, local time zone is a bit of a red herring, we only need to know how many minutes/seconds after update starts our trigger(s) update and corresponding differential between these and our target update.

There is also the possibility of rather than having just a link to the region, an action could be embedded to jump to that region at a click, moving your logged in nation there instantaneously - assuming of course this didn't violate any protocols ;)
Last edited by Letoilenoir on Fri Jul 03, 2015 6:05 pm, edited 6 times in total.
KEEP THE BLOOD CAVE FREE

User avatar
Lordieth
Post Czar
 
Posts: 31603
Founded: Jun 18, 2010
New York Times Democracy

Postby Lordieth » Sat Jul 04, 2015 2:03 am

Ah, well, there's no point in re-inventing the wheel, but I wrote this for the fun of building it more than anything else.

So, if this functionality already exists more-or-less, could the script perhaps be used as a basis for a more enhanced system? Instead of looking at it that it takes more steps to use the script than the dossier, look at it as a basis for something that could be improved over the dossier and become a far more useful tool.

For example;

- automated telegrams triggered by updates
- tracking average update time shifts by region (it's a pity the happenings shard isn't a part of the nation daily dump, or this could be turned into a fully-fledged system)

The list goes on. I'm happy to keep working on it, if there's any functionality that would enhance the functionality of the tool far beyond what is currently possible. I'm a relatively advanced PHP programmer, so feel free to throw ideas out there. I don't play the RD side of NationStates, so I don't know what sort of functionality there is a need or use for.
Last edited by Lordieth on Sat Jul 04, 2015 2:06 am, edited 2 times in total.
There was a signature here. It's gone now.

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

Postby Letoilenoir » Sat Jul 04, 2015 7:56 am

Although the functionality exists the available methods of accessing fall short of ideal.

Developing this project to provide a tactical dashboard would be the ultimate goal imho

Providing update times, differential timings between regions, the relative Influence scores of a regions inhabitants (which could suggest which nations could be engaged as involuntary point men to initiate regime change)

As mentioned above, enhancing the project to include buttons to deploy to a region,( and possibly switch puppet?) could help novices to participate.
KEEP THE BLOOD CAVE FREE

User avatar
Lordieth
Post Czar
 
Posts: 31603
Founded: Jun 18, 2010
New York Times Democracy

Postby Lordieth » Sat Jul 04, 2015 9:08 am

Letoilenoir wrote:Although the functionality exists the available methods of accessing fall short of ideal.

Developing this project to provide a tactical dashboard would be the ultimate goal imho

Providing update times, differential timings between regions, the relative Influence scores of a regions inhabitants (which could suggest which nations could be engaged as involuntary point men to initiate regime change)

As mentioned above, enhancing the project to include buttons to deploy to a region,( and possibly switch puppet?) could help novices to participate.


Such features would need to be discussed more in-depth, not only sure ensure they're practical and feasible, but that they're allowable within the game rules. But, these are all things I'm happy to explore, and the more feedback from people with the need of better RD tools, the more able I'll be to see if I can provide them.
Last edited by Lordieth on Sat Jul 04, 2015 9:09 am, edited 1 time in total.
There was a signature here. It's gone now.

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

Postby Letoilenoir » Sat Jul 04, 2015 11:18 am

:)
Last edited by Letoilenoir on Sat Jul 04, 2015 11:53 am, edited 1 time in total.
KEEP THE BLOOD CAVE FREE

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

Postby Letoilenoir » Sat Jul 04, 2015 11:26 am

Mock up
Image

IF I am interpreting the script rules correctly having a clickable button to switch regions is permissible as is a button to resign the nation you are currently logged into from the WA


The additional features I would envisage are:

  1. Drop down list to set the users timezone to allow them to view the times according to their "local" clock
  2. Generating the Regional dossier to show the relative Influence Endorsements/WA membership from the nations of the target region
  3. Move to button, allowing transfer of logged in nation to the target region
  4. Switching facility to change puppets

Not shown on the mock up:
  • Calculation of time differential
  • Resign from WA button

Obviously to generate 2 and 3 one of the user inputs would need to be set as the key - possibly the first entry

Probably not feasible: countdown based on the current time vs predicted update time of the target
Actually this might be possible using this as a starting point:
Code: Select all
<? /*
   declare target date; source: http://us.imdb.com/ReleaseDates?0121766 ;
  */
  $day   = 31;     // Day of the countdown
  $month = 12;      // Month of the countdown
  $year  = 2015;   // Year of the countdown
  $hour  = 23;     // Hour of the day (east coast time)
  $event = "New Year's Eve, 2015"; //event

  $calculation = ((mktime ($hour,0,0,$month,$day,$year) - time(void))/3600);
  $hours = (int)$calculation;
  $days  = (int)($hours/24);
/*
  mktime() http://www.php.net/manual/en/function.mktime.php
  time()   http://www.php.net/manual/en/function.time.php
  (int)    http://www.php.net/manual/en/language.types.integer.php
*/
?>
<ul>
<li>The date is <?=(date ("l, jS \of F Y g:i:s A"));?>.</li>
<li>It is <?=$days?> days until <?=$event?>.</li>
<li>It is <?=$hours?> hours until <?=$event?>.</li>
</ul>


Al of this probably is overkill, but as you say its more the challenge of constructing the thing and seeing if it is possible rather than its implementation
Last edited by Letoilenoir on Sat Jul 04, 2015 11:36 am, edited 2 times in total.
KEEP THE BLOOD CAVE FREE

User avatar
Lordieth
Post Czar
 
Posts: 31603
Founded: Jun 18, 2010
New York Times Democracy

Postby Lordieth » Sat Jul 04, 2015 11:43 am

Interesting stuff. The regional overview will be based on the API call on the Nations in the form fields?
There was a signature here. It's gone now.

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

Postby Letoilenoir » Sat Jul 04, 2015 11:58 am

Lordieth wrote:Interesting stuff. The regional overview will be based on the API call on the Nations in the form fields?


Based on earlier experiments:

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Regional Overview</title>
<style type="text/css" media="all">
      @import "http://www.nationstates.net/ns_v129.css";
   </style><!--[if IE 5]>
<style type="text/css">
/* place css box model fixes for IE 5* in this conditional comment */
.twoColFixLt #sidebar1 { width: 230px; }
</style>
<![endif]--><!--[if IE]>
<style type="text/css">
/* place css fixes for all versions of IE in this conditional comment */
.twoColFixLt #sidebar1 { padding-top: 30px; }
.twoColFixLt #mainContent { zoom: 1; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]--></head>

<body class="twoColFixLt">

<div id="container">
    <div id="mainContent">
    <h1>
   <img alt="MAD logo" height="138" longdesc="the letters W A &amp; D on Sauvage font" src="Default.png" width="290" /></h1>
      <h1> Regional Overview </h1>
    <h2>(Experimental Dossier)</h2>
    <table><th>Nation<th>Influence<th>WA<th>Score<th>Region<th>Last Active<th>Last login


<?php
$nation_list = array("pot","smartweed","letoilenoir","vampire_pirates","blood_and_sand","the_blood_cave","blood");/* populate this array with nations you wish to enquire about -max 50 */

   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;
      }
     
      $xml = simplexml_load_file($file);
      return $xml;
   }
   ini_set('user_agent', 'xxxxxxxxx');/* replace xxxxxxxx with your main nation name - this allows NS Admin to notify you is your script is causing ploblems */
   function display_strategic_report($nation) {
      $data = get_data($nation, 'name+influence+wa+censusscore-65+region+lastactivity+lastlogin');
     
      $name = (string) $data->NAME;
      $influence = (string) $data->INFLUENCE;
      $wa = (string) $data->UNSTATUS;
     $censusscore1 = (string) $data->CENSUSSCORE;
     $region = (string) $data->REGION;
     $activity = (string) $data->LASTACTIVITY;
     $timestamp = (string) $data->LASTLOGIN;
   

     echo "<tr><td><a rel='nofollow' target='_blank' href='http://www.nationstates.net/nation=$name'>$name</a>";
     echo "<td>$influence</td>";
    echo "<td>$wa</td>";
    echo "<td>$censusscore1</td>";
    echo "<td><a rel='nofollow' target='_blank' href='http://www.nationstates.net/region=$region'>$region</td>";
    echo "<td>$activity</td>";
    echo "<td>" . gmdate("d-M-y\TH:i:s", $timestamp) . "</td>";
   
   
 
   
 
       
    }/* This function retrives the data  nation and the required shards from the API ready for output*/
   
foreach ($nation_list as $nation)
{
  display_strategic_report($nation);   
}/* this loops through the array and outputs the relevent data (nation + shards) */

?></table>

      <br />

<a href="http://pipes.yahoo.com/redfleet/nutcracker2">Nutcracker </a>can also provide data on legislation passed by these nations and further
      <br />
      timestamps to determine a regions approximate update time<br />
      <br />
      The <a href="http://moruna.comoj.com/delegate14.php">Regional Update</a> page displays the schedule of regions at the last
      Major Update and may<br />
      help you will help you with positioning triggers and sleepers<br>
<br>Many thanks to <a href="http://www.nationstates.net/nation=the_blaatschapen">The Blaatschapen</a> for assisting with the gremlins <br>
and to <a href="http://www.nationstates.net/nation=glen-rhodes">Glen Rhodes</a>
               for the original code

<!-- end #container --></a><br />
      <br />
   </div>
</body>
</html>


I never got arround to setting the nation list array to be populated via a cal to the API, but in theory I guess it would be feasible - the array is handcoded at the moment
Last edited by Letoilenoir on Sat Jul 04, 2015 11:59 am, edited 1 time in total.
KEEP THE BLOOD CAVE FREE


Advertisement

Remove ads

Return to Technical

Who is online

Users browsing this forum: Kractero, Meraud, Republique Maritime dAlpine, Rusticus Damianus, Swiff, UNIOS

Advertisement

Remove ads