/
Clicktrip.py
74 lines (50 loc) · 1.96 KB
/
Clicktrip.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
62
63
64
65
66
67
68
69
70
71
72
73
74
from bottle import route, run, template, redirect, request, response
from config import InstagramConfig
import requests
import json
from flickr import Flickr
from instagram import Instagram
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
@route('/getimage/<location>/<service>')
@route('/getimage/<location>')
def getImage(location, service='flickr'):
returnJson = {}
print(" 1. my token is " + request.get_cookie("insta_auth_token"))
if service == 'flickr':
ps = Flickr()
elif service == 'insta':
ps = Instagram()
print("2. my token is " + request.get_cookie("insta_auth_token"))
print("GETTING SHIT")
ps.photo_lookup(location)
print(" 3. my token is " + request.get_cookie("insta_auth_token"))
photo = ps.get_next_photo()
print(" 4. my token is " + request.get_cookie("insta_auth_token"))
print(photo)
return json.dumps(photo)
@route('/instagram/authenticate')
def authenticate_instagram_callback():
Instagram().auth()
#@route('/instagram/authenticate/callback')
def authenticate_instagram_callback():
auth_code = request.query['code']
payload = {
'client_id': InstagramConfig.CLIENT_ID,
'client_secret': InstagramConfig.CLIENT_SECRET,
'grant_type': 'authorization_code',
'redirect_uri': InstagramConfig.REDIRECT_URL,
'code': auth_code
}
r = requests.post(InstagramConfig.ACCESS_TOKEN_API, payload)
access_token = r.json()['access_token']
# return InstagramConfig.SEARCH_BY_TAG_API.format(tag='sydney', access_token=access_token)
r = requests.get(InstagramConfig.SEARCH_BY_TAG_API.format(tag='sydney', access_token=access_token))
media = r.json()['data']
images = []
for item in media:
images.append(item['images']['standard_resolution']['url'])
response.content_type = 'application/json'
return json.dumps(images)
run(host='localhost', port=8080)