def processItem(args, contentArgs=None):
blogger = EasyBlogger(args.clientid, args.secret, args.blogid,
args.url)
try:
if args.command == "post":
newPost = blogger.post(args.title,
args.content or args.file,
args.labels,
args.filters,
isDraft=not args.publish,
fmt=args.format)
postId = newPost['id']
logger.debug("Created post: %s", postId)
if contentArgs:
contentArgs.updateFileWithPostId(postId)
print(newPost['url'])
if args.command == 'delete':
logger.debug("Deleting post: %s", args.postIds)
for postId in args.postIds:
blogger.deletePost(postId)
if args.command == 'update':
logger.debug("Updating post: %s", args.postId)
updated = blogger.updatePost(
args.postId,
args.title,
args.content or args.file,
args.labels,
args.filters,
isDraft=not args.publish,
fmt=args.format)
print(updated['url'])
if args.command == "get":
if args.postId:
posts = blogger.getPosts(postId=args.postId)
elif args.query:
posts = blogger.getPosts(
query=args.query,
maxResults=args.count)
elif args.u:
posts = blogger.getPosts(
url=args.u)
else:
posts = blogger.getPosts(
labels=args.labels,
maxResults=args.count)
jobs = [gevent.spawn(printPosts,
item, args.fields, args.doc, args.tofiles)
for item in posts]
gevent.wait(jobs)
except AccessTokenRefreshError:
# The AccessTokenRefreshError exception is raised if the credentials
# have been revoked by the user or they have expired.
print('The credentials have been revoked or expired, please re-run'
' the application to re-authorize')
return -1
return 0
评论列表
文章目录