# Fetch exchange strings behind factoriobin/pastebin links gathered from reddit/forums. argv: links tsv files import sys; sys.path.insert(0, __import__('os').path.dirname(__file__)) from common import * import html as _html from concurrent.futures import ThreadPoolExecutor links = {} for p in sys.argv[1:]: for l in open(p): k, _, v = l.rstrip("\n").partition("\t") links.setdefault(k, v) TRIED = os.environ.get("CACHE", "cache") + "/paste_tried.txt" tried = set(open(TRIED).read().split()) if os.path.exists(TRIED) else set() tf = open(TRIED, "a"); tlock = threading.Lock() def mark(link): with tlock: tf.write(link + "\n"); tf.flush() W = {"factoriobin": Writer("factoriobin"), "pastebin": Writer("pastebin")} def strings(text): out = extract_bps(text) return out or extract_bps(re.sub(r"\s+", "", text)) def one(item): link, via = item if link in tried: return try: fetch(link, via) finally: mark(link) def fetch(link, via): if "factoriobin.com" in link: pid = link.rsplit("/", 1)[1]; w = W["factoriobin"] if pid in w.seen: return page = get(f"https://factoriobin.com/post/{pid}") if not page: return page = page.decode("utf-8", "replace") cdn = re.search(r'https://cdn\.factoriobin\.com/[^"]+-0\.txt', page) or re.search(r'https://cdn\.factoriobin\.com/[^"]+\.txt', page) t = get(cdn.group(0)) if cdn else None m = re.search(r"