Skip to content

Commit

Permalink
支持多个平台推送,支持多uid
Browse files Browse the repository at this point in the history
  • Loading branch information
guorutao committed Dec 29, 2020
1 parent 850c4f9 commit ca6dca4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 26 deletions.
44 changes: 32 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,42 @@
#### 配置参数
参考:application.yml文件配置即可
```
# 配置自己的server酱key
# 参考地址:http://sc.ftqq.com/3.version
key: b082eb2****
# 什么值得买爆料人id:
# 参考:https://zhiyou.smzdm.com/member/9687682701/baoliao/
uid: 9687682701
# server酱有每天次数(重要重要重要)限制建议:60秒钟一次,已经做了重复限制,相同商品不会重复推送
corn: 0/59 * * * * ?
#测试频率:十秒一次
key:
#支持两种配置:【pushPlus】或者【serverJ】,二选一
#pushPlus参考:http://pushplus.hxtrip.com/,不限制次数,不用github账号
#serverJ参考:http://sc.ftqq.com/3.version ,需要github账号,限制次数
type: pushPlus
# 对应平台的key
value: SCU68113********
#爆料人id:https://zhiyou.smzdm.com/member/9687682701/baoliao/ 参考这个链接
blr:
#支持多个爆料人id,用英文都好隔开即可
uids: 9687682701,2031093162,3050600933
# 频率十秒一次 ,
#corn: 0/10 * * * * ?
# 三十秒一次
#corn: 0/30 * * * * ?
# 一分钟一次
corn: 0/59 * * * * ?
```

#### server酱参数
文档之间看官网即可
#### serverJ酱参数
文档之间看官网即可(需要github账号,限制次数)

文档:http://sc.ftqq.com/3.version

https://s3.ax1x.com/2020/12/29/rHchjg.png

![serverJ酱参数](https://s3.ax1x.com/2020/12/29/rHchjg.png)

#### pushPlus参数

文档之间看官网即可(不限制次数,不用github账号),比较推荐这个更简单点。

文档:http://pushplus.hxtrip.com/

http://sc.ftqq.com/3.version
https://s3.ax1x.com/2020/12/29/rHguVA.png
![serverJ酱参数](https://s3.ax1x.com/2020/12/29/rHguVA.png)

#### 启动
ZdmPushApplication.class
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/unfbx/zdm_push/processor/ZdmPageProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.processor.PageProcessor;

import java.util.HashMap;
import java.util.Map;

/**
* @Description
* @Author Grt
Expand All @@ -18,7 +21,7 @@ public class ZdmPageProcessor implements PageProcessor {
/**
* 防止重复发送,比较上次发送数据
*/
private String data = "";
private Map<String,Integer> data = new HashMap<>();
@Override
public void process(Page page) {
String url = page.getHtml().xpath("/html/body/div[1]/div[1]/div[3]/div[2]/div[1]/a").$("a","href").toString();
Expand All @@ -33,12 +36,14 @@ public void process(Page page) {
page.putField("flag",false);
if(StringUtils.isNotBlank(page.getHtml().xpath("/html/body/div[1]/div[1]/div[3]/div[2]/div[1]/a").$("a","href").toString())){
String[] split = url.split("/");
if(data.equals(split[split.length-1])){
//存在不推送
if(data.get(split[split.length-1]) != null){
page.putField("flag",false);
return;
}
page.putField("flag",true);
data = split[split.length-1];
//不存在存进去
data.put(split[split.length-1],1);
}

}
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/com/unfbx/zdm_push/task/ZdmTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import lombok.extern.java.Log;
import us.codecraft.webmagic.Spider;

/**
Expand All @@ -14,13 +15,14 @@
* @Date 2020-12-11
*/
@Component
@Log
public class ZdmTask {

private int i;
@Autowired
private ZdmPipeline zdmPipeline;
@Value("${uid}")
private String uid;
@Value("${blr.uids}")
private String[] uids;

ZdmPageProcessor zdmPageProcessor = new ZdmPageProcessor();

Expand All @@ -29,10 +31,16 @@ public class ZdmTask {
*/
@Scheduled(cron = "${corn}")
public void execute() {
Spider.create(zdmPageProcessor)
.addUrl("https://zhiyou.smzdm.com/member/"+uid+"/baoliao/")
.addPipeline(zdmPipeline)
.thread(1)
.run();
if(uids == null || uids.length <= 0){
log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~没有配置需要监控的博主~~~~~~~~~~~~~~~~~~~~~~~~~~");
return;
}
for (String uid : uids){
Spider.create(zdmPageProcessor)
.addUrl("https://zhiyou.smzdm.com/member/"+uid+"/baoliao/")
.addPipeline(zdmPipeline)
.thread(1)
.run();
}
}
}
12 changes: 8 additions & 4 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ spring:
application:
name: zdm
key:
#支持两种配置:pushPlus或者serverJ,二选一
#支持两种配置:【pushPlus】或者【serverJ】,二选一
#pushPlus参考:http://pushplus.hxtrip.com/,不限制次数,不用github账号
#serverJ参考:http://sc.ftqq.com/3.version ,需要github账号,限制次数
type: pushPlus
# 对应平台的key
value: 9b343***
value: SCU6811*********
#爆料人id:https://zhiyou.smzdm.com/member/9687682701/baoliao/ 参考这个链接
uid: 9687682701
blr:
#多个爆料人id用英文隔开即可
uids: 9687682701,2031093162,3050600933
# 频率十秒一次 ,
corn: 0/10 * * * * ?
#corn: 0/10 * * * * ?
# 三十秒一次
#corn: 0/30 * * * * ?
# 一分钟一次
corn: 0/59 * * * * ?

0 comments on commit ca6dca4

Please sign in to comment.