Created
September 24, 2009 04:43
-
-
Save ussjoin/192516 to your computer and use it in GitHub Desktop.
Script to calculate how many bytes of text I eat per day from my Google Reader subscriptions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to calculate how many bytes of text I eat per day from my Google Reader | |
# subscriptions. | |
use strict; | |
use XML::Feed; | |
open(OPML, "<google-reader-subscriptions.xml"); | |
my @lines = <OPML>; | |
close(OPML); | |
my @urls; | |
foreach (@lines) | |
{ | |
my $line = $_; | |
if ($line =~ m/xmlUrl\=\"(.+?)\"/) | |
{ | |
push(@urls, $1); | |
} | |
} | |
my $overall = 0.0; | |
foreach (@urls) | |
{ | |
print("URL: $_\n"); | |
my $feed = XML::Feed->parse(URI->new($_)); | |
if ($feed) | |
{ | |
print("Blog: ".$feed->title."\n"); | |
my $entries = scalar $feed->entries; | |
if ($entries > 0) | |
{ | |
my $bytes = 0; | |
foreach ($feed->entries) | |
{ | |
$bytes += length($_->content->body); | |
} | |
if ($bytes > 0) | |
{ | |
print("$bytes bytes in $entries entries\n"); | |
my $firstdate = ($feed->entries)[0]->issued; | |
#Some feeds (notably XKCD) don't use the issued feed, oddly | |
if (!$firstdate) | |
{ | |
$firstdate = ($feed->entries)[0]->modified; | |
} | |
my $lastdate = ($feed->entries)[$entries-1]->issued; | |
if (!$firstdate) | |
{ | |
$lastdate = ($feed->entries)[$entries-1]->modified; | |
} | |
my $duration = $firstdate->delta_ms($lastdate)->delta_minutes; | |
if ($duration == 0) # Happens when the feed only has one item | |
{ | |
$duration = 24*60; # Assume one day | |
} | |
my $perday = ($bytes/$duration)*24*60; | |
print("$bytes bytes / $duration minutes = $perday bytes/day\n"); | |
$overall += $perday; | |
} | |
else | |
{ | |
print("No content, moving on.\n"); | |
} | |
} | |
else | |
{ | |
print("No entries, moving on.\n"); | |
} | |
} | |
} | |
printf("Total of $overall bytes per day consumed from these feeds.\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment