Skip to content

Instantly share code, notes, and snippets.

@abhiyerra
Created October 2, 2009 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhiyerra/199487 to your computer and use it in GitHub Desktop.
Save abhiyerra/199487 to your computer and use it in GitHub Desktop.
python << EOF
# Post to Blog
import vim
import urllib2, urllib
import base64
import markdown2
blog_email = 'my@email.com'
blog_password = 'mYpA$$W0RD'
site_id = "123456"
api_url = 'http://posterous.com/api/newpost'
def post_blog():
title = vim.current.buffer[0]
body = markdown2.markdown('\n'.join(vim.current.buffer[2:]))
params = urllib.urlencode({
'site_id': site_id,
'title': title,
'body': body,
'autopost': '0'
})
req = urllib2.Request(api_url, params)
base64string = base64.encodestring('%s:%s' % (blog_email, blog_password))[:-1]
req.add_header("Authorization", "Basic %s" % base64string)
handle = urllib2.urlopen(req)
print handle.read()
vim.command('set nomodified')
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment