#!/usr/bin/python -tt wordpress = 'http://skvidal.wordpress.com/xmlrpc.php' # your xmlrpc posting location user = 'skvidal' # your username password = 'password' # your password feedfile = '/home/skvidal/myfeeds.txt' # txt file with one rss/atom feed per line # svn checkout http://wordpress-library.googlecode.com/svn/trunk/ wordpress-library wplibpath='/home/skvidal/tmp/wordpress-library' read_dir = '/tmp/wherever' import sys sys.path.append(wplibpath) import os, os.path import re import wordpresslib import feedparser wp = wordpresslib.WordPressClient(wordpress, user, password) def submit_to_blog(wp, title, description, categories=[]): """submits the entry to the named blog as a draft, returns postid""" wp.selectBlog(0) post = wordpresslib.WordPressPost() post.title = title post.description = description # TODO do something with categories here return wp.newPost(post, False) def is_seen(uid): uid_name = uid.replace('/','_') uid_name = uid_name.replace('http:__', '') uid_name = uid_name.replace('https:__', '') uid_name = read_dir + '/' + uid_name if os.path.exists(uid_name): return True return False def mark_as_seen(uid): uid_name = uid.replace('/','_') uid_name = uid_name.replace('http:__', '') uid_name = uid_name.replace('https:__', '') uid_name = read_dir + '/' + uid_name if not os.path.exists(read_dir): os.makedirs(read_dir) f = open(uid_name, 'w') f.flush() f.close() feeds = open(feedfile, 'r') feedlist = [] for line in feeds.readlines(): if re.match('^\s*\#.*', line) or re.match('^\s*$', line): continue feedlist.append(line) for feed in feedlist: print 'Looking at %s' % feed f = feedparser.parse(feed) for item in f['entries']: if is_seen(item.id): continue print 'post from %s about %s' % (item.author_detail.name, item.title) num = submit_to_blog(wp, item.title, item.description) print ' Blog id num %s' % num mark_as_seen(item.id)