Spaces:
Runtime error
Runtime error
File size: 1,009 Bytes
b1fe073 |
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 |
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")
|