Igor Gariev (gariev) wrote in changelog,
Igor Gariev
gariev
changelog

[ljcom] r11204: LJINT-454: Comments for side projects (g...

Committer: gariev
LJINT-454: Comments for side projects (global) - stage 2
A   trunk/bin/worker/partner-site
A   trunk/templates/PartnerSite/
A   trunk/templates/PartnerSite/entry.tmpl
Added: trunk/bin/worker/partner-site
===================================================================
--- trunk/bin/worker/partner-site	                        (rev 0)
+++ trunk/bin/worker/partner-site	2011-11-23 15:37:30 UTC (rev 11204)
@@ -0,0 +1,95 @@
+#!/usr/bin/perl
+use strict;
+use lib "$ENV{LJHOME}/cgi-bin";
+require 'ljlib.pl';
+
+package LJ::NewWorker::TheSchwartz::PartnerSite;
+use base 'LJ::NewWorker::TheSchwartz';
+sub capabilities { 'LJ::Worker::PartnerSite' }
+
+##
+## Sample test code
+##
+=comment
+my $sclient = LJ::theschwartz() or die;
+my $job = TheSchwartz::Job->new(
+    funcname    => "LJ::Worker::PartnerSite",
+    arg         => {
+        entry_url       => 'http://test.ljdev7.livejournal.ru/21183.html',
+        external_url    => 'http://kommersant.ru/doc/1821098',
+    },
+);
+$sclient->insert($job);
+=cut
+
+__PACKAGE__->start();
+
+package LJ::Worker::PartnerSite;
+use base 'TheSchwartz::Worker';
+use LWP::Simple qw/$ua/;
+use LJ::HTML::Metadata;
+
+sub work {
+    my ($class, $job) = @_;
+    my $a = $job->arg;
+    
+    my $entry_url       = $a->{'entry_url'};
+    my $external_url    = $a->{'external_url'};
+
+    my $response = $ua->get($external_url);
+    unless ($response->is_success) {
+        die "Can't get content from $external_url: " . $response->status_line;
+    }
+
+    my $metadata = LJ::HTML::Metadata->new( 'html' => $response->content );
+    unless ($metadata->title && $metadata->description) {
+        die "No metadata found in $external_url";
+    }
+
+    my $entry = LJ::Entry->new_from_url($entry_url);
+    unless ($entry && $entry->valid) {
+        die "Can't instantiate entry for $entry_url";
+    }
+
+    my $template = LJ::HTML::Template->new(
+        { use_expr => 1 }, filename => "templates/PartnerSite/entry.tmpl",
+    );
+    $template->param(
+        title       => $metadata->title || '',
+        description => $metadata->description || '',
+        image       => $metadata->image || '',
+        url         => $external_url,
+    );
+
+    my $journalu    = $entry->journal;
+    my $posteru     = $entry->poster;
+
+    my %res = ();
+    my %req = ( 
+        'mode'          => 'editevent',
+        'ver'           => $LJ::PROTOCOL_VER,
+        'user'          => $posteru->{'user'},
+        'userjournal'   => $journalu->{'user'},
+        'itemid'        => $entry->jitemid,
+        'security'      => $entry->security,
+        'allowmask'     => $entry->allowmask,
+        'subject'       => $metadata->title,
+        'event'         => $template->output,
+    );
+
+    # do editevent request
+    LJ::do_request(\%req, \%res, { 'noauth' => 1, 'u' => $posteru });
+
+    # check response
+    unless ($res{'success'} eq "OK") {
+        die "Can't update entry $entry_url: $res{'errmsg'}";
+    }
+    
+    return $job->completed;
+}
+
+sub keep_exit_status_for    { 0    }
+sub grab_for                { 400  }
+sub max_retries             { 3    }
+sub retry_delay             { 3600 }
+


Property changes on: trunk/bin/worker/partner-site
___________________________________________________________________
Added: svn:executable
   + *

Added: trunk/templates/PartnerSite/entry.tmpl
===================================================================
--- trunk/templates/PartnerSite/entry.tmpl	                        (rev 0)
+++ trunk/templates/PartnerSite/entry.tmpl	2011-11-23 15:37:30 UTC (rev 11204)
@@ -0,0 +1,10 @@
+<h1><tmpl_var title></h1>
+
+<tmpl_var description>
+
+<tmpl_if image><img src="<tmpl_var image>"></tmpl_if>
+
+<a href="<tmpl_var url>"><tmpl_var url></a>
+
+
+

Tags: gariev, ljcom, tmpl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments