def get(self, *args): path = base.set_template(args[0]) try: self.response.out.write(template.render(path, {})) except: self.response.set_status(404) path = base.set_template("not_found") self.response.out.write(template.render(path, {}))
def get(self, *args): if self.request.host == "instagrampc.appspot.com" or self.request.host == "www.instagram.jp": return self.redirect("http://www.i4pc.jp/", permanent=True) session = get_current_session() instagram = Instagram() max_id = self.request.get("max_id") prev_max_id = max_id first_page = True if max_id: first_page = False if session.has_key("access_token"): instagram.set_access_token(access_token=session["access_token"]) login = True user = session["user"] else: login = False user = None if self.request.path == "/popular" or login == False: path = base.set_template("popular") try: feed = instagram.media_popular(count=50, max_id=max_id) except InstagramAPIError, e: return base.error(self, 500, e.error_message.capitalize()) except:
def get(self): session = get_current_session() session.terminate() path = base.set_template('logout') self.response.out.write(template.render(path, { 'path' : self.request.path, }))
def get(self): instagram = Instagram() result = instagram.get_news() path = base.set_template('news') session = get_current_session() self.response.out.write(template.render(path, { 'items' : result['items'][0]['updates'], 'user' : instagram.get_user_info(session['ds_user_id']), 'followings': instagram.get_following(session['ds_user_id'])['users'], 'login' : True }))
def get(self, *args): path = base.set_template('about') session = get_current_session() login = False user = None if session.has_key('access_token'): login = True user = session['user'] self.response.out.write(template.render(path, { 'path' : self.request.path, 'login' : login, 'user' : user, }))
def get(self, tag): session = get_current_session() instagram = Instagram() max_id = self.request.get('max_id') prev_max_id = max_id first_page = True if max_id: first_page = False if session.has_key('access_token'): instagram.set_access_token( access_token = session['access_token'] ) login = True user = session['user'] else: login = False user = None path = base.set_template('tag') feed, pagination = instagram.tag_recent_media(tag_name=tag, count=25, max_id=max_id) if user: for media in feed: if memcache.get('user_has_liked_%s_%s' % ( user['id'], media.id ) ): media.user_has_liked = True media.like_count = media.like_count + 1 title = tag body_id = 'popular' max_id = None if pagination.has_key('next_max_id'): max_id = pagination['next_max_id'] self.response.out.write(template.render(path, { 'feed' : feed, 'user' : user, 'login' : login, 'max_id' : max_id, 'title' : title, 'body_id' : feed, 'path' : self.request.path, 'prev_max_id': prev_max_id, 'first_page' : first_page, }))
def get(self): session = get_current_session() instagram = Instagram() if session.has_key('access_token'): instagram.set_access_token( access_token = session['access_token'] ) feed, pagination = instagram.user_media_feed( count = 200, user_id = session['user']['id'], max_id = None, ) title = 'Feed - I4PC' else: feed = instagram.media_popular(count=200, max_id=None) title = 'Popular - I4PC' path = base.set_template('feed') self.response.out.write(template.render(path, { 'feed' : feed, 'title': title, }))
def get(self, username): instagram = Instagram() session = get_current_session() if not session.has_key("access_token"): session["redirect_to"] = self.request.path return self.redirect("/login") else: access_token = session["access_token"] user = session["user"] instagram.set_access_token(access_token=session["access_token"]) cursor = self.request.get("cursor") user = instagram.user_find_by_username(username) follows, pagination = instagram.user_followed_by(user_id=user["id"], count=20, cursor=cursor) next_cursor = None if pagination.has_key("next_cursor"): next_cursor = pagination["next_cursor"] path = base.set_template("follows") self.response.out.write( template.render( path, { "follows": follows, "next_cursor": next_cursor, "user": session["user"], "owner": user, "login": True, "path": self.request.path, "following": False, }, ) )
if not found and re.match(r"^\d+$", user_id): try: user_found = instagram.user(user_id) except InstagramAPIError, e: return base.error(self, 500, e.error_message.capitalize()) except: return base.error(self) if user_found: url = "/user/%s" % user_found["username"] if max_id: url = url + "?max_id=%s" % max_id return self.redirect(url, permanent=True) if feed == "feed": path = base.set_template("user_feed") self.response.headers["Content-Type"] = "text/xml; charset=utf-8" else: path = base.set_template("user") try: feed, pagination = instagram.user_recent_media(user_id=user_id, max_id=max_id) except InstagramAPIError, e: feed = [] pagination = {} if pagination.has_key("next_max_id"): max_id = pagination["next_max_id"] else: max_id = ""
user = None if self.request.path == "/popular" or login == False: path = base.set_template("popular") try: feed = instagram.media_popular(count=50, max_id=max_id) except InstagramAPIError, e: return base.error(self, 500, e.error_message.capitalize()) except: return base.error(self) title = "Popular" body_id = "popular" else: path = base.set_template("index") if self.request.path == "/liked": try: feed, pagination = instagram.user_liked_feed(count=20, max_id=max_id, user_id=user["id"]) title = "Liked" body_id = "liked" max_id = None except InstagramAPIError, e: return base.error(self, 500, e.error_message.capitalize()) except: return base.error(self) else: try: feed, pagination = instagram.user_media_feed(count=20, max_id=max_id, user_id=user["id"]) title = "Feed" body_id = "feed"
except: return base.error(self) try: likers = instagram.media_likes(media_id) except InstagramAPIError, e: return base.error(self, 500, e.error_message.capitalize()) except: return base.error(self) if user and hasattr(media, 'user_has_liked') and not media.user_has_liked: if memcache.get('user_has_liked_%s_%s' % ( user['id'], media.id ) ): media.user_has_liked = True media.like_count = media.like_count + 1 path = base.set_template('photo') self.response.out.write(template.render(path, { 'user' : user, 'owner' : owner, 'media' : media, 'comments': comments, 'likers' : likers, 'login' : login, 'path' : self.request.path, })) def main(): app = webapp.WSGIApplication([ ('/photo/(.+)', PhotoHandler), ], debug=False)