forked from chrislkeller/searchstagram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_instagram.py
61 lines (46 loc) · 2.07 KB
/
search_instagram.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from config import config_settings
import logging
from instagram.client import InstagramAPI
logging.basicConfig(level=logging.DEBUG)
def search_instagram(term_to_query, count, latitude, longitude, radius, min_timestamp, max_timestamp):
''' query instagram for images '''
# create a holding container for what the api returns
list_of_images = []
api = InstagramAPI(client_id=config_settings['INSTAGRAM_CLIENT_ID'], client_secret=config_settings['INSTAGRAM_CLIENT_SECRET'])
# search and set to variable
instagram_media = api.media_search(term_to_query, count, latitude, longitude, min_timestamp, max_timestamp)
# loop through what the search returned
for media in instagram_media:
# lets skip anything that doesn't have an address
if media.location.point.latitude is not None and media.location.point.longitude is not None:
latitude = media.location.point.latitude
longitude = media.location.point.longitude
else:
pass
if media.user.username is not None:
user = media.user.username
else:
user = None
if media.user.full_name is not None:
user_full_name = media.user.full_name
else:
user_full_name = None
if media.link is not None:
link = media.link
else:
link = None
if media.images['standard_resolution'].url is not None:
image_source = media.images['standard_resolution'].url
else:
image_source = None
if media.created_time is not None:
time_date = media.created_time
else:
time_date = None
if media.caption is not None:
caption = media.caption.text
else:
caption = None
image_dict = {'result_type': 'instagram', 'user': user, 'user_full_name': user_full_name, 'link': link, 'image_source': image_source, 'caption': caption, 'latitude': latitude, 'longitude': longitude, 'time_date': time_date}
list_of_images.append(image_dict)
return list_of_images