Login  |  Register
X
Username
Password
Forgot your password? 

NOTE 2009: This is very old, and I doubt it is anything you want ... there must be better ways, if anyone wishes to access such information these days.



Here's a little bit of MovableType business, well worth its High Intensity Time Wasting status! I was browsing the MovableType Help Forums, and came across this thread. Sam wanted, as it turned out, to have a counter on his site that would retrieve the current world population, and then be able to use it in something like this:

The current world population is
So, if I think I'm "one-in-a-million" I should just
bear in mind that there are about more people just like me!

Hey, let's hope none of them lives nearby!

So, being a bit of a narcissist myself, I thought I would benefit from being regularly reminded of my actual ordinariness, and thus I threw together some World Population code to enable the above demo. The first thing is a MovableType world census plugin which enables a <$MTworldPop$> tag that scrapes a government website for the current world population. Then there is some javascript for updating the population and doing some simple calcualtions.

Well, in case you missed it, download the world census plugin here, and install it in your MovableType plugin directory.

Then paste these javascript variables into your template somewhere between the <head> and </head> tags.

<script language="javascript" type="text/javascript">
     var myWorldPop = "<$MTworldPop$>";
     var myDate = "<$MTDate$>";
</script>

That will set up the strings necessary to get the rest done. The next javascript functions are just thrown together to demonstrate how one might use the info and to enable Sam's idea from the forums. They can serve as templates for other stuff of course. For the demo above, I placed them at the beginning of the entry, but for templates, they can also be placed between the <head> and </head> tags.

<script language="javascript" type="text/javascript">
< !-- hide

function removeCommas (myStr)
{
     var myRegEx = /,/g;
     return myStr.replace(myRegEx,'');
}

function CurrentPop(reb, popul)
{
     var pop_growth_per_sec = 3; // population increasing at 3 people/second
     var myLagTime = new Date() - new Date(reb); // subtract now from rebuild date = milliseconds since rebuild
     var newPeople = ((myLagTime * pop_growth_per_sec)/1000); //time in seconds * growthrate
     var myCurrentPop = (Number(removeCommas(popul)) + newPeople);
     document.write(myCurrentPop +"<br />");
}

function OneInAMil(reb,popul)
{
     var pop_growth_per_sec = 3; // population increasing at 3 people/second
     var myLagTime = new Date() - new Date(reb); // subtract now from rebuild      date = milliseconds since rebuild
     var newPeople = ((myLagTime * pop_growth_per_sec)/1000); //time in seconds * growthrate
     var myCurrentPop = (Number(removeCommas(popul)) + newPeople);
     var oneIn = Math.round(myCurrentPop/1000000);
     document.write(oneIn +"<br />");
}
// -->
</script>

Then you have to call these functions in the body of your entry or template so that they will be dynamically updated whenever the page is loaded. In my entry above, I did the following right in the body of the entry.:

The current world population is
< script language="JavaScript">
< !-- hide
CurrentPop(myDate,myWorldPop);
// -->
< /script>
< br />
So, if I think I'm "one-in-a-million" I should just <br />
bear in mind that there are about
< script language="JavaScript">
< !-- hide
OneInAMil(myDate,myWorldPop);
// -->
< /script>
more people just like me!<br /><br />
Hey, let's hope none of them lives nearby!<br />

Obviously, those functions are highly redundant, and could be modified any old way. Well, that's it. I thought I would post this just in case anyone else is interested. Enjoy.

Comments

