blob: b8a5d71983f8ec29d6db54f07d018c9cc31f724b (
plain)
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
|
"""
A script to post articles on my blog
"""
import re, sys
from twill import commands as c
IMAGE = re.compile('e::\s+([-+\w\.]+)') # figure/image
def replace_image_links(txt):
"Remove code-block directives and relative images to make Artima happy"
txt = re.sub(r'.. code-block:: \w+', '::', txt)
return IMAGE.sub(r'e:: http://www.phyast.pitt.edu/~micheles/scheme/\1', txt)
if __name__ == '__main__':
try:
rstfile, thread = sys.argv[1:]
except ValueError:
sys.exit('Usage: post <rstfile> <artima-thread-number>')
text = replace_image_links(file(rstfile).read())
c.go('http://www.artima.com/sign_in?d=%2Findex.jsp')
c.formvalue('1', 'username', 'micheles')
c.formvalue('1', 'password', 'pippolippo')
c.submit()
c.go('http://www.artima.com/weblogs/editpost.jsp?thread=%s' % thread)
c.formvalue('1', 'body', text)
c.submit()
|