FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python_scripts/utils.py at master · meliber/python_scripts · GitHub
meliber
python_scripts
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python_scripts
/
utils.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
68 lines (54 loc) · 1.6 KB
Breadcrumbs
python_scripts
/
utils.py
Copy path
File metadata and controls
68 lines (54 loc) · 1.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import
json
import
re
import
time
from
http
.
cookies
import
SimpleCookie
from
imageio
import
imread
from
wordcloud
import
WordCloud
import
jieba
.
analyse
def
word_segment
(
text
):
# 分词处理
jieba
.
analyse
.
set_stop_words
(
"./stopwords.txt"
)
words
=
jieba
.
cut
(
text
)
from
collections
import
Counter
result
=
Counter
(
words
).
most_common
(
20
)
print
(
result
)
tags
=
jieba
.
analyse
.
extract_tags
(
text
,
topK
=
20
)
print
(
tags
)
if
__name__
==
'__main__'
:
text
=
open
(
"text.txt"
,
encoding
=
"utf-8"
).
read
()
word_segment
(
text
)
pass
def
word_cloud
(
texts
):
"""
根据文本生成词云图片
"""
data
=
" "
.
join
(
text
for
text
in
texts
)
mask_img
=
imread
(
'./python-logo.png'
,
flatten
=
True
)
wordcloud
=
WordCloud
(
font_path
=
'/Library/Fonts//华文黑体.ttf'
,
background_color
=
'white'
,
mask
=
mask_img
).
generate
(
data
)
plt
.
imshow
(
wordcloud
)
plt
.
axis
(
'off'
)
plt
.
savefig
(
'./wordcloud.jpg'
,
dpi
=
600
)
def
cookie
(
s
):
from
http
.
cookies
import
SimpleCookie
rawdata
=
s
cookie
=
SimpleCookie
()
cookie
.
load
(
rawdata
)
# Even though SimpleCookie is dictionary-like, it internally uses a Morsel object
# which is incompatible with requests. Manually construct a dictionary instead.
cookies
=
{}
for
key
,
morsel
in
cookie
.
items
():
cookies
[
key
]
=
morsel
.
value
return
cookie
def
format_duration
(
duration
):
"""
格式化时长
:param duration 毫秒
"""
total_seconds
=
int
(
duration
/
1000
)
minute
=
total_seconds
//
60
seconds
=
total_seconds
%
60
return
f'
{
minute
:02
}
:
{
seconds
:02
}
'
Back
|
FazBrowse Home
|
New Git URL