yandex
loader

please wait

  • Shalini Jaiswal Feb-12-2019 06:26:06 AM ( 1 month ago )

    Whenever "answer" is having pipe delimiters in them, the files are getting corrupted and the record is not getting appended and further functionalities are disabling themselves.

    @app.route("/append_record", methods = ['POST'])
    def append_record():
        query = text_normalize_csv_diacritic(request.json["query"])
        #print query
        answer = text_normalize_csv_diacritic(request.json["answer"])
        #print answer
        module = request.json["module"]
        lang = request.json["lang"]
        isloop = request.json["is_loop"]
        csv_file = getfilefromdb(lang)
        #print csv_file.read()
        found = False
        questions=[]
        corpus = []
        lang_query = detect_language(query)
        lang_query_alt = detect_language(answer)
        #csv_file_r = csv.reader(csv_file.split('\n'), quotechar='"')
        csv_file_r = csv.reader(csv_file.splitlines(), quotechar='"')
        #print csv_file.read().splitlines()
        corpus = list(csv_file_r)
        #print corpus
    
        if lang_query_alt == lang_query and lang == lang_query:
    
            for t in corpus[1:]:
                try:
                    if len(t) > 1:
                        questions.append(t[0])
            #print questions
    
                except Exception as e:
                    return jsonify(error=str(e))
    
            if query not in questions:
                corpus.append([query, answer, module, isloop])
    
            else:
                index = questions.index(query)
                index+=1
    
                if corpus[index][1]== answer:
    
                    return jsonify(error="already exists")
                else:
                    corpus[index][1] = answer
    
        #print "\n".join(",".join(corpora).decode("utf-8","ignore") for corpora in corpus)
    
        else:
            return jsonify(error="Please make sure that you have selected your language appropriately")
    
        try:
            putfileindb("\n"

Please login

Similar Discussion

Recommended For You