Exemple #1
0
def sports_news():
    menu = {
        'ho': 0,
        'da': 1,
        'ml': 0,
        'se': 0,
        'co': 0,
        'cg': 0,
        'cr': 0,
        'st': 0,
        'wc': 1
    }
    sports_wordCloud()
    text_file = os.path.join(current_app.root_path, 'static/data/sports.txt')

    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('sports_res.html',
                           menu=menu,
                           weather=get_weather_main(),
                           mtime=mtime)
Exemple #2
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)