19 Responses to World Population Plugin for MT
  1. Oscar Says:

    Hmmm ... If you’ll email me your template code, I’ll try it here and be sure it’s working.

    But, before that, you might download the plugin again, or make sure it’s the latest one, then delete the current one on your server, then upload the new one. Then CHMOD the plugin to at least 755 (assuming your comfortable with such) - permissions are important here or plugins won’t work.

    If the plugin is failing to get the data, it should return “could not retrieve population” but if it is not working at all, you get a blank.

    In the latter case, the plugin has either become corrupted on upload somehow, or permissions are wrong.

    Let me know howit goes, and feel free to ask for more help. The thing should be working

  2. Susan Says:

    I got rid of the NaN thing, but nothing shows up for numbers now.
    I am sorry if I am being a pain.

  3. Susan Says:

    okay, is the new plug-in at the same location? I am still getting the NaN thing.

  4. Susan Says:

    Thanks!

  5. Oscar Says:

    If anyone is using this plugin, the site has changed just a little, so it hasn’t been working lately. I just now updated it, so download the new one and give it a try!

  6. Susan Says:

    I must be doing something wrong with this…I thought this would be an interesting piece of info for my email blog domain and I cannot seem to get it to work.

    Instead of getting numbers I get letters…3 of them which state “NaN”. What the heck did I do wrong?

  7. Oscar Says:

    Right you are John (on both size and “liveness”)!

    I’ll change the code and re-post the plugin when I get a few minutes wunna these days soon.

    Thanks!

  8. John Wyles Says:

    The script fetches a quote from a page that is double in size (~8k rather than ~4k) and seems to be less “live” than this page from Census.gov: http://www.census.gov/cgi-bin/ipc/popclockw .  Might I suggest only the following MINOR modifications?:

    sub scrape_pop {
      my $out = ‘Could not retrieve population.’;
      my $population = ‘http://www.census.gov/cgi-bin/ipc/popclockw’;
      my $req = HTTP::Request->new(GET => $population);
      my $ua = LWP::UserAgent->new;
      $ua->agent(‘cenCheck/1.0’);
      my $res = $ua->request($req);
      my $c = $res->content;                                                     

      if ($c =~ /<h1>(.*?)<\/h1>/i)
      {
          $out = $1;
      }
                                                         
      return $out;
    }

  9. Neil Says:

    Thanks alot.  I have it working now on my site.  http://neil.cbulock.com  It’s in the sidebar right under the cost of the Iraq war smile

  10. Oscar Says:

    It can go anywhere you want. You can put it in an individual post if you are going to use it only once, or in your index template or elsewhere if you plan to use it repeatedly, i.e., if you want those functions available to you regularly without having to recode them all the time. Hope that helps ...

  11. Neil Says:

    Where does the second “Chunk of Javascript code” go?  Do both the first two codes go in your head of “index.html”?  Also, does the last part have to be in a post, or can it go in the sidebar on the site?  Thanks
    -Neil Vitale

  12. Oscar Says:

    Thanks Beatriz! Yes, I used my computer brains to push the delete button on the duplicate comment Phew!

    You know, all you have to do is throw the plugin into the plugins directory, and then you have a new tag at your disposal. But, I know, ya gotta be in the mood for that sort of thing.

    I was thinking of adding some tags to the plugin, like populations for different countries, or who knows. But I figure, I’ll only do that if someone wants it!

    But, hey, I am glad that youy LIKE it in any case!

  13. Beatriz Says:

    Uh oh! Sorry for the double comment. But I’m sure being a blog-guru you can fix it.

  14. Beatriz Says:

    Dear God! Someone should have told me about this before I started making statistics of world population in Excel… ha ha! Cool plugin. I just don’t have the patience (or the resources, I’m afraid) to make them work.

    Cool! Spongebob!

  15. Oscar Says:

    Sign of a mis-spent youth Maggie!

    And yes, daughter had a fun egg hunt!

  16. Maggie Says:

    You are such a wiz with coding Oscar .  Hope you’re all geared up for the egg hunt tomorrow

  17. Page 1 of 1 pages


Trackbacks

  1. : One in a Million: World Population Plugin for MT If you are One in a Million, there are 6285 people in the world that are exactly like you....
    Tracked at 2003 04 21 20:01:54
  2. : MT Plugin Directory: World Population Plugin for MT Uses the census data from Census.gov. oscar@ofhills.com-->
    Tracked at 2003 04 24 19:04:37
  3. : Confessions of a Tech Junkie: World Population Plugin for MT Still playing around with plug-ins and track back. I just installed the World Population Gadget which screen scrapes the world population. It is a cute waste of time....
    Tracked at 2003 09 26 03:29:08




Tell us your thoughts...
And (as you probably know) if you want a pic to show with your comment, go get a gravatar!

Smilies

Please be kind enough to submit the word you see below:




Next entry: Caravan Tablature

Previous entry: PHP Script For Terror Alert Level

World Population Plugin for MT

Posted by Oscar on Fri, 4/18/03 at 07:36 PM
Filed under: • MT & Web Design
Comments: 19 Comments/Trackbacks






OFH Solo Banjo/Guitar mp3's
pretty good if you like pickin'



Loading images
loading
Tranjo Demonstration Jerry Reeds Sassy Last Old Shovel - ROMP 2007 Dixie Breakdown - ROMP 2007 The Man In The Middle - ROMP 2007 Sittin On Top Of The World - ROMP 2007 Home Sweet Home Sound Check - ROMP 2007 Do I Ever Cross Your Mind - ROMP 2007 Ridin On That Midnight Train - ROMP 2007 Drive-In Uncle Johns Band Lumberyard Blues Helium Brothers Montage 2009 Hey Hey Hey - ROMP 2007 Wishful Thinking Midnight Moonlight I Aint Broke - ROMP 2007 Close By - ROMP 2007