import pytumblr import sys import os from time import sleep from jinja2 import Environment, PackageLoader, select_autoescape import re from urllib.parse import urlparse from pathlib import Path import requests jenv = Environment( loader=PackageLoader("src.prerenders"), autoescape=select_autoescape() ) def progress_bar(iteration, total, prefix='', suffix='', length=30, fill='█'): percent = ("{0:.1f}").format(100 * (iteration / float(total))) filled_length = int(length * iteration // total) bar = fill * filled_length + '-' * (length - filled_length) sys.stdout.write(f'\r{prefix} |{bar}| {percent}% {suffix}') sys.stdout.flush() tokens = [] for envkey in ["TBS_CONSUMER_KEY", "TBS_CONSUMER_SECRET", "TBS_OAUTH_TOKEN", "TBS_OAUTH_SECRET"]: ek = os.environ.get(envkey) if not ek: print(f"missing {envkey} variable, exiting") exit(1) tokens.append(ek) # https://github.com/tumblr/pytumblr?tab=readme-ov-file client = pytumblr.TumblrRestClient( *tokens ) def queue_media_download(data): A = "./src/images" R = r"", post["type"], post.keys()) progress_bar(i, P, prefix='Downloading:', suffix='', length=30) if len(posts["posts"]) < L: break sleep(0.5)