#!/usr/bin/perl use 5.10.0; use warnings; use strict; use utf8; use autodie; #use CGI::Carp qw/fatalsToBrowser/;#DEBUG use CGI qw(:standard); use WWW::Scripter; use Sort::Key::Natural qw(natsort); use LWP::UserAgent; use List::Util 'shuffle'; use URI::Escape; use Readonly; Readonly my $MAXTOCACHE => 50; Readonly my $MAXSHIT => 7; my $interwebs = WWW::Scripter->new; $interwebs->use_plugin('JavaScript'); # We keep an hash to look up the sites we use. Should refactor if we were getting bigger. sub fetch_from_cache_or_web { my $site=shift; my %sites = ( dotomator => 'http://www.dotomator.com/web20.html', wtf => 'http://whatthefuckismysocialmediastrategy.com/', bullshitr => 'http://emptybottle.org/bullshit/index.php', dack => 'http://www.dack.com/web/bullshit.html', ); return unless $sites{$site}; my $now = time(); # We cache these pages for 3 hours to minimize latency - turns out that evaluating # the js is the real bottleneck. But hey. unless (-e "/tmp/bullshit-cache/$site.html" && -M "/tmp/bullshit-cache/$site.html" < 10800 ) { #warn "caching invoked\n"; #DEBUG $interwebs->get($sites{$site}); open OUT, '>:utf8', "/tmp/bullshit-cache/$site.html"; if($site eq 'dotomator') { my $ua = LWP::UserAgent->new; my $resp = $ua->get("http://www.dotomator.com/web20.js"); my $page = $interwebs->content; my $web20 = $resp->content; $page =~ s//\n