A while back I toyed with de.lirio.us for my link blog. I pulled the feed and transformed it into html. I used the html from my blog so it would have the same look. I was becoming less satisfied with de.lirio.us and started itching to use del.icio.us instead. I thought I could pull the feed and post each item to a real wordpress blog by dropping the data into the database. My solution is not pretty, but it works. I run a cron job daily to do the ‘pull and post.’I like it. I’ve poste the code in case you’re interested.—linkblog.py—#!/usr/bin/pythonimport time, os, sysWP_POST_PL=”"”#!/usr/bin/perluse strict;use LWP 5.64;use HTTP::Cookies;my $href=shift @ARGV;my $title=shift @ARGV;my $body=shift @ARGV;my $content=”$body<br /><br /><a href=\\\”$href\\\”>$href</a>”;my $browser = LWP::UserAgent->new;$browser->cookie_jar(HTTP::Cookies->new( ’file’ => ’cookies.lwp’, ’autosave’ => 1,));my $url=’http://bsoist.geexfiles.com/links/wp-admin/post.php’;my $response = $browser->post( $url, [ 'post_title' => $title, 'content' => $content, 'user_ID' => '1', 'action' => 'post', 'post_pingback' => '1', 'publish' => 'publish', 'trackback_url' => $href, 'referredby' => 'http%3A%2F%2Fbsoist.geexfiles.com%2Flinks%2Fwp-admin%2F',"""class WPpost: def __init__(self): self.wp_post_pl=WP_POST_PL def parse_post(self, postline): postparts=[] for piece in postline.split(’='): postparts.append(piece.split(’” ’)[0][1:]) self.href=postparts[1] self.title=postparts[2] self.body=postparts[3] self.cats=postparts[6].split() def parse_cats(self): self.postcats=[] self.addcats=” for cat in self.cats: if cat not in self.allcats: if not self.addcats: self.addcats=’./wp-addcats.pl ’ self.addcats+=’%s ’ % cat self.allcats.append(cat) self.nextcat+=1 self.postcats.append(self.nextcat) else: self.postcats.append(self.allcats.index(cat)) def post_to_blog(self, postline): self.parse_post(postline) self.parse_cats() if self.addcats: print ”Running” print self.addcats os.system(self.addcats) perlfile=open(’wp-post.pl’,'w+’) perlfile.write(self.wp_post_pl) for part in self.postcats: perlfile.write(”"” ’post_category[]‘ => ’%s’, ”"” % part) perlfile.write(’]);’) perlfile.close() command=”./wp-post.pl %s ’%s’ ’%s’ ” % (self.href, self.title, self.body) print ”Running” print command os.system(command) try: mydate=sys.argv[1]except: mydate=time.strftime(’%Y-%m-%d’,time.localtime(time.time()-72000))command=’./linkblog.pl ’+mydate+’ >linkblog.txt’print ”Running”print commandos.system(command)lines=open(’linkblog.txt’).readlines()catinfo=lines.pop().split()nextcatnumber=len(catinfo)cats=['']*(nextcatnumber+1)for part in catinfo: place,value=part.split(’-') cats[int(place)]=valueprint catsfor line in lines[2:-2]: wppost=WPpost() wppost.allcats=cats wppost.nextcat=nextcatnumber wppost.post_to_blog(line)—linkblog.pl—#!/usr/bin/perluse strict;use LWP 5.64;use HTTP::Cookies;my $date=shift @ARGV;my $browser = LWP::UserAgent->new;$browser->credentials( ’del.icio.us:80′, ’del.icio.us API’, ’USERID’ => ’PASSWORD’);my $url = ’http://del.icio.us/api/posts/get?dt=’ . $date;my $response = $browser->get($url);die ”Error: ”, $response->header(’WWW-Authenticate’) || ’Error accessing’, ”\n”, $response->status_line, ”\n at $url\n Aborting” unless $response->is_success;my $browser = LWP::UserAgent->new;$browser->cookie_jar(HTTP::Cookies->new( ’file’ => ’cookies.lwp’, ’autosave’ => 1,));my $url = ’http://bsoist.geexfiles.com/links/wp-login.php’;my $newresponse = $browser->post( $url, [ 'log' => 'admin', 'pwd' => 'sqlpassword', ]);my $browser = LWP::UserAgent->new;$browser->cookie_jar(HTTP::Cookies->new( ’file’ => ’cookies.lwp’, ’autosave’ => 1,));my $newresponse = $browser->get(’http://bsoist.geexfiles.com/links/wp-admin/mycats.php’);print $response->content;print $newresponse->content;print ”\n”;—wp-addcats.pl—#!/usr/bin/perluse strict;use LWP 5.64;use HTTP::Cookies;foreach my $cat (@ARGV) {my $browser = LWP::UserAgent->new;$browser->cookie_jar(HTTP::Cookies->new( ’file’ => ’cookies.lwp’, ’autosave’ => 1,));my $url=’http://bsoist.geexfiles.com/links/wp-admin/categories.php’;my $response = $browser->post( $url, [ 'cat_name' => $cat, 'cat' => '0', 'action' => 'addcat', 'category_description' => '', 'referredby' => 'http%3A%2F%2Fbsoist.geexfiles.com%2Flinks%2Fwp-admin%2F' ]);}
[powered by WordPress.]
22 queries. 4.802 seconds