私人定制之疫情监控

  • 2020-1-28 23:11
    流程优化和内容说明增加

2019-nCoV 牵动很多人的身心,借助自动化更友好的关注自己所关心的数据,在这紧张的情况下稍稍放松一下自己的身心。数据来源于丁香园,教程中涉及到企业微信的推送,相关教程这里找到:

目前提供三个功能

  • 关注地区感染人数变化通知
  • 相关最新消息通知
  • 查询相关地区确认人数

流程里面涉及了两个 link 节点,微信内容后面的链接的是 高级推送 节点, 处理微信发送前面连接是 企业微信 服务器节点

修改内容如下, 应用id和部门的id

image

部门id获取方式如下:

实时新闻 下面的微信播送内容里面修改自己关注的省份信息,格式如下 :

实时新闻和疫情推送都会判断消息是否已经推送过,当没有记录时以当前时间作为判断, 测试的时候可以把注释去掉

同时启用了微信消息去重功能,0是关闭,默认时间是1800s就是半个小时重复的消息不能推送

pushbear 流程示例

相关流程

[{"id":"fce8e4cb.4f33e8","type":"tab","label":"疫情提醒","disabled":false,"info":""},{"id":"dec5b0a0.5e498","type":"http request","z":"fce8e4cb.4f33e8","name":"","method":"GET","ret":"txt","url":"https://3g.dxy.cn/newh5/view/pneumonia","tls":"","x":220,"y":120,"wires":[["8bc5e4f1.fc6198"]]},{"id":"bf66d4fe.218f48","type":"inject","z":"fce8e4cb.4f33e8","name":"","topic":"","payload":"","payloadType":"date","repeat":"300","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":120,"wires":[["dec5b0a0.5e498"]]},{"id":"8bc5e4f1.fc6198","type":"switch","z":"fce8e4cb.4f33e8","name":"请求正常的","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":120,"wires":[["5179dd9a.0ca5a4"]]},{"id":"144cb62d.12a5da","type":"debug","z":"fce8e4cb.4f33e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":610,"y":400,"wires":[]},{"id":"5179dd9a.0ca5a4","type":"function","z":"fce8e4cb.4f33e8","name":"基于正则提取内容","func":"const newsReg = /<script id=\"getTimelineService\">.+?window.getTimelineService\\s=\\s(\\[{.+?\\])}catch\\(e\\){}<\\/script>/\nconst dataReg = /<script id=\"getListByCountryTypeService1\">.+?window.getListByCountryTypeService1\\s=\\s(\\[{.+?\\])}catch\\(e\\){}<\\/script>/\nconst regAreaStat = /<script id=\"getAreaStat\">.+?window.getAreaStat\\s=\\s(\\[{.+?\\])}catch\\(e\\){}<\\/script>/\nconst regStatistics = /<script id=\"getStatisticsService\">.+?window.getStatisticsService\\s=\\s({.+?)}catch\\(e\\){}<\\/script>/\nconst payload = msg.payload\n\n\n\nlet news  = payload.match(newsReg);\nlet data  = payload.match(dataReg);\nlet areaStat  = payload.match(regAreaStat);\nlet statistics  = payload.match(regStatistics);\n\n\nconst newMsg = {}\n\nif (news && news.length > 1) {\n    newMsg.news = JSON.parse(news[1])\n}\n\nif (statistics && statistics.length > 1) {\n    newMsg.statistics = JSON.parse(statistics[1])\n}\n\nconst areaObj = {}\nif (areaStat && areaStat.length > 1) {\n    const ad = JSON.parse(areaStat[1])\n    newMsg.areaStat = ad\n    \n    for (let i = 0; i < ad.length; i++) {\n        areaObj[ad[i].provinceShortName] = ad[i]\n    }\n    newMsg.areaObj = areaObj\n}\n\nconst retObj = {}\n\nif (data && data.length > 1) {\n    const n = JSON.parse(data[1])\n    newMsg.payload = n\n    \n    for (let i = 0; i < n.length; i++) {\n        retObj[n[i].provinceShortName] = n[i]\n    }\n    newMsg.retObj = retObj\n    \n}\n\nif (newMsg.payload && newMsg.areaStat && newMsg.statistics && newMsg.news) {\n    return [newMsg, null]\n}else {\n    if(msg.times > 1) {\n        return null\n    }\n    newMsg.times = 2\n    return [null, newMsg]\n}\n\n\n\n","outputs":2,"noerr":0,"x":570,"y":120,"wires":[["34b7cae3.d04fe6","b0845e10.0b21b","4844d129.1ada9"],["31aa6dfc.8c9092"]]},{"id":"34b7cae3.d04fe6","type":"function","z":"fce8e4cb.4f33e8","name":"实时新闻","func":"const keyName = 'news_last_time'\nlet lastTime = global.get(keyName) || new Date().getTime()\n\n\nconst news = msg.news\n\nif (!news) {\n    return null\n}\n\nlet n = null\nlet index = -1;\n\nfor (let i = 0; i < news.length; i++) {\n    n = news[i]\n    if (n.createTime > lastTime) {\n        index = i\n    }else {\n        break\n    }\n    \n}\n\nfor (let i = index; i >= 0; i--) {\n    node.send(news[i])\n}\n\nconst newsData = news[0]\nglobal.set(keyName, newsData.createTime)\n\n","outputs":1,"noerr":0,"x":360,"y":280,"wires":[["4841baf9.407be4"]]},{"id":"b234cb.f7707b38","type":"debug","z":"fce8e4cb.4f33e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":690,"y":220,"wires":[]},{"id":"4841baf9.407be4","type":"delay","z":"fce8e4cb.4f33e8","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"5","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":520,"y":280,"wires":[["b234cb.f7707b38","662eaf8.c549a5"]]},{"id":"31aa6dfc.8c9092","type":"delay","z":"fce8e4cb.4f33e8","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":280,"y":200,"wires":[["dec5b0a0.5e498"]]},{"id":"b0845e10.0b21b","type":"function","z":"fce8e4cb.4f33e8","name":"微信播送内容","func":"const keyName = 'pusher_last_time'\nlet lastTime = global.get(keyName) || new Date().getTime()\n//lastTime = 0\nif (msg.statistics.modifyTime - lastTime < 1000 * 3 * 60) {\n    return\n}\nglobal.set(keyName, msg.statistics.modifyTime)\n//\nconst d = new Date(msg.statistics.modifyTime)\nconst cities = ['湖北', '浙江']\nconst cityDescri = []\n\nfor (let i = 0; i < cities.length; i++) {\n    let obj = msg.areaObj[cities[i]]\n    cityDescri.push(`${obj.provinceName}, 确诊 ${obj.confirmedCount}, 死亡 ${obj.deadCount}, 治愈 ${obj.curedCount}`)\n}\nmsg.title = `全国数据统计,确诊 ${msg.statistics.confirmedCount},疑似  ${msg.statistics.suspectedCount},死亡 ${msg.statistics.deadCount},治愈 ${msg.statistics.curedCount}`\nmsg.description = `截至 ${d.toLocaleString()}(北京时间)\n全国数据统计,确诊 ${msg.statistics.confirmedCount},疑似  ${msg.statistics.suspectedCount},死亡 ${msg.statistics.deadCount},治愈 ${msg.statistics.curedCount}\n${cityDescri.join('\\n')}\n各项指标详情请点击进入查看\n`\n\nmsg.payload = {\n   \"toparty\" :  '4',\n   \"msgtype\" : \"news\",\n   \"agentid\" : \"1000006\",\n   \"news\" : {\n       \"articles\" : [\n           {\n               \"title\" : msg.title,\n               \"description\" : msg.description,\n               \"url\" : \"https://3g.dxy.cn/newh5/view/pneumonia\",\n               \"picurl\" : \"http://image.thepaper.cn/www/image/44/788/266.jpg\"\n           }\n        ]\n   },\n   \"enable_id_trans\": 1\n}\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":360,"wires":[["91a65042.d3ba1","144cb62d.12a5da"]]},{"id":"91a65042.d3ba1","type":"link out","z":"fce8e4cb.4f33e8","name":"","links":["de1dc7ef.474298"],"x":775,"y":360,"wires":[]},{"id":"662eaf8.c549a5","type":"function","z":"fce8e4cb.4f33e8","name":"微信消息内容","func":"msg.description = ``\nmsg.payload = {\n   \"toparty\" :  '4',\n   \"msgtype\" : \"news\",\n   \"agentid\" : \"1000006\",\n   \"news\" : {\n       \"articles\" : [\n           {\n               \"title\" : msg.title,\n               \"description\" : msg.summary,\n               \"url\" : msg.sourceUrl,\n               \"picurl\" : \"http://image.thepaper.cn/www/image/44/788/266.jpg\"\n           }\n        ]\n   }\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":720,"y":280,"wires":[["91a65042.d3ba1"]]},{"id":"4844d129.1ada9","type":"function","z":"fce8e4cb.4f33e8","name":"缓存疫情信息","func":"const data = msg.areaStat\nconst CACHE_P = {}\nconst CACHE_P_S = {}\n\nfor (let i = 0; i < data.length; i++) {\n        CACHE_P[data[i].provinceName] = data[i].provinceShortName\n        CACHE_P_S[data[i].provinceShortName] = data[i].provinceShortName\n        let cities = data[i].cities\n        \n        for (let c = 0; c < cities.length; c++) {\n            let city = cities[c]\n    \n            CACHE_P[city.cityName] = data[i].provinceShortName\n        }\n\n}\nconst keyName1 = 'pusher_cities_1'\nconst keyName2 = 'pusher_cities_2'\nconst keyName3 = 'CACHE_DATA'\nglobal.set(keyName1, CACHE_P)\nglobal.set(keyName2, CACHE_P_S)\nglobal.set(keyName3, msg)\n\n\nreturn msg;","outputs":1,"noerr":0,"x":780,"y":80,"wires":[[]]},{"id":"9f754fb4.c8b08","type":"link in","z":"fce8e4cb.4f33e8","name":"","links":["2f837926.c813c6"],"x":80,"y":460,"wires":[["b676040f.474648"]]},{"id":"b676040f.474648","type":"function","z":"fce8e4cb.4f33e8","name":"处理微信发送的消息","func":"const keyName1 = 'pusher_cities_1'\nconst keyName2 = 'pusher_cities_2'\nconst keyName3 = 'CACHE_DATA'\nconst CACHE_DATA = global.get(keyName3) || {}\n\nfunction getStatistics(name) {\n  if (!CACHE_DATA.areaObj) return '';\n  const provinceData = CACHE_DATA.areaObj[name]\n  //console.log(JSON.stringify(provinceData))\n  const statistics = CACHE_DATA.statistics\n\n  let cities = provinceData.cities\n  let msg = []\n  msg.push(`${provinceData.provinceShortName} 确认${provinceData.confirmedCount}例`)\n  for (let i = 0; i < cities.length; i++) {\n    let c = cities[i]\n    msg.push(`${c.cityName} 确认${c.confirmedCount}例`)\n  }\n  return `🏥疫情查询\n\n${msg.join('\\n')}\n时间: ${new Date(statistics.modifyTime).toLocaleString()}\n💊疫情播报→ t.cn/A6v1xgC0\n  `\n}\n\nconst CACHE_P = global.get(keyName1) || {}\nconst CACHE_P_S = global.get(keyName2) || {}\nconst message = msg.message\n\nif(CACHE_P[message.Content] || CACHE_P_S[message.Content]) {\n    let name = CACHE_P[message.Content] || CACHE_P_S[message.Content]\n    msg.data = getStatistics(name)\n }else {\n     return null\n }\n \n \n \n msg.payload = {\n   \"touser\" :  message.FromUserName,\n   \"agentid\" : \"1000006\",\n   \"msgtype\" : \"text\",\n   \"text\" : {\n       \"content\" : msg.data\n       \n   },\n   \"safe\":0,\n   \"enable_id_trans\": 0,\n   \"enable_duplicate_check\": 0\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"x":250,"y":460,"wires":[["57568615.fc84a8","91a65042.d3ba1"]]},{"id":"57568615.fc84a8","type":"debug","z":"fce8e4cb.4f33e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":530,"y":500,"wires":[]}]

图标乍弄进去的,大佬

哪个图标?ha还需要8个字

大神我按你的修改以后,没有提示任何错误。但是微信没有收到任何信息

认真看教程,里面都说明了,如果没有更新是没有推送的,相关的开关也可以自己关闭的

“Error: [微信推送]user & party & tag all invalid, hint: [1580734662_53_b76724e28de74d2f1a20a2ae419da84d], from ip: 117.140.122.219, more info at https://open.work.weixin.qq.com/devtool/query?e=81013
这个错误是什么意思

自己查看企业微信推送文档

大神请原谅我不知道在哪里看,但是我把高级推送换成推送。就不出现这个错误了

疫情查询用不了。不知道我哪里搞错了。装了很多微信留言的也是没反应。也不见提示错误

问问题你要描述清楚啊,你到底是流程数据没有还有推送收不到,这些都有是有对应的检查方法,请附上你做的操作是什么,不要上去就一句话,谁猜得出来

我用微信发信息。node没有接受到。但是我在企业微信应用里面是看的到了。

所以我查询疫情的时候,是没反应的。我试了几个微信留言。小爱的帖子。也是没反应

花神威武霸气侧漏

6666666666嗯,论坛牛逼

现在是不是不能用了,打开网址没有任何信息

丁香医生的网址变了,要更换网址和修改部分正则提取内容的标签.