def save_fsq_user(user_id, brand_name, access_token): api = get_api() api.set_access_token(access_token) me = api.users()["user"] fsq_user = FSQUser() fsq_user.fsq_id = me["id"] fsq_user.u_id = user_id fsq_user.brand_name = brand_name fsq_user.first_name = key_check(me, "firstName") fsq_user.last_name = key_check(me, "lastName") fsq_user.fields = me dupe_obj = FSQUser.collection().find_one({"u_id": user_id, "brand_name": brand_name}) if dupe_obj is None: fsq_user._id = FSQUser.collection().insert(fsq_user.serialize()) else: FSQUser.collection().update({"u_id": user_id, "brand_name": brand_name}, fsq_user.serialize()) fsq_user = FSQUser.unserialize(FSQUser.collection().find_one({"u_id": user_id, "brand_name": brand_name})) update_brand_mapping(user_id, brand_name, "foursquare", fsq_user.fsq_id, access_token) return fsq_user