Skip to content

Commit

Permalink
Merge pull request facebookarchive#122 from vipul-sharma20/my_branch
Browse files Browse the repository at this point in the history
removed extra whitespaces
  • Loading branch information
heatonjb committed Apr 27, 2015
2 parents b9b1eb5 + b48f6c2 commit 8779a56
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions sample_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,23 @@ def home():
except Exception as e:
print(e)

def get_nav():
def get_nav():
nav_menu = ("<h1>Python Instagram</h1>"
"<ul>"
"<li><a href='/recent'>User Recent Media</a> Calls user_recent_media - Get a list of a user's most recent media</li>"
"<li><a href='/user_media_feed'>User Media Feed</a> Calls user_media_feed - Get the currently authenticated user's media feed uses pagination</li>"
"<li><a href='/user_media_feed'>User Media Feed</a> Calls user_media_feed - Get the currently authenticated user's media feed uses pagination</li>"
"<li><a href='/location_recent_media'>Location Recent Media</a> Calls location_recent_media - Get a list of recent media at a given location, in this case, the Instagram office</li>"
"<li><a href='/media_search'>Media Search</a> Calls media_search - Get a list of media close to a given latitude and longitude</li>"
"<li><a href='/media_popular'>Popular Media</a> Calls media_popular - Get a list of the overall most popular media items</li>"
"<li><a href='/user_search'>User Search</a> Calls user_search - Search for users on instagram, by name or username</li>"
"<li><a href='/user_follows'>User Follows</a> Get the followers of @instagram uses pagination</li>"
"<li><a href='/location_search'>Location Search</a> Calls location_search - Search for a location by lat/lng</li>"
"<li><a href='/location_search'>Location Search</a> Calls location_search - Search for a location by lat/lng</li>"
"<li><a href='/tag_search'>Tags</a> Search for tags, view tag info and get media by tag</li>"
"</ul>")

return nav_menu

@route('/oauth_callback')
def on_callback():
def on_callback():
code = request.GET.get("code")
if not code:
return 'Missing code'
Expand All @@ -71,7 +70,7 @@ def on_callback():
return get_nav()

@route('/recent')
def on_recent():
def on_recent():
content = "<h2>User Recent Media</h2>"
access_token = request.session['access_token']
if not access_token:
Expand All @@ -89,25 +88,25 @@ def on_recent():
photos.append("<br/> <a href='/media_like/%s'>Like</a> <a href='/media_unlike/%s'>Un-Like</a> LikesCount=%s</div>" % (media.id,media.id,media.like_count))
content += ''.join(photos)
except Exception as e:
print(e)
print(e)
return "%s %s <br/>Remaining API Calls = %s/%s" % (get_nav(),content,api.x_ratelimit_remaining,api.x_ratelimit)

@route('/media_like/<id>')
def media_like(id):
def media_like(id):
access_token = request.session['access_token']
api = client.InstagramAPI(access_token=access_token, client_secret=CONFIG['client_secret'])
api.like_media(media_id=id)
redirect("/recent")

@route('/media_unlike/<id>')
def media_unlike(id):
def media_unlike(id):
access_token = request.session['access_token']
api = client.InstagramAPI(access_token=access_token, client_secret=CONFIG['client_secret'])
api.unlike_media(media_id=id)
redirect("/recent")

@route('/user_media_feed')
def on_user_media_feed():
def on_user_media_feed():
access_token = request.session['access_token']
content = "<h2>User Media Feed</h2>"
if not access_token:
Expand All @@ -126,11 +125,11 @@ def on_user_media_feed():
counter += 1
content += ''.join(photos)
except Exception as e:
print(e)
print(e)
return "%s %s <br/>Remaining API Calls = %s/%s" % (get_nav(),content,api.x_ratelimit_remaining,api.x_ratelimit)

@route('/location_recent_media')
def location_recent_media():
def location_recent_media():
access_token = request.session['access_token']
content = "<h2>Location Recent Media</h2>"
if not access_token:
Expand All @@ -143,11 +142,11 @@ def location_recent_media():
photos.append('<img src="%s"/>' % media.get_standard_resolution_url())
content += ''.join(photos)
except Exception as e:
print(e)
print(e)
return "%s %s <br/>Remaining API Calls = %s/%s" % (get_nav(),content,api.x_ratelimit_remaining,api.x_ratelimit)

