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
juanboy
2024-07-04 12:00:15 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
08554667455eff4c99075cb7dc81f04a7f569e9f
08554667
1 parent
9bebd200
舆情函数定义
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
1 deletions
model/topicdefine.py
utils/getTopicPageData.py
model/topicdefine.py
0 → 100644
View file @
0855466
from
utils.query
import
query
from
utils.getPublicData
import
*
articleList
=
getAllArticleData
()
commentList
=
getAllCommentsData
()
def
column_exists
(
table_name
,
column_name
):
sql
=
"SHOW COLUMNS FROM {} LIKE
%
s"
.
format
(
table_name
)
params
=
[
column_name
]
result
=
query
(
sql
,
params
,
type
=
'select'
)
return
len
(
result
)
>
0
# 添加新的标注列
def
add_label_article
():
# 为文章添加标注列
if
not
column_exists
(
'article'
,
'label'
):
sql
=
"ALTER TABLE article ADD COLUMN label TEXT NULL"
params
=
[]
query
(
sql
,
params
)
def
add_label_comments
():
# 为评论添加标注列
if
not
column_exists
(
'comments'
,
'label'
):
sql
=
"ALTER TABLE comments ADD COLUMN label TEXT NULL"
params
=
[]
query
(
sql
,
params
)
def
drop_label
():
# 删除标注列
sql
=
"ALTER TABLE article DROP COLUMN label "
params
=
[]
query
(
sql
,
params
)
def
drop_label1
():
# 删除标注列
sql
=
"ALTER TABLE comments DROP COLUMN label "
params
=
[]
query
(
sql
,
params
)
# 处理数据并添加标注
def
process_data
(
data
):
processed_data
=
testmodel
(
data
)
return
processed_data
def
testmodel
(
test
):
return
"wicao"
def
topicdefine
():
label_article
=
[]
label_comments
=
[]
for
x
in
articleList
:
label_article
.
append
((
x
[
0
],
process_data
(
x
[
5
])))
for
x
in
commentList
:
label_comments
.
append
((
x
[
5
],
process_data
(
x
[
4
])))
return
label_article
,
label_comments
# 更新数据库
def
update_data
(
label_article
,
label_comments
):
add_label_comments
()
add_label_article
()
for
row
in
label_article
:
id
,
label
=
row
sql
=
"UPDATE article SET label =
%
s WHERE id =
%
s"
params
=
[
str
(
label
),
str
(
id
)]
query
(
sql
,
params
)
for
row
in
label_comments
:
label
,
id
=
row
sql
=
"UPDATE comments SET label =
%
s WHERE authorName =
%
s"
params
=
[
str
(
label
),
str
(
id
)]
query
(
sql
,
params
)
# x,y=topicdefine()
# update_data(x,y)
drop_label
()
drop_label1
()
\ No newline at end of file
...
...
utils/getTopicPageData.py
View file @
0855466
...
...
@@ -5,7 +5,7 @@ def getTopicLen(topic):# 统计特定话题下的评论数目
topic_len
=
0
for
i
in
commentsList
:
if
i
[
9
]
==
topic
:
topic
L
en
+=
1
topic
_l
en
+=
1
return
topic_len
def
getTopicPageCreatedAtCharData
(
topic
):
# 统计特定话题的评论在每个日期的数量,并返回日期和对应的评论数量
...
...
Please
register
or
login
to post a comment