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:
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.
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.
< !-- 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.:
< 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 MTTrackbacks
- : 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 - : 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 - : 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!
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'























































December 12th, 2004 at 06:59 pm
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
December 12th, 2004 at 04:26 pm
I got rid of the NaN thing, but nothing shows up for numbers now.
I am sorry if I am being a pain.
December 12th, 2004 at 04:14 pm
okay, is the new plug-in at the same location? I am still getting the NaN thing.
December 12th, 2004 at 04:09 pm
Thanks!
December 10th, 2004 at 09:39 pm
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!
November 28th, 2004 at 01:56 pm
Instead of getting numbers I get letters…3 of them which state “NaN”. What the heck did I do wrong?
July 6th, 2004 at 11:09 pm
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!
July 6th, 2004 at 10:03 pm
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;
}
March 24th, 2004 at 05:32 pm
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
March 20th, 2004 at 03:57 pm
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 ...
March 20th, 2004 at 02:53 am
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
April 23rd, 2003 at 08:47 pm
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!
April 23rd, 2003 at 03:26 pm
Uh oh! Sorry for the double comment. But I’m sure being a blog-guru you can fix it.
April 23rd, 2003 at 03:22 pm
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.
April 20th, 2003 at 07:22 pm
Sign of a mis-spent youth Maggie!
And yes, daughter had a fun egg hunt!
April 19th, 2003 at 10:34 pm
You are such a wiz with coding Oscar
. Hope you’re all geared up for the egg hunt tomorrow
Page 1 of 1 pages