goodmodeler commited on
Commit
ad1b63f
·
1 Parent(s): 952db43

add image download file

Browse files
image_download.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import flickrapi
2
+ import requests
3
+ import os
4
+
5
+ # Your Flickr API credentials
6
+ FLICKR_PUBLIC = '0ff89a88a2a61c24f452774ad32ee62c'
7
+ FLICKR_SECRET = '35c5034466630c82'
8
+
9
+ # Create Flickr API object
10
+ flickr = flickrapi.FlickrAPI(FLICKR_PUBLIC, FLICKR_SECRET, format='parsed-json')
11
+
12
+ # Search for images with relevant tags
13
+ results = flickr.photos.search(
14
+ text='brooklyn advertisement',
15
+ per_page=50,
16
+ media='photos',
17
+ sort='relevance',
18
+ extras='url_o,url_l,url_c,tags',
19
+ content_type=1,
20
+ safe_search=1
21
+ )
22
+
23
+ photos = results['photos']['photo']
24
+
25
+ # Create folder to save images
26
+ # os.makedirs('flickr_brooklyn_ads', exist_ok=True)
27
+
28
+ # Download images
29
+ for i, photo in enumerate(photos):
30
+ url = photo.get('url_o') or photo.get('url_l') or photo.get('url_c')
31
+ if url:
32
+ img_data = requests.get(url).content
33
+ with open(f'nyc_ads_dataset/img_{i}.jpg', 'wb') as handler:
34
+ handler.write(img_data)
35
+ print(f"Downloaded: img_{i}.jpg")
nyc_ads_dataset/001.jpg DELETED
Binary file (869 Bytes)
 
nyc_ads_dataset/002.jpg DELETED
Binary file (942 Bytes)
 
nyc_ads_dataset/003.jpg DELETED
Binary file (957 Bytes)
 
nyc_ads_dataset/004.jpg DELETED
Binary file (1.01 kB)
 
nyc_ads_dataset/005.jpg DELETED
Binary file (976 Bytes)