Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
graces_es6
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rank
graces_es6
Commits
c3072b04
Commit
c3072b04
authored
Oct 30, 2020
by
李小芳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
ead6de1e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
diary.py
talos/models/diary/diary.py
+23
-0
diary_transfer.py
trans2es/utils/diary_transfer.py
+1
-0
No files found.
talos/models/diary/diary.py
View file @
c3072b04
...
@@ -184,6 +184,29 @@ class Diary(models.Model):
...
@@ -184,6 +184,29 @@ class Diary(models.Model):
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
''
return
''
def
get_keynote_sentence
(
user_id
=
None
,
id
=
None
):
try
:
result
=
Problems
.
objects
.
filter
(
user_id
=
user_id
,
topic_type__in
=
[
"0"
,
"1"
,
"2"
],
diary_id
=
id
,
is_online
=
True
)
.
order_by
(
'-last_modified'
)
.
values_list
(
"answer"
,
flat
=
True
)[:
5
]
content_list
=
[]
for
content
in
result
:
ss
=
content
.
encode
(
'utf-16'
,
'surrogatepass'
)
.
decode
(
'utf-16'
)
dr
=
re
.
compile
(
r"<[^>]+>"
,
re
.
S
)
str_re
=
dr
.
sub
(
""
,
ss
)
para
=
re
.
sub
(
'([;。!?
\
?])([^”’])'
,
r"\1\n\2"
,
str_re
)
# 单字符断句符
para
=
re
.
sub
(
'(
\
.{6})([^”’])'
,
r"\1\n\2"
,
para
)
# 英文省略号
para
=
re
.
sub
(
'(
\
…{2})([^”’])'
,
r"\1\n\2"
,
para
)
# 中文省略号
para
=
re
.
sub
(
'([;。!?
\
?][”’])([^,。!?
\
?])'
,
r'\1\n\2'
,
para
)
para
=
para
.
rstrip
()
# 段尾如果有多余的\n就去掉它
for
con
in
para
.
split
(
"
\n
"
):
##切分文章成一句一句的内容
r
=
'[’!"#$
%
&
\'
()*+,-./:;=?@[
\\
]^_`{|}~。?,]+'
cos
=
con
.
lstrip
(
r
)
content_list
.
append
(
cos
)
return
content_list
except
:
logging
.
error
(
"catch exception,logins:
%
s"
%
traceback
.
format_exc
())
return
[]
def
get_new_diary_score
(
self
):
def
get_new_diary_score
(
self
):
try
:
try
:
...
...
trans2es/utils/diary_transfer.py
View file @
c3072b04
...
@@ -68,6 +68,7 @@ def get_diary(instance):
...
@@ -68,6 +68,7 @@ def get_diary(instance):
'stick_priority'
:
d
.
stick_priority
,
'stick_priority'
:
d
.
stick_priority
,
"title"
:
d
.
title
,
"title"
:
d
.
title
,
"answer"
:
d
.
get_diary_answer
(),
"answer"
:
d
.
get_diary_answer
(),
"keynote_sentence"
:
d
.
get_keynote_sentence
(
d
.
user_id
,
d
.
id
)
if
int
(
float
(
d
.
content_level
))
>=
3
else
""
,
"good_click"
:
d
.
get_good_click
,
"good_click"
:
d
.
get_good_click
,
"is_promote"
:
d
.
get_cpc
,
"is_promote"
:
d
.
get_cpc
,
"is_low_quality"
:
d
.
get_low_quality
"is_low_quality"
:
d
.
get_low_quality
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment