Made for CGMatter/Default Cube vide: https://youtu.be/emPZiWmGsmg
Last active
October 10, 2021 09:38
-
-
Save ewerybody/74c58a19130c764d436bd45332a18a41 to your computer and use it in GitHub Desktop.
"One line" version of https://gist.github.com/ewerybody/0d9f73fa8d75fddf7c1c96d8bc9fe5b1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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