failure = True except api.Unauthorized as E: #we don't have access token if not params.quiet: print >>stderr, '#{id}: access denied to blog {blog}'.format(id=id, blog=params.blog) failure = True except api.Error as E: #I just don't know what went wrong! if not params.quiet: print >>stderr, '#{id}: {msg}'.format(id=id, msg=E.message) failure = True else: #Everything is fine failure = False if failure and (params.outcome=='fail'): #if something bad happened and we must fail exit(1) # then we fail. elif (not failure or (params.outcome=='ignore')) and \ (not params.editonly or changed): print >>stdout, params.format(post) # # if __name__=='__main__': parser = makeParser() params = parser.parse_args(args.decode_argv()[1:]) if params.useregexp: #preprocessing find-replace patterns if necessary params.body = makeRegexp(params.body) params.title = makeRegexp(params.title) if params.id=='-': ids = stdin else: ids = (params.id,) editPosts(params, ids) exit(0)
except NoMoreMatchesExpected: break # # except api.NotFound as E: if (params.id is not None): raise api.NotFound("post #{id}".format(id=params.id)) else: raise # # if __name__=='__main__': parser = makeParser() params = parser.parse_args(args.decode_argv()[1:]) #parsing CLI arguments (converted into unicode) try: posts = retrievePosts(params) #iterator over retrieved posts for post in posts: #post['tags'] = u','.join(post['tags']) print >>stdout, params.format(post) #formatting each post and printing it to stdout, duh. except api.NotFound as E: #raised if blog or post with specified ID was not found. if not params.quiet: print >>stderr, "404 Not Found: "+E.message exit(1) except api.Error as E: #raised if something else happened to API. if not params.quiet: print >>stderr, "Tumblr API error: "+E.message exit(1) else: #Everything is fine, we can finish now exit(0)