GR2WP – Google reader shared items till WordPress

I kategorin Tips så delar jag med mig av intressanta inlägg som jag hittat via mina RSS-flöden i Google Reader.

Det finns flera andra som har liknande funktion på sina bloggar, de använder då exempelvis FeedWordPress, SharedItems2WP eller WP-o-Matic. Av olika anledningar passade ingen av dessa lösningar mig perfekt, mest för att jag ville ha full kontroll över flödet och för att det var så länge sen jag programmerade i perl …

Som jag nyss avslöjade, så skrev jag alltså ett perl-script som hämtar min shared items-feed från google reader (via XML::Atom::Syndication::Feed) och sen trycker jag in en post med de senaste bloggtipsen i WordPress (via XMLRPC::Lite).

Effekten blir den här.

Gå till Google reader, hitta ett intressant inlägg och välj ”Share with note”.

Share with note i google reader
Share with note i google reader

Lägg till en anteckning och spara.

Kör sen perlscriptet gr2wp.pl (Google Reader To WordPress).
Då skapas ett WP-inlägg med alla nya utdelade bloggposter.

Resultatet i WordPress
Resultatet i WordPress

Alla ”Jonas tipsar”-inlägg

Här kommer perlscriptet. Du får gärna använda och modifiera det helt fritt. Jag har utgått från ett script som postade google-reader shared items till delicious.

#!/usr/bin/perl -w

use strict;
use LWP::Simple;
use XML::Atom::Syndication::Feed;
use XMLRPC::Lite;
use XML::XPath;
use WordPress::XMLRPC;
use HTML::Entities;
use Time::Local;

######## CONFIGURATION ########
my $debug = 0;
# Your Google Shared Items Feed URL
my $feed_url = 'yourgoogleshareditemsfeedurl';

# A local file location for the feed
my $feed_file = '/path/to/localfeedfile.xml';

# Timestamp file
my $ts_file = "/path/to/gr2wp_timestamp.lis";

# WordPress post title
$wp_title = "post title";

# WordPress post categories (example: ['Fashion','Beauty'])
# (The categories must exist before posting)
@wp_categories = ['category'];

# WordPress user
$wp_user = 'username';

# WordPress password
$wp_pwd = 'password';

# WordPress proxy (URL to xmlrpc.php, don't forget to activate xmlrpc protocol in blog!)
$wp_proxy = 'http://sitename/xmlrpc.php';

######## END CONFIGURATION ########

# start time handling
my @now = localtime;
my $time = timelocal(@now);

# Subtract one week (default if no timestamp file found)
my $default_start = $time - 7 * 24 * 60 * 60; 

my $start_date;

# fetch last startdate or, if not found, pick a date one week ago
if (-e $ts_file) {
	open FP, "<$ts_file" or die "Could not open file $ts_file: $! \n";
	$start_date = ()[0];
	close FP;
	chomp $start_date;
	$start_date =~ s/\s//g;
} else {
	$start_date = $default_start;
}

print "Start date: ", $start_date, "\n" if $debug;
print "now: ", $time, "\n" if $debug;

# Set the google reader namespace URI
my $gr = 'http://www.google.com/schemas/reader/atom/';

#snag a local copy of the shared items feed
my $status = getstore($feed_url,$feed_file);
	die "Error $status fetching the Google Reader feed." unless is_success($status); 

# Init the wordpress API
my $o = WordPress::XMLRPC->new({
username => $wp_user,
password => $wp_pwd,
proxy => $wp_proxy,
});

#parse the shared items feed
my $feed = XML::Atom::Syndication::Feed->new($feed_file);
my @entries = $feed->entries;

# loop through items in the feed
my $buf = "
    "; my $post_count = 0; foreach my $entry (@entries) { # grab the title, link, and source title my $postTitle = encode_entities($entry->title->body); my $postLink = $entry->link->href; my $sourceTitle = encode_entities($entry->source->title->body); # get the time this item was shared my $shareTime = $entry->get_attribute($gr,'crawl-timestamp-msec'); # convert from milliseconds to seconds $shareTime = $shareTime/1000; # skip item if it was shared before the start date next if $shareTime < $start_date; $post_count++; #grab any notes my $xp = $entry->as_xml; # get the notes, this should probably be simplified ... my $notes = encode_entities($1, "\200-\377") if $xp =~ m/annotation>(.*?)<\/content>/; # Remove the "CDATA" bit, if present $notes = $1 if $notes =~ m//s; print "Title: $postTitle\n" if $debug; print "Link: $postLink\n" if $debug; print "Source: $sourceTitle\n" if $debug; # Create the post content $buf .= "
  • $sourceTitle: $postTitle
  • "; if ($notes) { $buf .= "
    "; $buf .= "$notes"; $buf .= "
    "; } } $buf .= "
