コード例 #1
0
def add_item():
    # Get item from the POST body

    req_data = request.get_json()
    print(req_data)
    item = req_data['item']
    status = req_data['status']
    print(status)
    if status is None:
        res_data = helper.add_to_list(item, statu="Not Started")
    else:
        # Add item to the list
        res_data = helper.add_to_list(item, status)

    # Return error if item not added
    if res_data is None:
        response = Response("{'error': 'Item not added - '}" + item,
                            status=400,
                            mimetype='application/json')
        return response

    # return response
    response = Response(json.dumps(res_data), mimetype='application/json')

    return response
コード例 #2
0
ファイル: main_Vitali.py プロジェクト: ywsyws/MSP-2-OCR-APP
def add_comment():
    # Get comment from the POST body
    if request.method == "POST":

        req = request.form.to_dict()
        comment = req["comment"]
        text = get_text_from_url(comment)
        return Response("<p>" + text + "</p>")

    req_data = request.get_json()
    comment = req_data['comment']

    # Add comment to the list
    res_data = helper.add_to_list(comment)

    # Return error if comment not added
    if res_data is None:
        response = Response("{'error': 'comment not added - " + comment + "'}",
                            status=400,
                            mimetype='application/json')
        return response

    # Return response
    response = Response(json.dumps(res_data), mimetype='application/json')

    return render_template("index.html")
コード例 #3
0
ファイル: app.py プロジェクト: FatimaMoqran/moderationapp
def add_comment():
    # Get comment from the POST body
    if request.method == "POST":
        req = request.form.to_dict()
        comment = req["comment"]
        response = moderate.moderate(comment)
        if response["Terms"] == None:
            texte = "Votre commentaire a été enregistré"
        elif len(response["Terms"]) == 1:
            texte = "Votre commentaire a ete modéré à cause du mot {}".format(
                response["Terms"][0]['Term'])
        elif len(response["Terms"]) > 1:
            texte = "Votre commentaire a été supprimé !!"
        #return (response)
        return render_template("index.html",
                               commentaire=comment,
                               message=texte)

    req_data = request.get_json()
    comment = req_data['comment']
    res_data = helper.add_to_list(comment)

    if res_data is None:
        response = Response("{'error': 'comment not added - " + comment + "'}",
                            status=400,
                            mimetype='application/json')
        return response

    response = Response(json.dumps(res_data), mimetype='application/json')

    return render_template("index.html")
コード例 #4
0
def add_comment():
    # Get comment from the POST body
    if request.method == "POST":
        req = request.form.to_dict()
        comment = req["comment"]
        headers = {"Ocp-Apim-Subscription-Key": KEY, 'Content-type': 'text/plain'}
        url = 'https://westeurope.api.cognitive.microsoft.com/contentmoderator/moderate/v1.0/ProcessText/Screen?classify=True&language=fra'
        data = {'ContentValue': comment}
        response = requests.post(url, headers=headers, data=data)
        if response.json()["Terms"] is not None:        
            return Response("Votre commentaire a été modéré.")
        else:
            return Response("Votre commentaire a été enregistré.")    

    
    req_data = request.get_json()
    comment = req_data['comment']

    res_data = helper.add_to_list(comment)

    if res_data is None:
        response = Response("{'error': 'comment not added - " + comment + "'}", status=400 , mimetype='application/json')
        return response

    response = Response(json.dumps(res_data), mimetype='application/json')

    return render_template("index.html")
コード例 #5
0
def add_item():
    req_data = request.get_json()
    item = req_data['item']
    res_data = helper.add_to_list(item)
    if res_data is None:
        response = Response("{'error': 'item not added - '}" + item,
                            status=400,
                            mimetype='application/json')
        return response
    response = Response(json.dumps(res_data), mimetype='application/json')
    return response
コード例 #6
0
def listmoderation():
    # Get comment from the POST body
    if request.method == "POST":
        req = request.form.to_dict()
        comment = req["comment"]
        comment_list = list(comment.split(" "))
        comment_list = [x.lower() for x in comment_list]

        # Recup forbidden words
        f = open("app_moderation/checklist.txt", "r")
        forbidden_list = f.read()
        forbidden_list = list(forbidden_list.split("\n"))
        forbidden_list = [x.lower() for x in forbidden_list]

        # lists compare intersection
        inter_list = list(set(comment_list) & set(forbidden_list))

        # Traitement commentaire
        if len(comment) != 0:
            if len(inter_list) == 0:
                texte = "Bravo! Votre commentaire a été enregistré"
                # Enregistrement du commentaire en bd
                helper.add_to_list(comment)
            elif len(inter_list) == 1:
                texte = "Votre commentaire a été modéré à cause du mot {}".format(
                    inter_list[0])
            elif len(inter_list) > 1:
                forbidden_words = ', '.join(inter_list)
                texte = "Désolé, votre commentaire a été modéré pour cause de vulgarité !! ({})".format(
                    forbidden_words)
        else:
            texte = "Aucun commentaire saisi."

        # Récup liste commentaires depuis bd
        res = helper.get_list()

        # Render template
        return render_template("index.html", message=texte, data=res)
