Spaces:
Runtime error
Runtime error
from app._config import settings | |
import logging | |
import requests | |
logger = logging.getLogger(__name__) | |
match settings.IMG_DATASET: | |
case "growstuff": | |
global urls, keyword | |
urls = [ | |
"https://www.growstuff.org/harvests.json", | |
"https://www.growstuff.org/crops.json", | |
"https://www.growstuff.org/seeds.json" | |
] | |
keyword = "thumbnail_url" | |
thumbnail_urls = set() | |
for url in urls: | |
response = requests.get(url) | |
if response.status_code == 200: | |
data = response.json()['query'] | |
thumbnail_urls.update(item.get(keyword) for item in data if item and item.get(keyword)) | |
else: | |
logger.info(f"Failed to retrieve data from {url}.") | |
thumbnail_urls = list(thumbnail_urls) | |
with open(f'{settings.LOCAL_DATA_FOLDER}/myimglist.txt', 'w') as file: | |
for url in thumbnail_urls: | |
file.write(url + '\n') | |
logger.info(f"Retrieved {len(thumbnail_urls)} image urls and written to {settings.LOCAL_DATA_FOLDER}/myimglist.txt") | |