[Bast-commits] r8242 - ironman/IronMan-Web/script
grim at dev.catalyst.perl.org
grim at dev.catalyst.perl.org
Wed Jan 6 13:13:23 GMT 2010
Author: grim
Date: 2010-01-06 13:13:23 +0000 (Wed, 06 Jan 2010)
New Revision: 8242
Added:
ironman/IronMan-Web/script/pull_urls.pl
Log:
Created script to pull in links from feeds
Added: ironman/IronMan-Web/script/pull_urls.pl
===================================================================
--- ironman/IronMan-Web/script/pull_urls.pl (rev 0)
+++ ironman/IronMan-Web/script/pull_urls.pl 2010-01-06 13:13:23 UTC (rev 8242)
@@ -0,0 +1,56 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use Getopt::Long;
+use Pod::Usage;
+use XML::Feed;
+use URI;
+use TryCatch::Error;
+use TryCatch;
+
+use utf8 ();
+=head1 SYNOPSIS
+
+ perl pull_urls.pl --db_path=/home/graeme/workspace/Ironman/ironman.db
+
+This script populates the missing urls for the feeds based on the <link> tag returned.
+
+=cut
+
+use Data::Dumper;
+
+use IronMan::Schema;
+
+my ( $db_path );
+GetOptions(
+ 'db_path=s' => \$db_path,
+) or die pod2usage;
+
+unless($db_path) {
+ die pod2usage;
+}
+
+my $schema = IronMan::Schema->connect("dbi:SQLite:$db_path");
+
+#Grab the feeds with no links.
+my @feeds = $schema->resultset('Feed')->search({ link => undef })->all;
+
+foreach my $feed (@feeds) {
+ my $parsed_feed;
+
+ try {
+ $parsed_feed = XML::Feed->parse(URI->new($feed->url));
+ }
+
+ catch {
+ print "FAILED TO PARSE: ", $feed->url, "\n";
+ }
+
+ if($parsed_feed && $parsed_feed->link) {
+ print "DONE: ", $parsed_feed->link, "\n";
+ $feed->update({link => $parsed_feed->link});
+ } else {
+ print "FAILED: ", $feed->url, "\n";
+ }
+}
More information about the Bast-commits
mailing list