Пример #1
0
    def post(cls):
        payload = request.get_json()
        word_json = request.get_json()["word"]

        if WordModel.find_by_word(word=word_json):
            return {"message": WORD_ALREADY_EXISTS.format(word=word_json)}, 400

        try:
            word = WordModel(**payload)  # word_schema was throwing error
            word.save_to_db()
        except (Exception, ArithmeticError) as e:
            print(e)
            return {"message": ERROR_INSERTING}, 500

        return word_schema.dump(word), 201
Пример #2
0
    def get(cls):
        word = request.get_json()["word"]

        word = WordModel.find_by_word(word)
        if word:
            return word_schema.dump(word), 200

        return {"message": WORD_NOT_FOUND}, 404
Пример #3
0
    def delete(cls):
        word = request.get_json()["word"]

        word = WordModel.find_by_word(word)
        if word:
            word.delete_from_db()
            return {"message": WORD_DELETED}, 200

        return {"message": WORD_NOT_FOUND}, 404
Пример #4
0
    def put(self, word_value):
        data = Word.parser.parse_args()

        word = WordModel.find_by_word(word_value)

        if word is None:
            word = WordModel(word_value, **data)
        else:
            word.stem_id = data['stem_id']
            word.text = word_value

        word.save_to_db()

        return word.json()
Пример #5
0
    def put(cls):
        old_word_json = request.get_json()["old_word"]
        new_word_json = request.get_json()["new_word"]

        old_word = WordModel.find_by_word(old_word_json)

        if old_word:
            print('updating old word with new word')
            old_word.word = new_word_json
            old_word.save_to_db()

            return word_schema.dump(old_word), 200
        else:

            print('creating new word from new')
            new_word = word_schema.load(new_word_json)
            new_word.save_to_db()

            return word_schema.dump(new_word), 200
Пример #6
0
def NameClouds():
    """用户名词云"""
    result = WordModel.get_user_name(db.spider)
    data = []
    text = ''
    for i in result:
        text += re.sub(
            r'[-,$\(\)#\+\&\*::\.·`・|\s,。!/~\r\n=\!?、…_;\\—@\?()~\']', '',
            i['sign'])
    seg_list = [x.word for x in psg.cut(text) if x.flag.startswith('n')]
    all_words = Counter(seg_list).most_common(200)
    for i, _ in all_words:
        data.append(i)
    cloud_text = ",".join(data)
    wc = WordCloud(background_color="white",
                   max_words=200,
                   font_path="C:/Windows/Fonts/STFANGSO.ttf",
                   min_font_size=15,
                   max_font_size=50,
                   width=400)
    wc.generate(cloud_text)
    wc.to_file('../static/images/name_cloud.png')
Пример #7
0
    def post(self, word_value):
        if WordModel.find_by_word(word_value):
            return {
                'message':
                "An word with name '{}' already exists.".format(word_value)
            }, 400

        data = Word.parser.parse_args()

        word = WordModel(word_value, **data)

        try:
            word.save_to_db()
        except:
            return {"message": "An error occurred inserting the word."}, 500

        return word.json(), 201
Пример #8
0
 def get(cls):
     return {"words": word_list_schema.dump(WordModel.find_all())}, 200
Пример #9
0
 def get_user_name():
     """获取用户名"""
     result = WordModel.get_user_name(db.spider)
     return Response(result=result)
Пример #10
0
 def get_user_sign():
     """获取用户签名"""
     result = WordModel.get_user_sign(db.spider)
     return Response(result=result)
Пример #11
0
    def delete(self, word_value):
        word = WordModel.find_by_word(word_value)
        if word:
            word.delete_from_db()

        return {'message': 'word deleted'}
Пример #12
0
 def get(self, word_value):
     word = WordModel.find_by_word(word_value)
     if word:
         return word.json()
     return {'message': 'Word not found'}, 404