Mercurial > hg > bitsyblog
comparison bitsyblog/blogme.py @ 92:bc1753ff9b8b
i hate software
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 11 Feb 2013 13:38:10 -0800 |
parents | 3da163e44b8a |
children | 5c04cf601aba |
comparison
equal
deleted
inserted
replaced
91:56ac8bd08fa0 | 92:bc1753ff9b8b |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 """ | 2 """ |
3 command line blogger | 3 command line blogger |
4 """ | 4 """ |
5 | 5 |
6 import datetime | |
6 import optparse | 7 import optparse |
7 import os | 8 import os |
8 import subprocess | 9 import subprocess |
9 import sys | 10 import sys |
10 import tempfile | 11 import tempfile |
142 for i in range(attempts): | 143 for i in range(attempts): |
143 try: | 144 try: |
144 connection = urllib2.urlopen(url, data=msg) | 145 connection = urllib2.urlopen(url, data=msg) |
145 print connection.url # print the blog post's url | 146 print connection.url # print the blog post's url |
146 break | 147 break |
147 except (urllib2.HTTPError, urllib2.URLError), e: | 148 except (urllib2.HTTPError, urllib2.URLError, socket.error), e: |
148 continue | 149 continue |
150 except: | |
151 print >> sys.stderr, "An error has occured:" | |
152 print >> sys.stderr, sys.exc_info() # XXX pretty crappy | |
153 break | |
149 else: | 154 else: |
155 with file('blog-%s.txt' % datetime.datetime.now().strftime("%Y%m%d"), 'w') as f: | |
156 f.write(msg) | |
150 print >> sys.stderr, e | 157 print >> sys.stderr, e |
151 print msg | 158 print msg |
152 | 159 |
153 if __name__ == '__main__': | 160 if __name__ == '__main__': |
154 main() | 161 main() |