Python Desktop Server has been repeatedly upstreamed two files this evening, wiki/Index.html and wiki/index.html and has failed to upstream a long blog post I made earlier this evening. Earlier it raised a few internal errors while trying to upload postings that had already been deleted:
Background thread exception exceptions.ValueError: Invalid Posting id:
P393Exception instance __dict__: {'args': ('Invalid Posting id: P93',)}
/usr/lib/python2.3/site-packages/PyDS/Tool.py[1300] in thunk
/usr/lib/python2.3/site-packages/PyDS/MirrorTool.py[77] in _initthread
/usr/lib/python2.3/site-packages/PyDS/MirrorTool.py[128] in _addItem
/usr/lib/python2.3/site-packages/PyDS/WeblogTool.py[1165] in getRSSItem
/usr/lib/python2.3/site-packages/PyDS/WeblogTool.py[889] in getPost
The way upstreaming works has a feel of something beyond my control where I have to cross my fingers and hope and wait patiently and keep refreshing the cloud until my changes appear.
|
As promised, how to do photo blogging from mobile phone. Actually this should support submitting plain text blog posts from any email source as I want to use the same mechanism to post blog entries from work that are for public display, bypassing the firewall. This recipe works with UK O2 MMS messages.
The first line of text in the email message becomes the title of the post, the following lines become the body.
Requirements:
Exim (or any MTA that supports forward files)
Python Desktop Server (or any server that supports MetaWeblogAPI or Blogger API, although you have to hack the image upload yourself, depending on the server).
Python (or you can rewrite it all in some other language)
Exim has to be set up to allow .forward files to process email. The .forward file should look like this:
# Exim filter
logfile ~/.forward.log
if $header_subject is "Multimedia message"
then
pipe "/home/me/MailBot.py"
seen finish
endif
This will direct emails with this subject line (i.e. UK O2 MMS messages) to the python script that does the hard work. This script is as follows and has to be made executable by the exim process:
import smtplib
import sys
import email
import xmlrpclib
strMobileNumber = "0123456"
strXMLRPCUser = "fred"
strXMLRPCPassword = "xxx"
strMsg = ""
for strLine in sys.stdin.readlines():
strMsg += strLine
oEmail = email.message_from_string( strMsg)
if not( oEmail['from'].find( strMobileNumber) >= 0:
sys.exit()
body = ""
strImages = []
for oPart in oEmail.walk():
if oPart.get_content_type() == 'text/plain':
if oPart.is_multipart() == False:
strPart = oPart.get_payload( decode=True)
if strPart.find( "This is a Media Message from O2") >= 0:
continue
body += strPart
if oPart.get_content_type() == 'image/jpeg':
strImage = oPart.get_payload( decode=True)
strFileName = oPart['Content-Location']
open( '/home/me/.PyDS/www/images/' + strFileName, 'wb').write( strImage)
strImages.append( "$macros.imageTag( 'images/%s')\n" % strFileName)
strBody = body.split( '\n')
strTitle = strBody[0]
strBody = "".join( strImages) + "\n".join( strBody[1:])
oPyDS = xmlrpclib.ServerProxy( 'http://localhost:4334/RPC2')
oPosts = oPyDS.metaWeblog.getRecentPosts( '', strXMLRPCUser, strXMLRPCPassword, 1000)
oExistingPosts = {}
for oPost in oPosts:
oExistingPosts[oPost['title']] = oPost['postid']
oPost['title'] = unicode( strTitle, 'ISO-8859-1')
oPost['description'] = unicode( strBody, 'ISO-8859-1')
if not oExistingPosts.has_key( strTitle):
oPyDS.metaWeblog.newPost( '', strXMLRPCUser, strXMLRPCPassword, oPost, 1)
else:
oPyDS.metaWeblog.editPost( oExistingPosts[strTitle], strXMLRPCUser, strXMLRPCPassword, oPost, 1)
I had to make a small hack in Python Desktop Server. Posted articles default to either raw html or strict structured text but the image link requires structured text + cheetah. I had to edit the file MetaWebWeblogAPI.py to change the two lines that said:
structured = 2
to
structured = 1
ToDo:
|