Spaces:
Running
Running
File size: 953 Bytes
ad1b63f c269ab0 ad1b63f |
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 31 32 33 34 35 |
import flickrapi
import requests
import os
# Your Flickr API credentials
FLICKR_PUBLIC = '0ff89a88a2a61c24f452774ad32ee62c'
FLICKR_SECRET = '35c5034466630c82'
# Create Flickr API object
flickr = flickrapi.FlickrAPI(FLICKR_PUBLIC, FLICKR_SECRET, format='parsed-json')
# Search for images with relevant tags
results = flickr.photos.search(
text='advertisement',
per_page=50,
media='photos',
sort='relevance',
extras='url_o,url_l,url_c,tags',
content_type=1,
safe_search=1
)
photos = results['photos']['photo']
# Create folder to save images
# os.makedirs('flickr_brooklyn_ads', exist_ok=True)
# Download images
for i, photo in enumerate(photos):
url = photo.get('url_o') or photo.get('url_l') or photo.get('url_c')
if url:
img_data = requests.get(url).content
with open(f'nyc_ads_dataset/img_{i}.jpg', 'wb') as handler:
handler.write(img_data)
print(f"Downloaded: img_{i}.jpg") |