username = request.authorization.username
            new_trip = request.json

            # Find a trip and modify it
            trip_collection = app.db.trips
            trip_collection.update_one({"$set": {"username": username}, "$tripDate": {"lastModified": True}})

            my_trip = trip_collection.find_one({"_id": ObjectId(trip_id)})

            return my_trip


# [Ben-G] No possessive determiners! ;) Should be renamed to '/trips/' and '/users/'
api.add_resource(Trip, "/trips/", "/trips/<string:trip_id>")

api.add_resource(User, "/users/", "/users/<string:user_id>")


# provide a custom JSON serializer for flaks_restful
@api.representation("application/json")
def output_json(data, code, headers=None):
    resp = make_response(JSONEncoder().encode(data), code)
    resp.headers.extend(headers or {})
    # import pdb; pdb.set_trace()
    return resp


if __name__ == "__main__":
    # Turn this on in debug mode to get detailled information about request related exceptions: http://flask.pocoo.org/docs/0.10/config/
    app.config["TRAP_BAD_REQUEST_ERRORS"] = True
    app.run(host="0.0.0.0", debug=True)
Example #2
0
    OFFLINE,
    FACEBOOK_APP_ID,
    FACEBOOK_APP_SECRET,
)

# Setting up Data
Crawl_Time = 2419200  # 2419200 = 4 weeks in seconds
Crawl_By_Limit = (
    False
)  # if False, it will crawl datas by Crawl_Time. if True, it will just crawl last 100 datas of user's timeline..

# Setting up the Application
app = Flask(__name__)
app.debug = DEBUG
app.secret_key = SECRET_KEY
app.config["TRAP_BAD_REQUEST_ERRORS"] = TrapErrors

# Setting path to DB depending on DEBUG setting
if DEBUG == True:
    # dbURL = 'sqlite:////tmp/test.db'
    dbURL = os.environ["DATABASE_URL"]
else:
    dbURL = os.environ["DATABASE_URL"]
app.config["SQLALCHEMY_DATABASE_URI"] = dbURL

userCache = {}

db = SQLAlchemy(app)


class User(db.Model):