Toggle navigation
Toggle navigation
This project
Loading...
Sign in
万朱浩
/
Venue-Ops
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
戒酒的李白
2024-07-03 15:22:04 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
97e94c26b92c546edf5eb76b99ae071955902ea5
97e94c26
1 parent
468455eb
【app.py】路径配置
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
2 deletions
app.py
wordCloudPicture.py
app.py
View file @
97e94c2
from
flask
import
Flask
,
session
,
request
,
redirect
,
render_template
import
re
app
=
Flask
(
__name__
)
app
.
secret_key
=
'this is secret_key you know ?'
from
views.page
import
page
from
views.user
import
user
app
.
register_blueprint
(
page
.
pb
)
app
.
register_blueprint
(
user
.
ub
)
@app.route
(
'/'
)
def
hello_world
():
# put application's code here
return
session
.
clear
()
@app.before_request
def
before_reuqest
():
pat
=
re
.
compile
(
r'^/static'
)
if
re
.
search
(
pat
,
request
.
path
):
return
elif
request
.
path
==
'/user/login'
or
request
.
path
==
'/user/register'
:
return
elif
session
.
get
(
'username'
):
return
return
redirect
(
'/user/login'
)
@app.route
(
'/<path:path>'
)
def
catch_all
(
path
):
return
render_template
(
'404.html'
)
if
__name__
==
'__main__'
:
app
.
run
()
\ No newline at end of file
app
.
run
()
...
...
wordCloudPicture.py
0 → 100644
View file @
97e94c2
import
jieba
from
wordcloud
import
WordCloud
import
matplotlib.pyplot
as
plt
from
PIL
import
Image
,
ImageDraw
from
pymysql
import
*
import
json
import
numpy
as
np
def
stopWordList
():
return
[
line
.
strip
()
for
line
in
open
(
'./model/stopWords.txt'
,
encoding
=
'utf8'
)
.
readlines
()]
def
get_img
(
field
,
tableName
,
targetImgSrc
,
resImgSrc
):
con
=
connect
(
host
=
'localhost'
,
user
=
'root'
,
password
=
'root'
,
database
=
'weiboarticles'
,
port
=
3306
,
charset
=
'utf8mb4'
)
cuser
=
con
.
cursor
()
sql
=
f
'select {field} from {tableName}'
cuser
.
execute
(
sql
)
data
=
cuser
.
fetchall
()
text
=
''
for
item
in
data
:
text
+=
item
[
0
]
cuser
.
close
()
con
.
close
()
cut
=
jieba
.
cut
(
text
)
newCut
=
[]
for
word
in
cut
:
if
word
not
in
stopWordList
():
newCut
.
append
(
word
)
string
=
' '
.
join
(
newCut
)
img
=
Image
.
open
(
targetImgSrc
)
img_arr
=
np
.
array
(
img
)
wc
=
WordCloud
(
background_color
=
"#fff"
,
mask
=
img_arr
,
font_path
=
'STHUPO.TTF'
)
wc
.
generate_from_text
(
string
)
fig
=
plt
.
figure
(
1
)
plt
.
imshow
(
wc
)
plt
.
axis
(
'off'
)
plt
.
savefig
(
resImgSrc
,
dpi
=
500
)
# get_img('content','comments','./static/comment.jpg','./static/commentCloud.jpg')
get_img
(
'content'
,
'article'
,
'./static/content.jpg'
,
'./static/contentCloud.jpg'
)
...
...
Please
register
or
login
to post a comment