def isTokenValid(self): try: api = InstagramAPI(access_token=self._accessToken) api.user() except InstagramAPIError as e: return ErrorCode.E_INVALID_TOKEN except: self._logger.exception('InstaBase::isTokenValid() exception') return ErrorCode.E_FAILED else: return ErrorCode.S_OK
def getMyId(self): try: api = InstagramAPI(access_token=self._accessToken) self.myId = api.user().id except: return None return self.myId
def get_user(uid, access_token): try: api = InstagramAPI(access_token=access_token) user = api.user(uid) return user except InstagramAPIError, e: if e.error_type in ['APINotAllowedError-you', 'APINotFoundError-this']: delete_worker(uid) print e.error_type return e
def refresh_user_pic(): users = UserModel.query.all() for user in users: print user try: ret = urllib.urlopen(user.pic) if ret.code != 200: print 'refresh!' api = InstagramAPI(access_token=user.access_token) new = api.user(user_id=user.ukey) user.pic = new.profile_picture except Exception: pass db.session.commit()
photographer_id = new_user_search[0].id else: print('Username to ID failed for %s' % new_username) print("*** Remaining API Calls = %s/%s" % (api.x_ratelimit_remaining, api.x_ratelimit)) continue if photographer_id in good_users.keys(): print(" * photographer %s already in the database! Skipping." % (photographer_id)) continue print('') print('Adding %s' % (new_user_search[0].username)) pom_user = api.user(photographer_id) pom_user_follows = pom_user.counts[u'follows'] pom_user_followed_by = pom_user.counts[u'followed_by'] pom_user_media = pom_user.counts[u'media'] pom_user_full_name = pom_user.full_name analyzed_for_network = 0 analyzed_for_folowers = 0 user_rank = 0 user_categories = [] # =============================================================================================================================== good_users[photographer_id] = [new_user_search[0].username, pom_user_full_name, pom_user_media, pom_user_follows, \ pom_user_followed_by, analyzed_for_network, analyzed_for_folowers, user_rank, user_categories] print('User %s follows %s users and followed by %s users.' % (new_user_search[0].username, pom_user_follows,