Novel coronavirus 2019-nCoV real-time data extraction and real-time broadcast implementation

In order to facilitate timely follow-up of this novel coronavirus 2019-nCoVthe progress of the epidemic, plan on a small program based on a line epidemic Lilas page push service, service retrieval function is as follows, for your reference!

<?php

function get_nCoV_news()
{
    $reg = '/<script id="getTimelineService">.+?window.getTimelineService\s=\s({.+?)}catch\(e\){}<\/script>/im';
    if( preg_match( $reg , file_get_contents( 'https://3g.dxy.cn/newh5/view/pneumonia' ) , $out ) )
    {
        return @json_decode( $out[1] , 1); 
    }
    return false;
}

function get_nCoV_province()
{
    $reg = '/<script id="getListByCountryTypeService1">.+?window.getListByCountryTypeService1\s=\s(\[.+?])}catch\(e\){}<\/script>/im';
    if( preg_match( $reg , file_get_contents( 'https://3g.dxy.cn/newh5/view/pneumonia' ) , $out ) )
    {
        return @json_decode( $out[1] , 1); 
    }
    return false;
}

?>

Further datav can try to use a tool such as the linkage database and retrieve data to be api visual rendering: Each component has a render方法, receive data 数据, if the components of the drawing, can be used as the update data. Wherein the code must be placed in position module.exports = (stage) => {}inside method, varCtrName.render = (data) => {}//datathe API is configured inside the corresponding components json data returned varCtrName(获取的组件).emit('global_var', 'bm_name', val);to the callback parameter assignment by hook.js, so that the data in the screenIDE components - data source types which can be used :bm_nameas a parameter, so that hook.js to the callback parameter assignment.

Between the control panel and the display screen by the communication Socket. All screen will register with the Socket server when opened. Socket server a message to the control panel, then the Socket server will broadcast to all registered to his screen.

//动态插入JS文件
function getJs(url){
    var dom = document.createElement('script');//建立一个script元素
    dom.type = 'text/javascript';//写入属性
    dom.async = 'true';
    dom.src = url;
    document.getElementsByTagName('head')[0].appendChild(dom);
}
// 如果是公网DataV,就引用公网JS文件,如果是部署版DataV,就引用内网JS文件
const jsDomain="ip";
// 导入socket.js
getJs(`http://${jsDomain}/public/socket.js`) // socket方法
getJs(`http://${jsDomain}/public/common.js`) // 通用方法
 
// 控屏
function screenControl(stage) {
// 把当前屏注册向socket服务器注册
    var screenIdMatches = location.href.match(/(screen|share)\/([a-z\d]+)/);
    var screenId = screenIdMatches && screenIdMatches.length ? screenIdMatches[2] : '';
    var groupMatches = location.search.match(/group=([a-z0-9]+)/i);
    var group = groupMatches && groupMatches.length ? groupMatches[1] : 'public';
    var broadcast = new Socket(screenId, "mytest", group);
 
    broadcast.ready(function () {
        broadcast.on(sceneName, function (data) {
            //data.Show为按钮的对应属性的值
            //代码
        })
    })
}
//-----入口-------
module.exports = (stage) => {
  let interval = setInterval(function () {
    if (Socket) {//用来确保Socke存在
      screenControl(stage);//运行上面的“控屏”方法
      clearInterval(interval);//
    }
  }, 1000)
}
Published 75 original articles · won praise 505 · views 680 000 +

Guess you like

Origin blog.csdn.net/deng_xj/article/details/104075398