@route('/media_search')
def media_search():
def media_search():
access_token = request.session['access_token']
content = "<h2>Media Search</h2>"
if not access_token:
Expand All @@ -160,11 +159,11 @@ def media_search():
photos.append('<img src="%s"/>' % media.get_standard_resolution_url())
content += ''.join(photos)
except Exception as e:
print(e)
print(e)
return "%s %s <br/>Remaining API Calls = %s/%s" % (get_nav(),content,api.x_ratelimit_remaining,api.x_ratelimit)

@route('/media_popular')
def media_popular():
def media_popular():
access_token = request.session['access_token']
content = "<h2>Popular Media</h2>"
if not access_token:
Expand All @@ -177,11 +176,11 @@ def media_popular():
photos.append('<img src="%s"/>' % media.get_standard_resolution_url())
content += ''.join(photos)
except Exception as e:
print(e)
print(e)
return "%s %s <br/>Remaining API Calls = %s/%s" % (get_nav(),content,api.x_ratelimit_remaining,api.x_ratelimit)

@route('/user_search')
def user_search():
def user_search():
access_token = request.session['access_token']
content = "<h2>User Search</h2>"
if not access_token:
Expand All @@ -194,11 +193,11 @@ def user_search():
users.append('<li><img src="%s">%s</li>' % (user.profile_picture,user.username))
content += ''.join(users)
except Exception as e:
print(e)
print(e)
return "%s %s <br/>Remaining API Calls = %s/%s" % (get_nav(),content,api.x_ratelimit_remaining,api.x_ratelimit)

@route('/user_follows')
def user_follows():
def user_follows():
access_token = request.session['access_token']
content = "<h2>User Follows</h2>"
if not access_token:
Expand All @@ -216,11 +215,11 @@ def user_follows():
users.append('<li><img src="%s">%s</li>' % (user.profile_picture,user.username))
content += ''.join(users)
except Exception as e:
print(e)
print(e)
return "%s %s <br/>Remaining API Calls = %s/%s" % (get_nav(),content,api.x_ratelimit_remaining,api.x_ratelimit)

@route('/location_search')
def location_search():
def location_search():
access_token = request.session['access_token']
content = "<h2>Location Search</h2>"
if not access_token:
Expand All @@ -233,11 +232,11 @@ def location_search():
locations.append('<li>%s <a href="https://www.google.com/maps/preview/@%s,%s,19z">Map</a> </li>' % (location.name,location.point.latitude,location.point.longitude))
content += ''.join(locations)
except Exception as e:
print(e)
print(e)
return "%s %s <br/>Remaining API Calls = %s/%s" % (get_nav(),content,api.x_ratelimit_remaining,api.x_ratelimit)

@route('/tag_search')
def tag_search():
def tag_search():
access_token = request.session['access_token']
content = "<h2>Tag Search</h2>"
if not access_token:
Expand All @@ -251,7 +250,7 @@ def tag_search():
photos.append('<img src="%s"/>' % tag_media.get_standard_resolution_url())
content += ''.join(photos)
except Exception as e:
print(e)
print(e)
return "%s %s <br/>Remaining API Calls = %s/%s" % (get_nav(),content,api.x_ratelimit_remaining,api.x_ratelimit)

@route('/realtime_callback')
Expand All @@ -260,7 +259,7 @@ def on_realtime_callback():
mode = request.GET.get("hub.mode")
challenge = request.GET.get("hub.challenge")
verify_token = request.GET.get("hub.verify_token")
if challenge:
if challenge:
return challenge
else:
x_hub_signature = request.header.get('X-Hub-Signature')
Expand All @@ -270,4 +269,4 @@ def on_realtime_callback():
except subscriptions.SubscriptionVerifyError:
print("Signature mismatch")

bottle.run(app=app, host='localhost', port=8515, reloader=True)
bottle.run(app=app, host='localhost', port=8515, reloader=True)

0 comments on commit 8779a56

Please sign in to comment.