Skip to content

Instantly share code, notes, and snippets.

@AtomicMaya
Last active August 31, 2021 22:45
from typing import List
import urllib
import requests
from codecs import open
import os
import multiprocess as mp
if not os.path.exists('./results'):
os.makedirs('./results')
attempts = 0
fails = 0
namespace = [str(i) for i in range(10)] + [chr(i) for i in range(97, 123)]
start_value = "c11912"
current_value = start_value
max_value = "1qvc8ny"
url_template = "https://prnt.sc/"
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0'}
search_string = '<meta property="og:image" content="'
end_string = '"/>'
def to_namespace(value: str) -> List[int]:
return [namespace.index(x) for x in value]
def to_str(value: List[int]) -> str:
return "".join([namespace[i] for i in value])
def get_next(value: str) -> str:
ns = to_namespace(value)
pos = -1
while (ns[pos] + 1) % 36 == 0:
ns[pos] = 0
pos -= 1
ns[pos] += 1
return to_str(ns)
def save_image(value: str) -> bool:
print(f"Attempt {value}")
req = urllib.request.Request(url_template + value, headers=headers)
data = urllib.request.urlopen(req).read()
sdata = data.decode('utf-8')
start = sdata.find(search_string) + len(search_string)
if start == -1:
return True
end = sdata.find(end_string, start)
url = sdata[start:end]
img = requests.get(url)
if img.status_code != 200:
return True
img = img.content
img_format = url.split(".")[-1]
with open(f"./results/{value}.{img_format}", "wb") as fh:
fh.write(img)
fh.close()
return False
if __name__ == '__main__':
elements = [current_value]
while len(elements) < 100:
current_value = get_next(current_value)
elements += [current_value]
pool = mp.Pool(5)
results = pool.map(save_image, elements)
print(f"Attempts: {len(results)}")
print(f"Failures: {len(list(filter(lambda x: x, results)))}")
print(f"Success rate: {(len(results) - len(list(filter(lambda x: x, results)))) / len(results)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment