Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if file already exists before downloading #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
downloads
/mkbsdvenv/
15 changes: 12 additions & 3 deletions mkbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import aiohttp
import asyncio
from urllib.parse import urlparse

url = 'https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s'


async def delay(ms):
await asyncio.sleep(ms / 1000)


async def download_image(session, image_url, file_path):
try:
async with session.get(image_url) as response:
Expand All @@ -21,6 +24,7 @@ async def download_image(session, image_url, file_path):
except Exception as e:
print(f"Error downloading image: {str(e)}")


async def main():
try:
async with aiohttp.ClientSession() as session:
Expand All @@ -29,7 +33,7 @@ async def main():
raise Exception(f"⛔ Failed to fetch JSON file: {response.status}")
json_data = await response.json()
data = json_data.get('data')

if not data:
raise Exception('⛔ JSON does not have a "data" property at its root.')

Expand All @@ -48,15 +52,19 @@ async def main():
filename = f"{file_index}{ext}"
file_path = os.path.join(download_dir, filename)

await download_image(session, image_url, file_path)
print(f"🖼️ Saved image to {file_path}")
if os.path.exists(file_path):
print(f"⚠️ File {file_path} already exists. Skipping download.")
else:
await download_image(session, image_url, file_path)
print(f"🖼️ Saved image to {file_path}")

file_index += 1
await delay(250)

except Exception as e:
print(f"Error: {str(e)}")


def ascii_art():
print("""
/$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$
Expand All @@ -70,6 +78,7 @@ def ascii_art():
print("")
print("🤑 Starting downloads from your favorite sellout grifter's wallpaper app...")


if __name__ == "__main__":
ascii_art()
time.sleep(5)
Expand Down