def run(argv): args = _get_cli_args(argv) if args.debug: import logging logging.basicConfig(level=logging.DEBUG, format='%(module)s: %(message)s') # Read files from arguments and from stdin files = [] if not sys.stdin.isatty(): files.extend(f.rstrip('\n') for f in sys.stdin.readlines()) if args.files != ['-']: files.extend(args.files) gallery = pyimgbox.Gallery(title=args.title, adult=args.adult, thumb_width=args.thumb_width, square_thumbs=args.square_thumbs, comments_enabled=args.comments) try: if args.json: exitcode = _json_output(gallery, files) else: exitcode = _text_output(gallery, files) except RuntimeError as e: exitcode = 100 print(''.join(traceback.format_tb(e.__traceback__)), file=sys.stderr) print('Please report this as a bug: ' 'https://github.com/plotski/pyimgbox/issues', file=sys.stderr) return exitcode
async def example2(filepaths): gallery = pyimgbox.Gallery(title="Hello, World!") try: async for submission in gallery.add(filepaths): print(submission) finally: await gallery.close()
async def example1(filepaths): async with pyimgbox.Gallery(title="Hello, World!") as gallery: async for submission in gallery.add(filepaths): if not submission['success']: print(f"{submission['filename']}: {submission['error']}") else: print(submission)
async def _upload_photo_to_imgbox(self, file_path: str) -> str: async with pyimgbox.Gallery(title="parkun_by_bot") as gallery: submission = await gallery.upload(file_path) if submission.get("success", False): return submission.get("image_url", "") else: return ""
async def example3(filepaths): async with pyimgbox.Gallery(title="Hello, World!") as gallery: try: await gallery.create() except ConnectionError as e: print('Gallery creation failed:', str(e)) else: print('Gallery URL:', gallery.url) print(' Edit URL:', gallery.edit_url) async for submission in gallery.add(filepaths): print(submission)
async def imgbox_upload(list_of_filepath): async with pyimgbox.Gallery(title=torrent_title, thumb_width=350) as gallery: async for submission in gallery.add(list_of_filepath): if not submission['success']: logging.error( f"{submission['filename']}: {submission['error']}") else: thumbs_links_dict[submission[ "thumbnail_url"]] = submission["web_url"] if submission["edit_url"] not in edit_url: edit_url.append(submission["edit_url"])
async def up_imgbox(file_paths, gallery_name): img_bbcode = [] async with pyimgbox.Gallery(title=gallery_name) as gallery: gallery.thumb_width = 350 async for submission in gallery.add(file_paths): if not submission['success']: print(f"{submission['filename']}: {submission['error']}") else: print(submission) img_bbcode.append( '[url=%s][img]%s[/img][/url]' % (submission['web_url'], submission['thumbnail_url'])) return img_bbcode
async def run(args): args = _input.get_args(args) if args.debug: import logging logging.basicConfig(level=logging.DEBUG, format='%(module)s: %(message)s') exit_code = 0 try: files = _input.get_files(args) except ValueError as e: print(e, file=sys.stderr) exit_code = 1 else: gallery = pyimgbox.Gallery( title=args.title, adult=args.adult, thumb_width=args.thumb_width, square_thumbs=args.square_thumbs, comments_enabled=args.comments, ) if args.json: create_output = _output.json elif args.bbcode: create_output = _output.bbcode else: create_output = _output.text async with gallery: try: exit_code = await create_output(gallery, files) except Exception as e: exit_code = 100 tb = ''.join(traceback.format_exception(type(e), e, e.__traceback__)) print( f'{tb}\nPlease report this as a bug: {__bugtracker_url__}', file=sys.stderr, ) return exit_code
async def example4(filepaths): async with pyimgbox.Gallery(title="Hello, World!") as gallery: submission1 = await gallery.upload(filepaths[0]) submission2 = await gallery.upload(filepaths[1]) submission3 = await gallery.upload(filepaths[2]) print('Submissions:', submission1, submission2, submission3)