Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
M
meta_base_code
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
黎涛
meta_base_code
Commits
18ee510f
Commit
18ee510f
authored
Nov 13, 2020
by
litaolemo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
d8ca25b4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
0 deletions
+75
-0
daily_search_word_count.py
task/daily_search_word_count.py
+75
-0
No files found.
task/daily_search_word_count.py
0 → 100644
View file @
18ee510f
# -*- coding:UTF-8 -*-
# @Time : 2020/11/13 11:08
# @File : daily_search_word_count.py
# @email : litao@igengmei.com
# @author : litao
# coding=utf-8
import
hashlib
import
pymysql
# from elasticsearch import Elasticsearch
import
datetime
# from maintenance.func_send_email_with_file import send_file_email
# import zipfile
# es = Elasticsearch([
# {
# 'host': '172.16.31.17',
# 'port': 9200,
# }, {
# 'host': '172.16.31.11',
# 'port': 9200,
# }])
if
__name__
==
"__main__"
:
tag_names_list
=
[]
tag_names_list_week
=
[]
all_data_day
=
[]
all_data_week
=
[]
db_zhengxing_eagle
=
pymysql
.
connect
(
host
=
"172.16.30.136"
,
port
=
3306
,
user
=
"doris"
,
password
=
"o5gbA27hXHHm"
,
db
=
"doris_prod"
,
charset
=
'utf8'
,
cursorclass
=
pymysql
.
cursors
.
DictCursor
)
zhengxing_cursor
=
db_zhengxing_eagle
.
cursor
()
for
count_date
in
range
(
0
,
3
):
tag_names_list_week
=
[]
date
=
datetime
.
datetime
.
now
()
.
date
()
-
datetime
.
timedelta
(
days
=
count_date
)
print
(
str
(
date
))
date_str
=
date
.
strftime
(
"
%
Y
%
m
%
d"
)
yesterday_date
=
datetime
.
datetime
.
now
()
.
date
()
-
datetime
.
timedelta
(
days
=
count_date
+
1
)
sql
=
"""select keywords,sum(sorted) as nums,sum(uv) as uvs from api_search_words where is_delete = 0 and
create_time >= "{yesterday_date}" and create_time <= "{date}" group by keywords order by nums desc"""
.
\
format
(
yesterday_date
=
str
(
yesterday_date
),
date
=
str
(
date
))
print
(
sql
)
zhengxing_cursor
.
execute
(
"set names 'UTF8'"
)
zhengxing_cursor
.
execute
(
sql
)
data
=
zhengxing_cursor
.
fetchall
()
for
name
in
list
(
data
):
word
=
name
.
get
(
"keywords"
,
None
)
nums
=
name
.
get
(
"nums"
,
0
)
uv
=
name
.
get
(
"uvs"
,
0
)
tag_names_list_week
.
append
([
word
,
nums
,
uv
,
date_str
])
db
=
pymysql
.
connect
(
host
=
'172.16.40.158'
,
port
=
4000
,
user
=
'st_user'
,
passwd
=
'aqpuBLYzEV7tML5RPsN1pntUzFy'
,
db
=
'jerry_prod'
)
cursor
=
db
.
cursor
()
for
item
in
tag_names_list_week
:
word
,
nums
,
uv
,
date_str
=
item
partition_date
=
date_str
pid
=
hashlib
.
md5
((
partition_date
+
word
)
.
encode
(
"utf8"
))
.
hexdigest
()
insert_sql
=
"""replace into daily_search_word_count(
word, nums, uv,date_str,pid) VALUES(
'{word}',{nums},{uv},'{date_str}','{pid}');"""
.
format
(
word
=
word
,
nums
=
nums
,
uv
=
uv
,
date_str
=
date_str
,
pid
=
pid
)
print
(
insert_sql
)
# cursor.execute("set names 'UTF8'")
res
=
cursor
.
execute
(
insert_sql
)
db
.
commit
()
print
(
res
)
\ No newline at end of file
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