def summarize(): """ Get a summary of given links subjected to limit of words Argument in JSON: { topic: "topic inputted by user", links: ["array of links"], words: 150 // words limit } """ if not request.headers["Host"].startswith("ns.apps.xiamx.me"): print "tada" return redirect("http://ns.apps.xiamx.me" + "/summarize", code=301) params = request.get_json() print "Summarize " + params["topic"] + " from " + str(params["links"]) if not len(params["links"]) > 0: abort(400) summary = generate_summary.delay(params["links"], params["words"]) response = {"summary": summary.get()} return jsonify(response)
def summarize(): """ Get a summary of given links subjected to limit of words. Argument in JSON: { topic: "topic inputted by user", words: 150 // words limit } Return 201 if request is queued, otherwise return 4xx. """ if environ.get("REDIRECT") == "1": print("Move to new domain") return redirect("http://ns.apps.xiamx.me" + "/summarize", code=301) params = request.get_json() print("Summarize %s" % params["topic"]) try: cached_summary = Summary.select().where( Summary.topic == params["topic"], Summary.last_updated.between( datetime.today() - timedelta(days=3), datetime.today() ) ).order_by(Summary.last_updated.desc()).get() print("Summary found in database") return jsonify({ "summary": cached_summary.summary, "images": cached_summary.images, "links": cached_summary.links, "names": cached_summary.names, "status": "done" }), 200 except DoesNotExist: summary = generate_summary.delay(params["topic"], params["words"]) tid = summary.task_id return jsonify({"status": "created", "task": tid}), 201
def summarize(): """ Get a summary of given links subjected to limit of words. Argument in JSON: { topic: "topic inputted by user", words: 150 // words limit } Return 201 if request is queued, otherwise return 4xx. """ if environ.get("REDIRECT") == "1": print "Move to new domain" return redirect("http://ns.apps.xiamx.me" + "/summarize", code=301) params = request.get_json() print "Summarize %s" % params["topic"] summary = generate_summary.delay(params["topic"], params["words"]) tid = summary.task_id return jsonify({"status": "created", "task": tid}), 201