Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
searchhotcrawler
Overview
Overview
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
zhiwei
searchhotcrawler
Commits
56a2d38e
Commit
56a2d38e
authored
Jul 31, 2020
by
马黎滨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
采集预警方式修改
parent
07e166b9
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
61 additions
and
21 deletions
+61
-21
src/main/java/com/zhiwei/searchhotcrawler/crawler/DouyinHotSearchCrawler.java
+1
-1
src/main/java/com/zhiwei/searchhotcrawler/timer/BaiduHotSearchRun.java
+1
-0
src/main/java/com/zhiwei/searchhotcrawler/timer/DouyinHotSearchRun.java
+4
-2
src/main/java/com/zhiwei/searchhotcrawler/timer/SougoHotSearchRun.java
+4
-2
src/main/java/com/zhiwei/searchhotcrawler/timer/ThreadOneRun.java
+1
-0
src/main/java/com/zhiwei/searchhotcrawler/timer/ToutiaoHotSearchRun.java
+4
-2
src/main/java/com/zhiwei/searchhotcrawler/timer/WeiboHotSearchRun.java
+4
-2
src/main/java/com/zhiwei/searchhotcrawler/timer/WeiboTopicRun.java
+2
-0
src/main/java/com/zhiwei/searchhotcrawler/timer/ZhihuChildHotSearchRun.java
+4
-2
src/main/java/com/zhiwei/searchhotcrawler/timer/ZhihuHotSearchRun.java
+4
-2
src/main/java/com/zhiwei/searchhotcrawler/timer/ZhihuTopSearchRun.java
+4
-2
src/main/java/com/zhiwei/searchhotcrawler/util/TipsUtils.java
+28
-6
No files found.
src/main/java/com/zhiwei/searchhotcrawler/crawler/DouyinHotSearchCrawler.java
View file @
56a2d38e
...
...
@@ -40,7 +40,7 @@ public class DouyinHotSearchCrawler {
* @return List<ZhihuHotSearch> 返回类型
*/
public
static
List
<
HotSearchList
>
getMobileDouyinHotList
(){
List
<
HotSearchList
>
list
=
n
ull
;
List
<
HotSearchList
>
list
=
n
ew
ArrayList
<>()
;
String
url
=
"https://api.amemv.com/aweme/v1/hot/search/list/"
;
String
htmlBody
=
null
;
Request
request
=
RequestUtils
.
wrapGet
(
url
);
...
...
src/main/java/com/zhiwei/searchhotcrawler/timer/BaiduHotSearchRun.java
View file @
56a2d38e
...
...
@@ -48,6 +48,7 @@ public class BaiduHotSearchRun extends Thread{
if
(
Objects
.
nonNull
(
list
)
&&
!
list
.
isEmpty
())
{
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
TipsUtils
.
recoveryTips
(
"百度热搜"
,
new
Date
());
}
else
{
TipsUtils
.
sendTips
(
"百度热搜"
,
new
Date
());
}
...
...
src/main/java/com/zhiwei/searchhotcrawler/timer/DouyinHotSearchRun.java
View file @
56a2d38e
...
...
@@ -50,9 +50,11 @@ public class DouyinHotSearchRun extends Thread{
log
.
info
(
"{}, 抖音热搜榜此轮采集到的数据量为:{}"
,
new
Date
(),
Integer
.
valueOf
(
list
!=
null
?
list
.
size
()
:
0
));
if
(
list
==
null
||
list
.
size
()
==
0
){
TipsUtils
.
sendTips
(
"抖音热搜"
,
new
Date
());
}
else
{
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
TipsUtils
.
recoveryTips
(
"抖音热搜"
,
new
Date
());
}
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
log
.
info
(
"抖音热搜榜采集结束........"
);
}
...
...
src/main/java/com/zhiwei/searchhotcrawler/timer/SougoHotSearchRun.java
View file @
56a2d38e
...
...
@@ -46,9 +46,11 @@ public class SougoHotSearchRun extends Thread {
log
.
info
(
"{}, 此轮采集到的数据量为:{}"
,
new
Date
(),
Integer
.
valueOf
(
list
!=
null
?
list
.
size
()
:
0
));
if
(
list
==
null
||
list
.
size
()
==
0
){
TipsUtils
.
sendTips
(
"搜狗微信热搜"
,
new
Date
());
}
else
{
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
TipsUtils
.
sendTips
(
"搜狗微信热搜"
,
new
Date
());
}
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
log
.
info
(
"搜狗微信采集结束........"
);
}
...
...
src/main/java/com/zhiwei/searchhotcrawler/timer/ThreadOneRun.java
View file @
56a2d38e
...
...
@@ -39,6 +39,7 @@ public class ThreadOneRun extends Thread {
}
else
{
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
TipsUtils
.
sendTips
(
"腾讯新闻"
,
new
Date
());
}
}
}
src/main/java/com/zhiwei/searchhotcrawler/timer/ToutiaoHotSearchRun.java
View file @
56a2d38e
...
...
@@ -42,9 +42,11 @@ public class ToutiaoHotSearchRun extends Thread{
log
.
info
(
"{}, 今日头条此轮采集到的数据量为:{}"
,
new
Date
(),
Integer
.
valueOf
(
list
!=
null
?
list
.
size
()
:
0
));
if
(
list
==
null
||
list
.
size
()
==
0
){
TipsUtils
.
sendTips
(
"今日头条热搜"
,
new
Date
());
}
else
{
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
TipsUtils
.
sendTips
(
"今日头条热搜"
,
new
Date
());
}
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
log
.
info
(
"今日头条热搜采集结束........"
);
}
...
...
src/main/java/com/zhiwei/searchhotcrawler/timer/WeiboHotSearchRun.java
View file @
56a2d38e
...
...
@@ -40,9 +40,11 @@ public class WeiboHotSearchRun extends Thread{
log
.
info
(
"{}, 微博此轮采集到的数据量为:{}"
,
new
Date
(),
Integer
.
valueOf
(
list
!=
null
?
list
.
size
()
:
0
));
if
(
list
==
null
||
list
.
size
()
==
0
){
TipsUtils
.
sendTips
(
"微博热搜"
,
new
Date
());
}
else
{
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
TipsUtils
.
sendTips
(
"微博热搜"
,
new
Date
());
}
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
}
}
src/main/java/com/zhiwei/searchhotcrawler/timer/WeiboTopicRun.java
View file @
56a2d38e
...
...
@@ -40,6 +40,8 @@ public class WeiboTopicRun extends Thread{
log
.
info
(
"{}, 微博话题此轮采集到的数据量为:{}"
,
new
Date
(),
Integer
.
valueOf
(
list
!=
null
?
list
.
size
()
:
0
));
if
(
list
==
null
||
list
.
size
()
==
0
){
TipsUtils
.
sendTips
(
"微博话题"
,
new
Date
());
}
else
{
TipsUtils
.
sendTips
(
"微博话题"
,
new
Date
());
}
List
<
Document
>
data
=
new
ArrayList
<>();
for
(
HotSearchList
topic
:
list
){
...
...
src/main/java/com/zhiwei/searchhotcrawler/timer/ZhihuChildHotSearchRun.java
View file @
56a2d38e
...
...
@@ -44,9 +44,11 @@ public class ZhihuChildHotSearchRun extends Thread {
log
.
info
(
"{}, 知乎{}话题此轮采集到的数据量为:{}"
,
new
Date
(),
name
,
Integer
.
valueOf
(
list
!=
null
?
list
.
size
()
:
0
));
if
(
list
==
null
||
list
.
size
()
==
0
)
{
TipsUtils
.
sendTips
(
"知乎热搜"
+
name
+
"分类"
,
new
Date
());
}
else
{
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
TipsUtils
.
sendTips
(
"知乎热搜"
+
name
+
"分类"
,
new
Date
());
}
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
log
.
info
(
"知乎{}话题热榜采集结束..."
,
name
);
ZhiWeiTools
.
sleep
(
3000
);
}
...
...
src/main/java/com/zhiwei/searchhotcrawler/timer/ZhihuHotSearchRun.java
View file @
56a2d38e
...
...
@@ -47,9 +47,11 @@ public class ZhihuHotSearchRun extends Thread{
log
.
info
(
"{}, 知乎此轮采集到的数据量为:{}"
,
new
Date
(),
Integer
.
valueOf
(
list
!=
null
?
list
.
size
()
:
0
));
if
(
list
==
null
||
list
.
size
()
==
0
){
TipsUtils
.
sendTips
(
"知乎热搜"
,
new
Date
());
}
else
{
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
TipsUtils
.
sendTips
(
"知乎热搜"
,
new
Date
());
}
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
log
.
info
(
"知乎话题采集结束........"
);
}
...
...
src/main/java/com/zhiwei/searchhotcrawler/timer/ZhihuTopSearchRun.java
View file @
56a2d38e
...
...
@@ -39,9 +39,11 @@ public class ZhihuTopSearchRun extends Thread {
log
.
info
(
"{}, 知乎热搜此轮采集到的数据量为:{}"
,
new
Date
(),
Integer
.
valueOf
(
list
!=
null
?
list
.
size
()
:
0
));
if
(
list
==
null
||
list
.
size
()
==
0
){
TipsUtils
.
sendTips
(
"知乎热搜榜单"
,
new
Date
());
}
else
{
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
TipsUtils
.
sendTips
(
"知乎热搜榜单"
,
new
Date
());
}
List
<
Document
>
data
=
hotSearchCacheDAO
.
addData
(
list
);
hotSearchDAO
.
addHotSearchList
(
data
);
log
.
info
(
"知乎热搜话题采集结束........"
);
}
}
src/main/java/com/zhiwei/searchhotcrawler/util/TipsUtils.java
View file @
56a2d38e
package
com
.
zhiwei
.
searchhotcrawler
.
util
;
import
com.zhiwei.searchhotcrawler.dao.HotSearchListDAO
;
import
org.checkerframework.checker.units.qual.A
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.
Date
;
import
java.util.
*
;
/**
* 预警发送
*/
public
class
TipsUtils
{
private
static
Long
timeDifference
=
5
*
60
*
1000L
;
private
static
Long
timeDifference
=
10
*
60
*
1000L
;
private
static
String
key
=
"a8e26ce3-8aaa-4d3e-bcf6-30b81526050b"
;
private
Logger
logger
=
LoggerFactory
.
getLogger
(
TipsUtils
.
class
);
private
static
Map
<
String
,
Date
>
typeTips
=
new
HashMap
<>();
//未采集到数据发送预警信息
public
static
void
sendTips
(
String
type
,
Date
time
){
HotSearchListDAO
hotSearchListDAO
=
new
HotSearchListDAO
();
//获取数据库最后一条数据判断该程序几分钟没有采集到数据
Date
lastTime
=
hotSearchListDAO
.
getLastTimeByType
(
type
);
if
(
time
.
getTime
()
-
lastTime
.
getTime
()
>
timeDifference
){
//发送预警
String
crawlerContent
=
String
.
format
(
"%s已经采集数据异常"
,
type
);
// QYWechatUtil.send(key, QYWechatUtil.MSGTYPE_TEXT, crawlerContent,
// null, null);
if
(!
typeTips
.
containsKey
(
type
)){
//发送预警
String
crawlerContent
=
String
.
format
(
"%s数据采集异常"
,
type
);
QYWechatUtil
.
send
(
key
,
QYWechatUtil
.
MSGTYPE_TEXT
,
crawlerContent
,
null
,
null
);
}
typeTips
.
put
(
type
,
time
);
}
}
//数据采集恢复发送通知
public
static
void
recoveryTips
(
String
type
,
Date
time
){
if
(
typeTips
.
containsKey
(
type
)){
//最后一次未采集到数据的时间
Date
lastTime
=
typeTips
.
get
(
type
);
//两者比较,相差10分钟以上认为恢复采集
if
(
time
.
getTime
()
-
lastTime
.
getTime
()
>
timeDifference
){
typeTips
.
remove
(
type
);
//发送恢复通知
String
crawlerContent
=
String
.
format
(
"%s数据采集恢复正常"
,
type
);
QYWechatUtil
.
send
(
key
,
QYWechatUtil
.
MSGTYPE_TEXT
,
crawlerContent
,
null
,
null
);
}
}
}
}
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