You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.9 KiB

#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <>.
#Copyright (c) 2011 Blagovest Petrov b l a g o v e s t ({ AT ]] p e t r o v s D0T info
import json
import urllib2
import sys
import ConfigParser
import xmlrpclib
from optparse import OptionParser
def get_last_pic(user):
jsonurl = "" + str(user) + "&include_pics=1"
response = urllib2.urlopen(jsonurl)
jsobj = json.loads(
#lastpic = jsobj['value']['users'][0]['last_pic_id']
lastpic = jsobj['value']['users'][0]['pics'][0]['id']
#print lastpic
return lastpic
def write_last_pic(pic):
config = ConfigParser.RawConfigParser()
config.set('pics', 'lastpic', str(pic))
#config.set('pics', 'int', lastpic)
with open('foo.cfg', 'wb') as configfile:
def get_old_pic():
config = ConfigParser.RawConfigParser()'foo.cfg')
return config.get('pics', 'lastpic')
#return config.get('pics', 'int')
def get_pic_info(picid):
jsonurl = "" + str(picid)
#jsonurl = ""
response = urllib2.urlopen(jsonurl)
jsobj = json.loads(
url640 = jsobj['value']['pics'][0]['pic_files']['640r']['img_url']
url320 = jsobj['value']['pics'][0]['pic_files']['320rh']['img_url']
caption = jsobj['value']['pics'][0]['caption']
#placename = jsobj['value']['pics'][0]['place']['id'] ##TODO
rtr = { 'url640' : url640, 'url320' : url320, 'caption' : caption }
return rtr
#picinfo = get_pic_info(45)
#print picinfo['url640']
#print picinfo['url320']
#print picinfo['caption']
def wpost(picurl, title, site, user, passwd):
content = '[caption id="" align="aligncenter" width="640" caption="' + title + '"]<img title="' + title + '" src="' + picurl + '" alt="' + title + '" width="640"height="480" />[/caption]'
server = xmlrpclib.ServerProxy(str(site) + 'xmlrpc.php')
blog_content = { 'title' : title, 'description' : content }
post_id = int(server.metaWeblog.newPost(0, str(user), str(passwd), blog_content,0)), str(user), str(passwd))
def check_pic(pic):
if str(pic) == get_old_pic():
return False
return True
def main():
parser = OptionParser("usage: %prog -wpuser WP_username -wppass WP_password -plzusr picplz_username")
parser.add_option("--wpuser", "--wordpress-username", dest="wpuser", help="Wordpress username")
parser.add_option("--wppass", "--wordpress-password", dest="wppass", help="Wordpress password")
parser.add_option("--plzusr", "--picplz-username", dest="plzusr", help="PizPlz username")
parser.add_option("--wpsite", "--wordpress-site", dest="wpsite", help="Wordpress site URL ( http://myblog.mydomain/ )")
(options, args) = parser.parse_args()
if options.wpuser is None or options.wppass is None or options.wpsite is None or options.plzusr is None :
parser.error("Incorrect number of options")
wpuser = options.wpuser
wppass = options.wppass
wpsite = options.wpsite
plzusr = options.plzusr
lpic = get_last_pic(str(plzusr))
if(check_pic(lpic) == 1):
picinfo = get_pic_info(lpic)
wpost(picinfo['url640'], picinfo['caption'], wpsite, wpuser, wppass)
print "No change"
if __name__ == "__main__":