summary refs log tree commit diff
path: root/lifestream.pl
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2009-12-21 20:53:33 +0100
committerfranck cuny <franck@lumberjaph.net>2009-12-21 20:53:33 +0100
commiteb73581424fcdf1204ec864f4a102928f28cbdc9 (patch)
treed8e5d48b899f0eacfdd1835180215b996b79c5a0 /lifestream.pl
parentadd github (diff)
downloadlifestream-eb73581424fcdf1204ec864f4a102928f28cbdc9.tar.gz
from a dumb .pl to Tatsumaki
Diffstat (limited to 'lifestream.pl')
-rw-r--r--lifestream.pl85
1 files changed, 42 insertions, 43 deletions
diff --git a/lifestream.pl b/lifestream.pl
index 9423cc5..faf20ea 100644
--- a/lifestream.pl
+++ b/lifestream.pl
@@ -1,53 +1,52 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
+
 use strict;
-use feature 'say';
+use warnings;
+use lib ('lib');
 
-use XML::Feed;
 use YAML::Syck;
-use URI;
-use Template;
-
-my $config = LoadFile( shift );
-
-my $hash_entries;
-foreach ( @{$config->{actions}} ) {
-    my $feed = XML::Feed->parse( URI->new( $_->{ url } ) );
-    for my $e ( $feed->entries ) {
-        my $date = $e->issued->strftime( '%Y.%m.%d' );
-        push @{ $hash_entries->{ $date } },
-            {
-            source     => $_->{ source },
-            date       => $e->issued->hms,
-            title      => $e->title,
-            link       => $e->link,
-            source_url => $_->{ source_url },
-            };
-    }
-}
+use Lifestream;
+use Getopt::Long;
 
-my @dates = keys %$hash_entries;
-my @sorted_dates = sort { $a cmp $b } @dates;
+my $options = GetOptions(
+    'config=s'  => \my $config,
+    'deploy'    => \my $deploy,
+    'add'       => \my $add,
+    'url=s'     => \my $url,
+    'name=s'    => \my $name,
+    'start'     => \my $start,
+    'profile=s' => \my $profile,
+);
 
-my $hash_templates;
-for my $type ( 'profiles', 'actions' ) {
-    foreach my $profile ( @{ $config->{ $type } } ) {
-        push @{ $hash_templates->{ profiles } }, $profile;
-    }
+my $yaml_conf = LoadFile($config);
+
+my $schema = Lifestream::Schema->connect( @{ $yaml_conf->{connect_info} } );
+
+if ($deploy) {
+    $schema->deploy;
 }
 
-foreach my $date ( reverse @sorted_dates ) {
-    my @actions = sort { $b->{ date } cmp $a->{ date } }
-        @{ $hash_entries->{ $date } };
-    push @{ $hash_templates->{ entries } },
+if ($add) {
+    $schema->resultset('Feed')->create(
         {
-        date    => $date,
-        actions => \@actions
-        };
+            feed_url         => $url,
+            name        => $name,
+            profile_url => $profile,
+        }
+    );
 }
 
-my $template = Template->new;
-$template->process( 'lifestream.tt', $hash_templates, \my $content )
-    or die $!;
-open my $fh, '>:utf8', 'public/index.html';
-print $fh $content;
-close $fh;
+if ($start) {
+    my $app = Lifestream->app( config => LoadFile($config) );
+
+    if ( $0 eq __FILE__ ) {
+        require Tatsumaki::Server;
+        Tatsumaki::Server->new(
+            port => 9999,
+            host => 0,
+        )->run($app);
+    }
+    else {
+        return $app;
+    }
+}