abhiyerra (owner)

Revisions

gist: 199487 Download_button fork
public
Public Clone URL: git://gist.github.com/199487.git
Embed All Files: show embed
posterous_blog.py #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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