스파르트 코딩클럽
f = open("test.txt", "w", encoding="utf-8")
f.write("안녕, 스파르타!")
f.close()
with open("test.txt", "r", encoding="utf-8") as f:
lines = f.readlines()
for line in lines:
print(line)
import matplotlib.font_manager as fm
for font in fm.fontManager.ttflist:
if 'Gothic' in font.name:
print(font.name, font.fname)
from wordcloud import WordCloud
wc = WordCloud(font_path=font_path, background_color="white", width=600, height=400)
wc.generate(text)
wc.to_file("result.png")
for line in lines:
if '] [' in line:
text += line.split('] ')[2].replace('ㅋ','').replace('ㅠ','').replace('ㅜ','').replace('사진\n','').replace('이모티콘\n','').replace('삭제된 메시지입니다','')
from PIL import Image
import numpy as np
mask = np.array(Image.open('cloud.png'))
wc = WordCloud(font_path=font_path, background_color="white", mask=mask)
wc.generate(text)
wc.to_file("result_masked.png")