-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlamem-instagram.py
47 lines (31 loc) · 2.03 KB
/
lamem-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
import urllib2 # synchronous http loading
import json
import datetime
# this url returns a JSON of the most recent 20 images/videos. results variable should parse the "items" key
instagramURL = "https://www.instagram.com/taylorswift/media/"
# below are alternate URL forms that get previous images. results variable should parse the "data" key
#instagramURL = "https://api.instagram.com/v1/users/11830955/media/recent?access_token=2912979.87fdd31.0949d22f4a714349ae84643c5af165ef&max_id=1088060304040849874_11830955"
#instagramURL = "https://api.instagram.com/v1/users/11830955/media/recent?access_token=2912979.87fdd31.0949d22f4a714349ae84643c5af165ef&max_id=1078363953501761596_11830955"
#instagramURL = "https://api.instagram.com/v1/users/11830955/media/recent?access_token=2912979.87fdd31.0949d22f4a714349ae84643c5af165ef&max_id=1060697492037759175_11830955"
#instagramURL = "https://api.instagram.com/v1/users/11830955/media/recent?access_token=2912979.87fdd31.0949d22f4a714349ae84643c5af165ef&max_id=1050221392618779437_11830955"
instagramURL = "https://api.instagram.com/v1/users/11830955/media/recent?access_token=2912979.87fdd31.0949d22f4a714349ae84643c5af165ef&max_id=1041378278638547805_11830955"
memScoreBaseURL = "http://memorability.csail.mit.edu/cgi-bin/image.py?url="
req = urllib2.Request(instagramURL)
response = urllib2.urlopen(req)
results = json.loads(response.read())["data"]
for i in range(0, len(results)):
# skip videos
isVideo = results[i].get("videos", False)
if isVideo != False:
continue # skip!
# get photo stuff
imageURL = results[i]["images"]["standard_resolution"]["url"]
likes = results[i]["likes"]["count"]
memScoreURL = memScoreBaseURL + imageURL
createdTime = results[i]["created_time"]
printedTime = datetime.datetime.fromtimestamp(int(createdTime)).strftime('%Y-%m-%d %H:%M:%S')
# fetch memscore
req = urllib2.Request(memScoreURL)
response = urllib2.urlopen(req)
memScoreResults = json.loads(response.read())
print printedTime + ", " + imageURL + ", " + str(likes) + ", " + str(memScoreResults["memscore"])