-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_files.py
More file actions
37 lines (32 loc) · 1.43 KB
/
fetch_files.py
File metadata and controls
37 lines (32 loc) · 1.43 KB
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
import requests
import os
def download_file(url, filename, datatype):
response = requests.get(url, stream=True)
if response.status_code == 200:
with open(filename, 'wb') as f:
for chunk in response.iter_content(1024):
f.write(chunk)
else:
print(f"Failed to download {datatype} from {url}")
def fetch_files(latest, datatype="images"):
script_dir = os.path.dirname(os.path.abspath(__file__))
images_dir = os.path.join(script_dir, datatype)
os.makedirs(images_dir, exist_ok=True) # Create files directory if needed
skipped_days = []
print(f"Fetching {datatype}...")
extension = "jpg" if datatype == "images" else "mp4"
for day in range(1, latest):
path = os.path.join(images_dir, f"{day:04d}.{extension}")
if os.path.exists(path):
skipped_days.append(day)
continue
if datatype == "images":
file_url = f"https://basepaint.xyz/api/art/image?day={day}" # jpg image 2560x2560
# available in png at lower res too at https://basepaint.net/v3/{day:04d}.png
elif datatype == "videos":
file_url = f"https://basepaint.net/animations/{day:04d}.{extension}"
download_file(file_url, path, datatype)
if day % 10 == 0:
print(f"Downloading {datatype} {day}")
print(f"Skipped days (already downloaded): {skipped_days}")
print(f"Finished downloading {datatype}.")