def search_information(): """ Performs a search in the database for information that matches the given parameters. """ if not request.method == 'POST': abort(405) try: title_part = request.form['title_part'] tags = ast.literal_eval(request.form['tags']) try: startD = datetime.strptime(request.form['start_date'], "%Y-%m-%d") endD = datetime.strptime(request.form['end_date'], "%Y-%m-%d") res = search.get_information.delay(title_part, tags, startD=startD, endD=endD) except Exception as exp: log("Exception: "+str(type(exp))+"\nMsg: "+exp.message+ "\n(KeyError is allowed here; no start/end date specified.)"); res = search.get_information.delay(title_part, tags) store_job_result(res) return jsonify(job_id=res.id) except Exception as exp: log("Exception: "+str(type(exp))+"\nMsg: "+exp.message); abort(400)
def register_user(): """Scrapes an article from a URL and adds it to the database. URL Structure: ``/register`` Method: POST Parameters: username (str): The username to be registered. password (str): The password to be used with the username to login. Returns: Upon success, returns an object with the job_id, ex:: {"job_id": "ff92-23ad-232a-2334s-23"} Result when finished: *user_created (boolean)* : [True | False] *error (str)* : A string containing the error if any. Errors: * **405** -- Method not allowed """ if request.method != 'POST': abort(405) res = login.register.delay(request.form.get('username'), request.form.get('password')) store_job_result(res) return jsonify(job_id=res.id)
def search_information(): """ Performs a search in the database for information that matches the given parameters. """ if not request.method == 'POST': abort(405) try: title_part = request.form['title_part'] tags = ast.literal_eval(request.form['tags']) try: startD = datetime.strptime(request.form['start_date'], "%Y-%m-%d") endD = datetime.strptime(request.form['end_date'], "%Y-%m-%d") res = search.get_information.delay(title_part, tags, startD=startD, endD=endD) except Exception as exp: log("Exception: " + str(type(exp)) + "\nMsg: " + exp.message + "\n(KeyError is allowed here; no start/end date specified.)") res = search.get_information.delay(title_part, tags) store_job_result(res) return jsonify(job_id=res.id) except Exception as exp: log("Exception: " + str(type(exp)) + "\nMsg: " + exp.message) abort(400)
def search_information(): """ Performs a search in the database for information that matches the given parameters. URL Structure: /jobs/search/information Method: POST Parameters: title_part (str): The part of a title of information. tags (str): The tags of the information. start_date (str/Date [%Y-%m-%d]): The start time, when the information earliest could've been created. end_date (str/Date [%Y-%m-%d]): The end time, when the information latest could've been created. Returns: Upon success, returns an object with the job_id, ex: {"job_id": "baad-f00d-dead-beef-15"} Result when finished: An object with the information found. Errors: 400 - Bad syntax/No name/type in request 405 - Method not allowed """ if not request.method == 'POST': abort(405) try: title_part = request.form['title_part'] tags = ast.literal_eval(request.form['tags']) try: startD = datetime.strptime(request.form['start_date'], "%Y-%m-%d") endD = datetime.strptime(request.form['end_date'], "%Y-%m-%d") res = search.get_information.delay(title_part, tags, startD=startD, endD=endD) except Exception as exp: log("Exception: " + str(type(exp)) + "\nMsg: " + exp.message + "\n(KeyError is allowed here; no start/end date specified.)") res = search.get_information.delay(title_part, tags) store_job_result(res) return jsonify(job_id=res.id) except Exception as exp: log("Exception: " + str(type(exp)) + "\nMsg: " + exp.message) abort(400)
def search_information(): """ Performs a search in the database for information that matches the given parameters. URL Structure: /jobs/search/information Method: POST Parameters: title_part (str): The part of a title of information. tags (str): The tags of the information. start_date (str/Date [%Y-%m-%d]): The start time, when the information earliest could've been created. end_date (str/Date [%Y-%m-%d]): The end time, when the information latest could've been created. Returns: Upon success, returns an object with the job_id, ex: {"job_id": "baad-f00d-dead-beef-15"} Result when finished: An object with the information found. Errors: 400 - Bad syntax/No name/type in request 405 - Method not allowed """ if not request.method == 'POST': abort(405) try: title_part = request.form['title_part'] tags = ast.literal_eval(request.form['tags']) try: startD = datetime.strptime(request.form['start_date'], "%Y-%m-%d") endD = datetime.strptime(request.form['end_date'], "%Y-%m-%d") res = search.get_information.delay(title_part, tags, startD=startD, endD=endD) except Exception as exp: log("Exception: "+str(type(exp))+"\nMsg: "+exp.message+ "\n(KeyError is allowed here; no start/end date specified.)"); res = search.get_information.delay(title_part, tags) store_job_result(res) return jsonify(job_id=res.id) except Exception as exp: log("Exception: "+str(type(exp))+"\nMsg: "+exp.message); abort(400)
def search_producers(): """Performs a search in the database for producers that match the given parameters. URL Structure: /jobs/search/producers Method: POST Parameters: name (str): The name of a producer. type (str): The type of a producer. Returns: Upon success, returns an object with the job_id, ex: {"job_id": "baad-f00d-dead-beef-15"} Result when finished: An object with the producer data found. Errors: 400 - Bad syntax/No name/type in request 405 - Method not allowed """ if not request.method == 'POST': abort(405) try: name = request.form['name'] type_of = request.form['type'] if type_of == '': type_of = None except: abort(400) res = search.get_producers.delay(name, type_of) store_job_result(res) return jsonify(job_id=res.id)
def awesome(): res = mkawesome.delay() store_job_result(res) return jsonify(job_id=res.id)
400 - Bad syntax in request 405 - Method not allowed """ if not request.method == 'POST': abort(405) try: source = request.form['source'] sink = request.form['sink'] tag = request.form['tag'] except KeyError, AttributeError: abort(400) res = algorithms.tidaltrust.delay(source, sink, tag) store_job_result(res) return jsonify(job_id=res.id) @app.route("/jobs/algorithms/sunny", methods=['GET', 'POST']) def sunny(): """ Calculates the trust between source and sink in the global network using the specified tag. URL Structure: /jobs/algorithms/sunny Method: POST