Skip to content

Instantly share code, notes, and snippets.

@ewerybody
Last active October 10, 2021 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ewerybody/74c58a19130c764d436bd45332a18a41 to your computer and use it in GitHub Desktop.
Save ewerybody/74c58a19130c764d436bd45332a18a41 to your computer and use it in GitHub Desktop.
exec("import os\nimport time\nimport requests\n\nNAME = 'thispersondoesnotexist'\nURL = f'https://{NAME}.com/image'\nIMG_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), NAME))\nIMG_NAME = 'face_{nr}.jpg'\nNUM_IMG = 5\nRETRIES = 5\nTIMEOUT = 0.1\n\n\ndef main():\n os.makedirs(IMG_DIR, exist_ok=True)\n adds = 0\n img_data = b''\n for i in range(1, NUM_IMG + 1):\n img_data = _get_img(img_data)\n\n try_name = os.path.join(IMG_DIR, IMG_NAME.format(nr=i + adds))\n while os.path.isfile(try_name):\n adds += 1\n try_name = os.path.join(IMG_DIR, IMG_NAME.format(nr=i + adds))\n\n with open(try_name, 'wb') as fobj:\n print('try_name: %s' % try_name)\n fobj.write(img_data)\n time.sleep(TIMEOUT)\n\n\ndef _get_img(img_before):\n img_new = requests.get(URL).content\n for try_nr in range(RETRIES):\n if img_new != img_before:\n print('try_nr: %s' % try_nr)\n return img_new\n time.sleep(TIMEOUT)\n img_new = requests.get(URL).content\n raise RuntimeError(f'Could not get new image from {NAME} after {RETRIES} retries!')\n\n\nif __name__ == '__main__':\n main()")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment