Ejemplo n.º 1
0
def text():
    if request.method == 'GET':
        return render_template('wordcloud/text.html', menu=menu, weather=get_weather_main())
    else:
        lang = request.form['lang']
        f_text = request.files['text']
        file_text = os.path.join(current_app.root_path, 'static/upload/') + f_text.filename
        f_text.save(file_text)
        if request.files['mask']:
            f_mask = request.files['mask']
            file_mask = os.path.join(current_app.root_path, 'static/upload/') + f_mask.filename
            f_mask.save(file_mask)
        else:
            file_mask = None
        stop_words = request.form['stop_words']
        current_app.logger.debug(f"{lang}, {f_text}, {request.files['mask']}, {stop_words}")

        text = open(file_text, encoding='utf-8').read()
        stop_words = stop_words.split(' ') if stop_words else []
        img_file = os.path.join(current_app.root_path, 'static/img/text.png')
        if lang == 'en':
            engCloud(text, stop_words, file_mask, img_file)
        else:
            hanCloud(text, stop_words, file_mask, img_file)

        mtime = int(os.stat(img_file).st_mtime)
        return render_template('wordcloud/text_res.html', menu=menu, weather=get_weather_main(),
                                filename=f_text.filename, mtime=mtime)
Ejemplo n.º 2
0
def sports_news():
    menu = {
        'ho': 0,
        'da': 1,
        'ml': 0,
        'se': 0,
        'co': 0,
        'cg': 0,
        'cr': 0,
        'st': 0,
        'wc': 1
    }
    text_file = os.path.join(current_app.root_path, 'static/data/sports.txt')
    get_sports_news(text_file)

    text = open(text_file, encoding='utf-8').read()
    stop_words = ['오피셜']
    mask_file = os.path.join(current_app.root_path, 'static/img/ball.jpg')
    img_file = os.path.join(current_app.root_path, 'static/img/sports.png')
    hanCloud(text, stop_words, mask_file, img_file)
    mtime = int(os.stat(img_file).st_mtime)
    return render_template('wordcloud/sports_res.html',
                           menu=menu,
                           weather=get_weather_main(),
                           mtime=mtime)
Ejemplo n.º 3
0
def sports_news():
    text_file = os.path.join(current_app.root_path, 'static/data/sports.txt')
    get_sports_news(text_file)

    text = open(text_file, encoding='utf-8').read()
    stop_words = [
        '오피셜', '더', '저', '점', '주', '것', '나',
        '네', '제', '의', '셜', '명', '내', '호', '등',
        '입', '전', '첫', '석', '원'
    ]
    mask_file = os.path.join(current_app.root_path, 'static/img/ball.jpg')
    img_file = os.path.join(current_app.root_path, 'static/img/sports.png')
    hanCloud(text, stop_words, mask_file, img_file)
    mtime = int(os.stat(img_file).st_mtime)
    return render_template('wordcloud/sports_res.html', menu=menu, weather=get_weather_main(),
                            mtime=mtime)