コード例 #7
0
def moderation():
    # Get comment from the POST body
    if request.method == "POST":
        req = request.form.to_dict()
        comment = req["comment"]
        result_moderation = moderation_api(comment)

        # Traitement commentaire
        if len(comment) != 0:
            if result_moderation["Terms"] == None:
                texte = "Bravo! Votre commentaire a été enregistré"
                # Enregistrement du commentaire en bd
                helper.add_to_list(comment)
            elif len(result_moderation["Terms"]) == 1:
                texte = "Votre commentaire a été modéré à cause du mot {}".format(
                    result_moderation["Terms"][0]['Term'])
            elif len(result_moderation["Terms"]) > 1:
                # [{'Index': 11, 'OriginalIndex': 11, 'ListId': 0, 'Term': 'putain'},
                # {'Index': -1, 'OriginalIndex': 18, 'ListId': 0, 'Term': 'de merde'},
                # {'Index': 19, 'OriginalIndex': 21, 'ListId': 0, 'Term': 'merde'}]
                # rejected_words = result_moderation["Terms"]
                # for item in result_moderation["Terms"]:

                rejected_words = [
                    item['Term'] for item in result_moderation["Terms"]
                ]
                rejected_words = ', '.join(rejected_words)
                texte = "Désolé, votre commentaire a été modéré pour cause de vulgarité !! ({})".format(
                    rejected_words)
        else:
            texte = "Aucun commentaire saisi."

        # Récup liste commentaires depuis bdS
        res = helper.get_list()

        # Render template
        return render_template("index.html", message=texte, data=res)
コード例 #8
0
def add_item():
    #Get item from the POST body
    req_data = request.get_json()
    item = req_data['item']
    #Add items to the list
    res_data = helper.add_to_list(item)
    #Return error if item not added
    if res_data is None:
        response = Response("{'error': 'Item not added - " + item + "'}",
                            status=400,
                            mimetype='application/json')
        return response
    #return response
    response = Response(json.dumps(res_data), mimetype='application/json')
    return response
コード例 #9
0
ファイル: main.py プロジェクト: zaferon/BlogServer
def add_article():
    # Get article from the POST body
    req_data = request.get_json()
    article = req_data['article']
    # Add article to the list
    res_data = helper.add_to_list(article)
    # Return error if article not added
    if res_data is None:
        response = Response("{'error': 'Article not added - " + article + "'}",
                            status=400,
                            mimetype='application/json')
        return response

    # Return response
    response = Response(json.dumps(res_data), mimetype='application/json')
    return response
コード例 #10
0
ファイル: app.py プロジェクト: nonodamiens/OCR_application
def get_image():
    # Get and analyze the image from the POST body
    if request.method == "POST":
        req = request.form.to_dict()
        url = req["image"]
        text = get_text_from_url(url)

        text_to_db = '\n'.join(text)
        res_data = helper.add_to_list(url, text_to_db)
        if res_data is None:
            response = Response("{'error': 'text not added - " + text_to_db +
                                "'}",
                                status=400,
                                mimetype='application/json')
            return response

        return render_template("result.html", text=text)
コード例 #11
0
ファイル: main.py プロジェクト: sarahlevins/todolist
def add_item():
    # get item from the post body
    req_data = request.get_json()
    item = req_data['item']

    # add item to list
    res_data = helper.add_to_list(item)

    # return error if item not added
    if res_data is None:
        response = Response(f"{{'error': 'Item not added - {item} }}",
                            status=400,
                            mimetype='application/json')
        return response

    response = Response(json.dumps(res_data), mimetype='application/json')

    return response
コード例 #12
0
def add_item():
    req_body = request.get_json()
    title = req_body['title']
    description = req_body['description']
    date = req_body['date']

    res_data = helper.add_to_list(title, description, date)

    # if helper function is unable to write to DB
    if res_data is None:
        response = Response("{'error': 'Item not added - " + title + "'}",
                            status=400,
                            mimetype='application/json')
        return response

    response = Response(json.dumps(res_data), mimetype='application/json')

    return response
コード例 #13
0
ファイル: app.py プロジェクト: ademarrohregger/FlaskReact
    def _add_item():
        """ Add a new task item """
        # Get item from the POST body
        req_data = request.get_json()

        title = req_data["title"]
        description = req_data["description"]
        deadline = req_data["deadline"]

        # Add item to the list
        res_data = helper.add_to_list(title, description, deadline)

        # Return error if item not added
        if res_data is None:
            response = Response("{'error': 'Item not added - " +
                                title + "'}", status=400, mimetype='application/json')
            return response

        # Return response
        response = Response(json.dumps(res_data), mimetype='application/json')

        return response
コード例 #14
0
ファイル: main.py プロジェクト: javierguignard/todo-app-flask
def add_item():
    #Get item from the POST body
    item = request.args.get('item')
    if not item:
        response = Response("{'error': 'Item not added - :( '}",
                            status=400,
                            mimetype='application/json')
        return response

    #Add item to the list
    res_data = helper.add_to_list(item)

    #Return error if item not added
    if res_data is None:
        response = Response("{'error': 'Item not added - '}" + item,
                            status=400,
                            mimetype='application/json')
        return response

    #Return response
    response = Response(json.dumps(res_data), mimetype='application/json')

    return response
コード例 #15
0
 def post(self):
     args = parser.parse_args()
     add_to_list(args.get('task'))
     return get_all_items()