Created
April 24, 2017 13:25
-
-
Save tonywangcn/4b3f0c03d0a0d51ac2f5285b50c993a9 to your computer and use it in GitHub Desktop.
flask app for log server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, Response | |
import json | |
from pymongo import MongoClient | |
from datetime import datetime | |
client = MongoClient("mongodb://logging:password@lcoal:port/logging") | |
db = client['logging'] | |
post = db.log | |
# set expire time 7 days, once setuped, couldn't change it again. | |
post.ensure_index("CreateDate", expireAfterSeconds= 7*24*60*60 ) | |
utc_timestamp = datetime.utcnow() | |
app = Flask(__name__) | |
@app.route('/log',methods=['POST']) | |
def index(): | |
data = json.loads(json.dumps(request.form)) | |
data.update({"CreateDate": utc_timestamp}) | |
response = post.insert_one(data) | |
print response.inserted_id, data | |
return "" | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port = 5000, debug=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment