mirror of
https://github.com/nadimkobeissi/mkbsd.git
synced 2024-12-23 03:05:31 +00:00
check if file already exists before downloading
This commit is contained in:
parent
82e50c64f0
commit
7978628708
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
.DS_Store
|
.DS_Store
|
||||||
downloads
|
downloads
|
||||||
|
/mkbsdvenv/
|
||||||
|
|
9
mkbsd.py
9
mkbsd.py
|
@ -5,11 +5,14 @@ import time
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import asyncio
|
import asyncio
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
url = 'https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s'
|
url = 'https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s'
|
||||||
|
|
||||||
|
|
||||||
async def delay(ms):
|
async def delay(ms):
|
||||||
await asyncio.sleep(ms / 1000)
|
await asyncio.sleep(ms / 1000)
|
||||||
|
|
||||||
|
|
||||||
async def download_image(session, image_url, file_path):
|
async def download_image(session, image_url, file_path):
|
||||||
try:
|
try:
|
||||||
async with session.get(image_url) as response:
|
async with session.get(image_url) as response:
|
||||||
|
@ -21,6 +24,7 @@ async def download_image(session, image_url, file_path):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error downloading image: {str(e)}")
|
print(f"Error downloading image: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
|
@ -48,6 +52,9 @@ async def main():
|
||||||
filename = f"{file_index}{ext}"
|
filename = f"{file_index}{ext}"
|
||||||
file_path = os.path.join(download_dir, filename)
|
file_path = os.path.join(download_dir, filename)
|
||||||
|
|
||||||
|
if os.path.exists(file_path):
|
||||||
|
print(f"⚠️ File {file_path} already exists. Skipping download.")
|
||||||
|
else:
|
||||||
await download_image(session, image_url, file_path)
|
await download_image(session, image_url, file_path)
|
||||||
print(f"🖼️ Saved image to {file_path}")
|
print(f"🖼️ Saved image to {file_path}")
|
||||||
|
|
||||||
|
@ -57,6 +64,7 @@ async def main():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {str(e)}")
|
print(f"Error: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
def ascii_art():
|
def ascii_art():
|
||||||
print("""
|
print("""
|
||||||
/$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$
|
/$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$
|
||||||
|
@ -70,6 +78,7 @@ def ascii_art():
|
||||||
print("")
|
print("")
|
||||||
print("🤑 Starting downloads from your favorite sellout grifter's wallpaper app...")
|
print("🤑 Starting downloads from your favorite sellout grifter's wallpaper app...")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
ascii_art()
|
ascii_art()
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
Loading…
Reference in a new issue