Quick tip: clone of PHP’s microtime() function as a Perl subroutine.

Refer to the PHP manual for how the function is supposed to work. The short version is that you call “microtime(1)” to get this perl subroutine to return a float-formatted value containing the seconds and microseconds since the unix epoch.


# Clone of PHP's microtime. - from http://seancolombo.com
use Time::HiRes qw(gettimeofday);
sub microtime{
my $asFloat = 0;
if(@_){
$asFloat = shift;
}
(my $epochseconds, buy  my $microseconds) = gettimeofday;
if($asFloat){
while(length("$microseconds") < 6){
$microseconds = "0$microseconds";
}
$microtime = "$epochseconds.$microseconds";
} else {
$microtime = "$epochseconds $microseconds";
}
return $microtime;
}

This is public domain, use it as you’d like. Please let me know if you find any bugs.

Hope it helps!

Open sourcing a MediaWiki bot framework

On my last post I asked what my readers wanted me to write about and all of the responses I got on the post or in person had the “how to write a MediaWiki bot in 10 minutes or less” at the top of the list.

I have that post mostly written, physiotherapy but in order to make that whole process easier, more about I’ve finally made the bot framework that I now use to be open sourced and easily accessible online.

Background

I used to use custom scripts for my bot, but this summer when LyricWiki transitioned over to Wikia, they all broke. My scripts pre-dated the MediaWiki API so they had depended on screen-scraping which no longer worked when we switched to Wikia’s skins which had a completely different layout.

When I had to get my bots running again, I looked at a few Perl frameworks for connecting to the MediaWiki API, and the one that seemed to have significantly less bugs than the others was a perl module by CBM.

Over the months, I’ve realized that there was some functionality that wasn’t implemented yet but which I needed – deleting pages, issuing purges, finding all templates included on a page – so I updated to the module. I tried to get access to the MediaWiki Tool Server where the project is currently hosted, but they must be really busy because they haven’t replied to the JIRA issue (request for an account) and it’s been months.

Since it has become quite a waiting game, I decided to just fork the project. Hopefully CBM will want access to the repository and we can just keep working on it together. Regardless, I’ve created all of the usual suspects for a project such as this (see next section).

Project links

So, without further delay, here are the beginnings of the Perl MediaWiki API

The links (especially the wiki) need a lot of work before it becomes obvious how to quickly get set up and use the module. The next blog post will take care of that!

However, if you’re curious & are already comfortable with Perl (and to some extent MediaWiki), you can jump right in. Let me know if you have any feedback. Thanks!

What do you want to see?

Note: If you’re seeing this on facebook, epilepsy it is just pulled in from my blog at http://seancolombo.com

I’m in the mood to do some blogging in the next couple of days but have more ideas than time. What would YOU find most interesting? I’m thinking along the lines of either analyzing LyricWiki statistics or doing quick tutorials (“How to Write a MediaWiki Bot in 10 Minutes or Less”, or something similar).

Here were some ideas of stats I could do. They each take a decent amount of time, so please let me know which ones you are most interested in:

  • Views / #Songs by Genre
  • Views / #Pages by Language
  • Views / #Pages by Publisher
  • Infographic of Lables/Publishers in the Music Industry, how they relate to each other, and their prevalence in the market.
  • Our prevalence in a country vs. it’s prevalence online
  • Impact on page-views of being SOTD / AOTW / FMOM vs. not.
  • Views from songs that were on the iTunes Top 100 during the month vs. those that weren’t. Views/page for that same group.
  • Views by page-age and views/page by page-age.
  • Views by page freshness (last touched) and views/page by page freshness. Include histogram of freshness across all pages.

Let me know in the comments what you want to see! Those stats, the tutorial mentioned, or anything else are all fair game. Since I don’t have many readers yet, if you comment then I’ll probably do the post you’re asking for.