def command(self): users = Session.query(User) for current_user in users: for checkin in current_user.friend_checkins(300): print checkin["place"]["distance"] if (checkin["place"]["distance"] < 5): current_user.send_nearby_notification(checkin)
def update_location(access_token, latitude, longitude): query = Session.query(User) user = query.filter_by(access_token=access_token).first() if user: user.lat = latitude user.lon = longitude Session.commit() return True
def user_with_access_token(access_token, device_token): graph_api = facebook.GraphAPI(access_token) me = graph_api.get_object("me") # TODO wrap in a try catch facebook_user_id = facebook_user_id = me['id'] query = Session.query(User) user = query.filter_by(facebook_user_id=facebook_user_id).first() if user is None: user = User(facebook_user_id, access_token, device_token) push_client = airship() push_client.register(device_token, alias='fbuid:' + str(facebook_user_id)) Session.add(user) Session.commit() elif (user.access_token is not access_token or user.device_token is not device_token): user.access_token = access_token user.device_token = device_token push_client = airship() push_client.register(device_token, alias='fbuid:' +\ str(user.facebook_user_id)) Session.commit() return user