Skip to content

Commit

Permalink
add tranx-plugin upload edits feature to flask app apis
Browse files Browse the repository at this point in the history
  • Loading branch information
frankxu2004 committed Feb 20, 2020
1 parent fd5afd2 commit 6e1421e
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions server/app.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from __future__ import print_function

import time

import six
import argparse
import sys
from flask import Flask, url_for, jsonify, render_template, request
import json

from pymongo import MongoClient
from components.standalone_parser import StandaloneParser

app = Flask(__name__)
parsers = dict()

client = MongoClient()

def init_arg_parser():
arg_parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -66,6 +69,20 @@ def parse(dataset):
return jsonify(responses)


@app.route("/upload", methods=['POST'])
def upload():
try:
req_data = request.get_json()
db = client['tranx']
collection = db['events']
req_data['timestamp'] = int(time.time())
collection.insert_one(req_data)
return "success"
except Exception as e:
print(e)
return "failed"


if __name__ == '__main__':
args = init_arg_parser().parse_args()
config_dict = json.load(open(args.config_file))
Expand Down

0 comments on commit 6e1421e

Please sign in to comment.