-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmlg.instagram.dataset.py
45 lines (37 loc) · 1.15 KB
/
mlg.instagram.dataset.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
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>
import requests
import simplejson as json
import time
from datetime import datetime
from config import c_id
count = 33 # this much works
# desired tag
tag = "igers"
# request scheme for recent media per igers tag
request_url = 'https://api.instagram.com/v1/tags/{}/media/recent?count={}&client_id={}'.format(tag, count, c_id)
file_name = "./results/instagram-tags-landscape-{0}.json"
image_count = 0
iteration = 0
max_image_count = 1000 * 1000
image_ids = []
# <codecell>
r = requests.get(request_url)
while image_count < max_image_count:
print "Iteration {0} | Photo count {1}".format(iteration, image_count)
if r.status_code != 200:
print(r)
result = r.json()
data = result['data']
for image in data:
image_ids.append(image['id'])
pagination = result['pagination']
f = open(file_name.format(iteration), 'w' )
f.write(json.dumps(result))
f.close()
image_count = len(set(image_ids))
time.sleep(1)
r = requests.get(pagination['next_url'])
iteration = iteration + 1
print "Iteration {0} | Photo count {1}".format(iteration, image_count)