removed magic number from pyhton file.

This commit is contained in:
Deniz Erdem 2024-09-25 14:42:05 +02:00
parent 48ee84dd7f
commit 705cb710b3

View file

@ -8,10 +8,12 @@ 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'
MAX_IMAGES = 380 MAX_IMAGES = 380
MIN_AMOUNT_OF_IMAGES = 1
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:
@ -23,10 +25,13 @@ 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():
# Get user input for number of pictures and starting index # Get user input for number of pictures and starting index
num_pictures = await ask_for_valid_number(f'How many pictures would you like to download? (Max: {MAX_IMAGES}) ', 1, MAX_IMAGES) num_pictures = await ask_for_valid_number(f'How many pictures would you like to download? (Max: {MAX_IMAGES}) ',
start_index = await ask_for_valid_number(f'From which picture (index) would you like to start? ', 1, MAX_IMAGES) MIN_AMOUNT_OF_IMAGES, MAX_IMAGES)
start_index = await ask_for_valid_number(f'From which picture (index) would you like to start? ',
MIN_AMOUNT_OF_IMAGES, MAX_IMAGES)
try: try:
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
@ -69,6 +74,7 @@ async def main():
except Exception as e: except Exception as e:
print(f"Error: {str(e)}") print(f"Error: {str(e)}")
async def ask_for_valid_number(prompt, min_value, max_value): async def ask_for_valid_number(prompt, min_value, max_value):
while True: while True:
try: try:
@ -80,6 +86,7 @@ async def ask_for_valid_number(prompt, min_value, max_value):
except ValueError: except ValueError:
print("🚫 Invalid input. Please enter a valid number.") print("🚫 Invalid input. Please enter a valid number.")
def ascii_art(): def ascii_art():
print(""" print("""
/$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$ /$$ /$$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$$
@ -93,6 +100,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)