-
Notifications
You must be signed in to change notification settings - Fork 4
/
flickr_GetUrl.py
37 lines (37 loc) · 1.15 KB
/
flickr_GetUrl.py
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
36
37
from flickrapi import FlickrAPI
import pandas as pd
import sys
key=''
secret=''
def get_urls(image_tag,MAX_COUNT):
flickr = FlickrAPI(key, secret)
photos = flickr.walk(text=image_tag,
tag_mode='all',
tags=image_tag,
extras='url_o',
per_page=50,
sort='relevance')
count=0
urls=[]
for photo in photos:
if count< MAX_COUNT:
count=count+1
print("Fetching url for image number {}".format(count))
try:
url=photo.get('url_o')
urls.append(url)
except:
print("Url for image number {} could not be fetched".format(count))
else:
print("Done fetching urls, fetched {} urls out of {}".format(len(urls),MAX_COUNT))
break
urls=pd.Series(urls)
print("Writing out the urls in the current directory")
urls.to_csv(image_tag+"_urls.csv")
print("Done!!!")
def main():
tag=sys.argv[1]
MAX_COUNT=int(sys.argv[2])
get_urls(tag,MAX_COUNT)
if __name__=='__main__':
main()