Last active
September 29, 2015 20:33
-
-
Save hancush/eb603da6c26e2aecd0e7 to your computer and use it in GitHub Desktop.
attempts to bypass instagram's 20 posts per request by automatically cycling through until it reaches given min timestamp (24 hours prior @ time of posting). also attempts to bypass shitty python api wrapper by manually calling the api and extracting the timestamp of the last post in each batch. for some reason, getting caught in an infinite loo…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib2 import urlopen | |
import datetime | |
from instagram.client import InstagramAPI | |
import six | |
api = InstagramAPI( | |
client_id='adeb7a8be4d0463b8bae5e12df37145e', | |
client_secret='428e9e381d3e4a9298a307fd322aaf24', | |
access_token='181028960.adeb7a8.43b0ef71f8df44cda7e75c6e10740672' | |
) | |
day_count = 0 | |
def search(max_timestamp): | |
global more_media | |
more_media = api.media_search( | |
lat='13.7246005', | |
lng='100.6331108', | |
max_timestamp=max_timestamp | |
) | |
def count(collection): | |
for img in collection: | |
global day_count | |
day_count += 1 | |
print "Found {0} photos so far...".format(day_count) | |
def mark(): | |
print "Last get created " + ( | |
datetime.datetime.fromtimestamp( | |
max_timestamp | |
).strftime('%Y-%m-%d %H:%M:%S') | |
) | |
def get_data(collection): | |
last = collection[-1] | |
label, value = str(last).split() | |
last_data = urlopen( | |
'https://api.instagram.com/v1/media/{0}?access_token=181028960.adeb7a8.43b0ef71f8df44cda7e75c6e10740672'.format(value) | |
) | |
for page in last_data: | |
start_value = page.find('created_time') + 15 | |
end_value = start_value + 10 | |
global max_timestamp | |
max_timestamp = int(page[start_value:end_value]) | |
# START # | |
recent_media = api.media_search( | |
lat='13.7246005', | |
lng='100.6331108' | |
) | |
count(recent_media) | |
get_data(recent_media) | |
# LOOP # | |
for trial in range(1,100): | |
if max_timestamp > 1443454200: | |
search(max_timestamp) | |
count(more_media) | |
get_data(more_media) | |
mark() | |
else: | |
break | |
# END # | |
week_count = day_count * 7 | |
print "{0} photos total found in the last 24 hours. That's {1} in a week.".format( | |
day_count, | |
week_count | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment