-
Notifications
You must be signed in to change notification settings - Fork 4
/
Download.py
50 lines (33 loc) · 1.17 KB
/
Download.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from collections import namedtuple
from threading import Thread
import multiprocessing
import requests
import shutil
import json
import os
#---------------------------------------------
#Enter the API URL here:
api_url = "https://nekos.life/api/v2/img/neko"
#---------------------------------------------
def download(url,path):
response = requests.get(url,stream = True)
if response.status_code == 200:
with open(path,"wb") as file:
response.raw.decode_content = True
shutil.copyfileobj(response.raw,file)
print("Sucessfully downloaded " + path)
def neko():
while True:
path = ""
with requests.Session() as session:
response = session.get(api_url)
output = response.text
info = json.loads(output,
object_hook = lambda d : namedtuple('X',d.keys())(*d.values()))
url = info.url
path = url[url.rfind("/") + 1:]
if not os.path.exists(path):
download(url,path);
for i in range(multiprocessing.cpu_count()):
thread = Thread(target = neko)
thread.start()