Created
May 29, 2013 11:45
-
-
Save anka-213/5669708 to your computer and use it in GitHub Desktop.
Locate the first link in the forum thread to each frame in the xkcd Time comic
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
#!/usr/bin/perl -w | |
use strict; | |
use warnings; | |
use LWP::Simple; | |
sub main | |
{ | |
my $start = 0; | |
my %frames; | |
if(open FILE, "<data/forums2.txt") { | |
my $last_line; | |
while(<FILE>) { | |
$frames{$1} = 1 if /^(.*), (.*)$/; | |
$start = $1 if $2 =~ /start=(\d*)/ && $1 > $start | |
} | |
close FILE or die $!; | |
print "$_\n" for (keys %frames); | |
} | |
#print "$start\n"; | |
my $oldstart = $start; | |
open FILE, ">>data/forums2.txt" or die "Couldn't open file, $!"; | |
my $data; | |
do { | |
print "\nPage: " . ($start/40+1) . "\n"; | |
my $time = "http://imgs.xkcd.com/comics/time/"; | |
my $url = "http://forums.xkcd.com/viewtopic.php?f=7&t=101043&start=$start"; | |
$data = get($url); | |
while ($data =~ m/(#p\d*)[^#]*$time([0-9a-z]{64}\.png)/gs) | |
{ | |
my $post = $1; | |
my $img = $2; | |
if (!$frames{$img}) { | |
# print "$img, $url$post\n"; | |
print FILE "$img, $url$post\n"; | |
$frames{$img} = 1; | |
} | |
} | |
$start += 40; | |
} while ($start < $oldstart + 100*40 && $data =~ /$start" class="right-box right">Next/); | |
close(FILE) or die $!; | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment