def handle_unauthorized_commands(factory, action): imgur = factory.build_api() req = None if action == 'upload': req = factory.build_request_upload_from_path(sys.argv[2]) res = imgur.retrieve(req) print(res['link']) else: if action == 'list-comments': thash = sys.argv[2] req = factory.build_request(('gallery', thash, 'comments')) if action == 'get-album': id = sys.argv[2] req = factory.build_request(('album', id)) if action == 'get-comment': (thash, cid) = sys.argv[2:4] req = factory.build_request(('gallery', thash, 'comments', cid)) if action == 'get-gallery': imgur = factory.build_api() id = sys.argv[2] req = factory.build_request(('gallery', id)) res = imgur.retrieve(req) print(res)
def handle_authorized_commands(factory, action): token = sys.argv[2] auth = factory.build_oauth(token, None) imgur = factory.build_api(auth) if action == 'upload-auth': path = sys.argv[3] req = factory.build_request_upload_from_path(path) if action == 'comment': thash = sys.argv[3] text = ' '.join(sys.argv[4:]) if len(text) > 140: print("Comment too long (trim by %d characters)." % (len(text) - 140)) sys.exit(1) req = factory.build_request(('gallery', thash, 'comment'), { 'comment': text }) if action == 'vote-gallery' or action == 'vote-comment': (tid, vote) = sys.argv[3:] target = None if action == 'vote-gallery': target = ('gallery', tid, 'vote', vote) else: target = ('comment', tid, 'vote', vote) req = factory.build_request(target) try: res = imgur.retrieve(req) if action == 'upload-auth': print(res['link']) else: if action == 'comment': print("Success! https://www.imgur.com/gallery/%s/comment/%s" % (thash, res['id'])) else: print(res) except expired: print("Expired access token")