cleanup + more args

This commit is contained in:
Rdimo
2022-06-03 12:30:58 +02:00
parent a5e1830a97
commit dce633c5ea
3 changed files with 51 additions and 49 deletions

View File

@@ -1,49 +1,31 @@
#how about you import some bitches
import os
# how about you import some bitches
import requests
from os import mkdir, sep
from random import randint
from threading import Thread
from zipfile import ZipFile, ZIP_DEFLATED
api = 'https://api.waifu.pics/nsfw/waifu'
def get(dirr=None):
'''can choose directory name too'''
directory = "bitches"
if dirr:
directory = dirr
try: os.mkdir(directory)
except Exception: pass
for i in range(randint(5, 10)):
Thread(target=bitches, args=(directory, )).start()
def bitches(dir_):
for i in range(randint(3, 7)):
def get(directory="bitches", amount=randint(5, 10)):
'''can choose directory name too'''
try:
mkdir(directory)
except Exception:
pass
for i in range(amount):
Thread(target=bitches, args=(directory, amount)).start()
def bitches(dir_, amount=randint(3, 7)):
for i in range(amount):
req_url = requests.get(api)
url = req_url.json()['url']
if not req_url.ok:
print("error: "+req_url)
with open(dir_+os.sep+url[21:], 'wb') as f:
with open(dir_+sep+url[21:], 'wb') as f:
response = requests.get(url, stream=True)
for block in response.iter_content(1024):
if not block:
break
f.write(block)
def tempDir():
system = os.name
if system == 'nt':
return os.getenv('temp')
elif system == 'posix':
return '/tmp/'
def zipfile(_file):
_zipfile = os.path.join(os.getcwd(), 'bitches.zip')
zipped_file = ZipFile(_zipfile, "w", ZIP_DEFLATED)
abs_src = os.path.abspath(_file)
for dirname, _, files in os.walk(_file):
for filename in files:
absname = os.path.abspath(os.path.join(dirname, filename))
arcname = absname[len(abs_src) + 1:]
zipped_file.write(absname, arcname)
zipped_file.close()