"; #Delete the local copy of the feed unlink($feed_file); # timestamp my $ymd = sub{sprintf '%04d-%02d-%02d', $_[5]+1900, $_[4]+1, $_[3]}->(localtime); my $content_hashref; $content_hashref->{title} = "$wp_title - $ymd"; $content_hashref->{categories} = @wp_categories; $content_hashref->{description} = $buf; # Post to wordpress if ($post_count > 0) { $o->newPost($content_hashref, 1); open FP, ">$ts_file" or die "Could not open file $ts_file for writing: $!\n"; print FP $time; close FP; } else { print "No posts\n"; } # Debugging purposes, write post to local file gr2wp_debug.lis if ($debug) { open OFP, ">gr2wp_debug.lis"; print OFP $buf; close OFP; }

För enkelhetens skull kör jag perl-scriptet en gång om dagen, via crontab.

Jonas tipsar – 2009-07-07

Flickr

This is a test post from flickr, a fancy photo sharing thing.

cialis vs viagra cialis on line viagra coupons 75 off viagra without prescription cialis 20 mg levitra vs viagra healthy man viagra generic levitra buy levitra cialis 30 day trial coupon cialis side effects generic viagra available in usa what is viagra generic cialis tadalafil cialis patent expiration date extended levitra 20 mg viagra pharmacy herbal viagra levitra coupon cialis coupon 20 mg does viagra work generic viagra 100mg how does cialis work female viagra how long does levitra last viagra without a doctor prescription generic cialis at walmart levitra 20mg viagra savings offer canadian cialis viagra substitute levitra 20 mg cost walmart cialis alternative viagra coupons from pfizer levitra prices what does viagra do natural viagra alternatives that work cialis discount viagra vs cialis vs levitra what is cialis viagra coupon viagra dosage cialis vs viagra sophia viagra lowest cialis prices viagra girls viagra porn when will cialis go generic cialis daily levitra online viagra vs cialis cialis 20mg directions what is levitra buy viagra online viagra generic viagra for women levitra canada cialis 30 day sample discount cialis viagra 100mg tablets retail price free cialis cialis tadalafil levitra reviews cialis generic tadalafil viagra alternatives cialis price cialis website viagra from canada cialas levitra side effects viagra vs cialis vs levitra levitra vs cialis viagra on line no prec how much does cialis cost how much does viagra cost utilisation viagra buy cialis female viagra pills cialis generic viagra prices without insurance price cialis cvs pharmacy viagra coupons viagra single packs cost cialis coupons printable viagra costs levitra 10mg cialis or viagra viagra samples best price viagra cost of levitra side effects of cialis how does viagra work cialis patent expiration levitra without a doctor prescription daily cialis sex viagra for women how to take cialis cialis coupons 2017 cialis cialis samples overnight cialis without a doctor’s prescription viagra dose viagra prices levitra loc us cialis savings card viagra on line viagra cialis cialis pricing generic viagra order online viagra over the counter viagra cialis otc canada viagra cialis from canada cialis 20mg viagra without a doctor prescription usa levitra generic cialis for sale cialis coupons viagra patent expiration cialis patent expiration 2017 viagra pills cialis 5 mg cialis for women levitra cyalis generic for cialis pfizer viagra otc viagra is viagra government funded viagra from amazon cialis coupons from manufacturer cheap viagra pfizer viagra coupons cialis sample cialis for men cialis voucher viagra 100mg price walmart levitra vs viagra for hardness viagra government funding levitra 10 mg cost of viagra cialis samples sildenafil vs viagra cialis pharmacy prices viagra wholesale cialis viagra best price does the government fund viagra cialis or viagra viagra pills for sale viagra for sale cialis online non prescribed viagra online cialis viagra cost cialis coupon viagra price is viagra government funded in america viagra sex is viagra federally funded 200 cialis coupon viagra single packs cialis dosage cialis trial women viagra viagra ingredients cialis cheap liquid cialis online viagra cialis dosage recommendations cialis effects buy cialis online cialis for daily use 9 levitra at walmart walgreens viagra substitute cialis professional cialis copay card buy viagra cialis 5mg cialis pills stendra vs viagra cialis for bph cialis 10 mg levitra coupons canada cialis natural viagra cealis cialis canada viagra pill viagra online cialis dosage strengths cialis free trial viagra government funded levitra dosage side effects of viagra generic for viagra viagra canada cialis prices viagra coupons where to buy viagra cialis coupon print viagra side effects buy levitra online viagra activate discount viagra is viagra covered by insurance revatio vs viagra cilias cialis testimonials cialis reviews cialis 5mg daily cialis medication trial viagra sample levitra cost viamedic cialis viagra vs cialis erectile dysfunction cialis is viagra funded by government how long does viagra last cialis cost cheap cialis inexpensive viagra pills cost of cialis generic cialis cialis canadian pharmacy cialis pills for sale cialis generic availability free viagra canadian viagra levitra vs viagra

