seamusbarnes commited on
Commit ·
e1cf890
1
Parent(s): 6edfb74
wrote script to download sample images
Browse files- get_images.py +36 -0
get_images.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastbook import *
|
| 2 |
+
|
| 3 |
+
def download_single_image(term, folder, attempts=10):
|
| 4 |
+
|
| 5 |
+
file_path = Path(os.path.join(folder, f'{term}.jpg'))
|
| 6 |
+
urls = search_images_ddg(term, max_images=10)
|
| 7 |
+
for i in range(attempts):
|
| 8 |
+
try:
|
| 9 |
+
download_url(urls[i], file_path, show_progress=False)
|
| 10 |
+
break
|
| 11 |
+
except Exception as e:
|
| 12 |
+
print(f'Error on attempt {i+1}: {e}')
|
| 13 |
+
|
| 14 |
+
if __name__ == '__main__':
|
| 15 |
+
|
| 16 |
+
terms = [
|
| 17 |
+
'sushi',
|
| 18 |
+
'udon',
|
| 19 |
+
'tofu',
|
| 20 |
+
'tempura',
|
| 21 |
+
'ramen',
|
| 22 |
+
'donburi',
|
| 23 |
+
'oden',
|
| 24 |
+
'soba',
|
| 25 |
+
'miso soup',
|
| 26 |
+
'okonomiyaki',
|
| 27 |
+
'gyoza',
|
| 28 |
+
'takoyaki',
|
| 29 |
+
'edamame',
|
| 30 |
+
'yakisoba',
|
| 31 |
+
'chawanmushi',
|
| 32 |
+
'wagashi',
|
| 33 |
+
'sashimi']
|
| 34 |
+
|
| 35 |
+
for term in [terms[-1]]:
|
| 36 |
+
download_single_image(term, 'images2')
|