summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
+ }
+}