how many 5mg cialis should i take what is in cialis cialis for men tadalafil vs cialis cialis reviews cialis vs viagra cialis news get cialis cialis dosage 20mg viagra vs cialis cialis single dose daily dose cialis buy cialis cheap cialis mg strength max dose cialis cialis and levitra what does cialis do for you can cialis be taken with food best cialis prices cialis tadalafil cialis dosage instructions generic cialis how many cialis can i take how long is cialis effective cialis 5mg side effects what is cialis made of cialis free trial cialis online order cialis once a day medicine cialis cialis dosage 30 mg cialis use cialis is for cialis price what is cialis 20 mg used for what is cialis pills buy generic cialis online cialis 30 mg dose what is the maximum dose of cialis cialis eli lilly cheap generic cialis buy cheap cialis online cialis maximum dose cialis drug generic cialis price buy online cialis dose cialis cialis mg dosage tadalafil cialis 20mg cialis dosage can you take 10mg cialis daily cialis prescription online drug cialis cialis what is it used for cialis dosing www cialis cialis for daily use side effects cialis ohne rezept cialis dosage amounts cialis uk dosage cialis cialis what is it 20 mg cialis daily cialis company cialis 10mg cialis dosage 5mg cialis drug name cialis doses available side effects of cialis 20mg cialis alternative when to take cialis 10mg 20 mg cialis for daily use how to take cialis 10mg generic cialis canada cialis preise cialis online purchase daily dose of cialis canada cialis cialis online pharmacy cialis free sample should i take 10 or 20 mg of cialis cialis men cialis prescribing information normal dosage for cialis buy cialis viagra how often should you take cialis maximum daily dose of cialis 20 mg cialis standard cialis dose cialis symptoms whats cialis canada cialis generic cialis dosage when to take when is best time to take cialis soft cialis side effects of cialis 20 mg cialis overnight cialis online uk cialis without a prescription cheap cialis online another name for cialis what is cialis used for buy generic cialis normal dose of cialis how is cialis prescribed cialis dosage options what is a cialis pill cialis 20 mg tablet medication cialis how often can you take cialis cialis 40 mg free cialis cialis tablets 10mg directions for taking cialis 20 mg is cialis cialis coupon cheapest cialis price cialis tadalafil tablets cialis verkauf what is cialis prescribed for cialis australia cialis standard dose how much is cialis 20mg what is cialis 5mg used for maximum cialis dosage what is the dosage for cialis how is cialis taken cialis daily or 36 hour cialis samples how to use cialis 10mg cialis original cialis 5mg for daily use canadian cialis cialis generique cialis side effects cialis 20 mg cialis generic india how to take cialis 5mg how to use cialis 20 mg cialis dosage recommendations when is the best time to take cialis cialis purchase how much cialis can you take order generic cialis cialis 20mg dosage average dose of cialis cialis kaufen 10mg cialis daily how many mg cialis should i take cialis dose range cialis 10 mg tadalafil how to use cialis is cialis effective cialis tadalafil 10mg tablets buy cialis generic online cialis daily cialis lowest price discount generic cialis how much cialis should i take cialis best price purchase cialis cialis hap when to take cialis 20mg herbal cialis cialis time brand name cialis highest dose of cialis information on cialis how to use cialis 20mg tablets cialis generic viagra compare viagra to cialis tell me about cialis how often to take cialis 20mg what are the side effects of cialis cialis online no prescription use of cialis how often can i take 20mg cialis cialis commercial how do you use cialis what is cialis tablets used for what are side effects of cialis cialis cialis 20 mg dosage buy cheap cialis what is normal dose of cialis cialis risks 20 mg of cialis buy cialis now generico cialis cialis 5mg dosage when should you take cialis cialis buy cialis cheap who makes cialis generic cialis tadalafil how to take 5mg cialis when to take 20mg cialis cheap cialis cialis dosage 10mg cialis mg sizes cialis dosage timing dosage of cialis cialis tablets dosage uses of cialis cialis c20 cialis tablets 20mg cialis strength cialis effects tadalafil cialis 20 mg uk cialis cialis 20 mg side effects where to buy cialis buy cialis uk cialis mg cialis viagra cialis online bestellen cialis tablets uses when should i take cialis cialis one time use uses for cialis cialis 10 or 20 mg cialis etkileri cialis dosages available cialis how much to take cialis lilly how do i get cialis cialis max dose per day order cialis is cialis bad for you online pharmacy cialis potenzmittel cialis cialis daily dosage cialis 10mg or 20mg daily cialis dose best time to take cialis 20mg what is cialis how much are cialis pills cialis 10 cialis medication cialis generic average cialis dose low cost cialis how to take cialis 20 mg cialis recommended dosage how to take cialis 20mg cialis dosage side effects cialis cost what is cialis good for cialis tablets what are they how to make cialis kaufen cialis cialis cialis how do you take cialis buy cialis generic normal cialis dose what are cialis pills cialis 10 mg daily use generic cialis online cialis europe cialis proper dosage cialis chest pain cialis 5 cialis etkisi when do i take cialis main ingredient in cialis active ingredient cialis cialis generic online cialis normal dose cialis starting dose cialis tablets cialis order cialis what does it do cialis as needed dose cialis 36 hour cialis testimonials recommended dosage for cialis when do i take cialis 20 mg what are cialis tablets used for side effects of cialis 5mg viagra cialis cialis 20mg tadalafil cialis how to use cialis side online cialis how effective is cialis cialis for women cialis no prescription recommended cialis dosage cialis shop cialis ed dosage using cialis best time to take cialis cialis mail order what is the normal dose of cialis typical cialis dosage other uses for cialis buy cialis online how often can i take cialis what is a cialis when to take cialis 20 mg recommended dose of cialis cialis discount how to use cialis 20mg cialis experience cialis 24 hours cialis active ingredient best way to take cialis 20mg cialis usa what are cialis tablets cialis strengths available cialis how to take best way to use cialis 20mg cialis dosage daily cialis without prescription active ingredient in cialis maximum dose of cialis in 24 hours cialis 10mg daily maximum dose of cialis viagra cialis levitra cheap cialis generic cialis levitra medikament cialis cialis information cialis 20 cialis rezeptfrei cialis effect time cialis mexico is cialis safe prescription cialis cialis is used for cialis pills cialis dosage 10mg or 20mg cialis online prescription how to take cialis cialis on line cialis heart what does cialis do how much cialis can i take cialis free cialis tadalafil 10mg best price cialis cialis 20 mg instructions lilly cialis discount cialis 5mg cialis vs 10mg purchase cialis online what is cialis pills used for liquid cialis what is cialis tablets discount cialis online cialis dosage strengths cialis one a day cialis buy online eli lilly cialis cialis prescription cialis tadalafil 5mg pills cialis cialis muscle pain cialis vs tadalafil daily cialis side effects cheapest cialis uk achat cialis cialis 5 mg effects of cialis about cialis how do you get cialis levitra cialis how do i take cialis dosage for cialis 20mg when should i take cialis 20mg cialis when to take cialis dosage for ed cialis levitra viagra order cialis online cialis for sale cialis uses how often can i take cialis 20 mg cialis tadalafil 20mg cialis 20 mg 30 tablet cialis tadalafil 20mg tablets taking cialis how to take cialis properly cialis dosing options cialis 20mg side effects best cialis dose how often to take cialis cialis india cialis directions for use generic cialis cheap cialis 20mg side effects of cialis 10mg when do you take cialis different doses of cialis when to take cialis how often can you take 20mg cialis low price cialis how to take cialis 20mg tablets cialis canada cialis best time to take cialis everyday dose effectiveness of cialis cialis 20mg tablets is tadalafil the same as cialis proper dosage of cialis how much is a cialis pill cialis used for cialis online buy cialis how much cialis other names for cialis cialis dosage directions for cialis 20mg cialis single use dose order cheap cialis cialis effect on blood pressure