civitai-stable-diffusion-2.5m / download_civitai.py
hanruijiang's picture
upload scripts
63839d2
raw
history blame contribute delete
990 Bytes
import requests
import json
import time
from tqdm.auto import tqdm
proxies = {
'http': 'http://localhost:7890',
'https': 'http://localhost:7890'
}
headers = {'Content-Type': 'application/json'}
url = 'https://civitai.com/api/v1/images'
results = list()
tbar = tqdm()
wait_time = 2
flag = True
while flag:
try:
# data = requests.get(url, proxies=proxies)
data = requests.get(url)
data = json.loads(data.content)
url = data['metadata'].get('nextPage')
except KeyboardInterrupt:
break
except:
wait_time = min(60, wait_time * 2)
time.sleep(wait_time)
continue
if url == None: break
items = data['items']
# now do whatever you want with data
wait_time = 2
time.sleep(wait_time)
results.extend(items)
tbar.update()
with open('../dataset/scrap/civitai-2023-11-14.jsonl', 'wt') as f:
for i in tqdm(results):
f.write(json.dumps(i) + '\n')