WordPress极简博客 WordPress极简博客
  • 新鲜事
  • 战疫情
  • UI素材
    • UI素材
    • 电商/节日
    • PPT
      • 节日庆典
      • 工作汇报
      • 商业计划书
    • word
      • 简历竞聘
      • 合同/公文
  • 创客头条
    • 音乐分享
    • 初创文章
    • 极客头条
    • 生活趣事
    • 生活日记
    • 防骗指南
  • 编程教学
    • API日记
    • Linux安全栏目
      • Linux运维安全汇总
      • DDOS攻击防护
      • XSS攻击防护
      • SQL安全防护
    • Python技术栏目
      • Python基础入门
      • Python基础结构
    • WordPress技术栏目
      • WP主题
      • WordPress技术教程
      • RIPRO主题美化
    • WordPress漏洞发布
    • 技术教程汇总
    • 严选源码
  • 专题
  • 基友
  • 隐私
  • 注册
    登录
立即登录
  • 首页
  • 云优化
  • 新疫情
  • 新鲜事
    • 热文
    • 极客
    • 生活
  • 技术篇
    • WP主题
    • 技术教程
    • Python入门
    • Python基础
  • 专题篇
  • 友链君
首页 技术教程(干货) WP主题疫情实时数据API(转自丁香园数据)

WP主题疫情实时数据API(转自丁香园数据)

夏柔 2月 16, 2020

现在冠状病毒肆虐,假期不断充值,大家都被迫困在家里,闲来无事在导航站添加了新型冠状病毒 COVID-19 疫情实时数据,效果如下:(演示站:http://us.wpon.cn)

WP主题疫情实时数据API(转自丁香园数据)-WordPress极简博客

数据来源于丁香园,数据api来源于:BlankerL

添加方法

WebStack Pro 导航主题复制下方代码到主题文件 index.php 的搜索模块下方(注意主题的 <?php   ?>标签)。

其他主题请放到需要显示的位置,然后自行调整 css 样式。

?>
<div class="row row-sm" style="position: relative;">
    <div class="col-12">
        <div class="card" style="color:#fff;background-color:#61adff">
            <div class="card-body py-2">
                <div class="d-flex flex-fill text-sm">
                    <span>新型冠状病毒数据</span>
                    <div class="flex-fill"></div>
                    <div>截至 <span id="updateTime">0000-00-00 00:00:00</span></div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-6 col-md-3">
        <div class="card" style="color:#fff;background-color:#FF464D">
            <div class="card-body py-3">
                <div class="d-flex flex-fill text-md mb-4">
                    <span>确诊</span>
                    <div class="flex-fill"></div>
                    <span class="text-sm">较昨日:<span id="confirmedIncr">00</span></span>
                </div>
                <h1 id="confirmedCount" class="h2 m-0">000</h1>
            </div>
        </div>
    </div>
    <div class="col-6 col-md-3">
        <div class="card" style="color:#fff;background-color:#FFA746">
            <div class="card-body py-3">
                <div class="d-flex flex-fill text-md mb-4">
                    <span>疑似</span>
                    <div class="flex-fill"></div>
                    <span class="text-sm">较昨日:<span id="suspectedIncr">00</span></span>
                </div>
                <h1 id="suspectedCount" class="h2 m-0">000</h1>
            </div>
        </div>
    </div>
    <div class="col-6 col-md-3">
        <div class="card" style="color:#fff;background-color:#67727d">
            <div class="card-body py-3">
                <div class="d-flex flex-fill text-md mb-4">
                    <span>死亡</span>
                    <div class="flex-fill"></div>
                    <span class="text-sm">较昨日:<span id="deadIncr">00</span></span>
                </div>
                <h1 id="deadCount" class="h2 m-0">000</h1>
            </div>
        </div>
    </div>
    <div class="col-6 col-md-3">
        <div class="card" style="color:#fff;background-color:#02B88C">
            <div class="card-body py-3">
                <div class="d-flex flex-fill text-md mb-4">
                    <span>治愈</span>
                    <div class="flex-fill"></div>
                    <span class="text-sm">较昨日:<span id="curedIncr">00</span></span>
                </div>
                <h1 id="curedCount" class="h2 m-0">000</h1>
            </div>
        </div>
    </div>
    <div class="col-12 col-md-6 d-none d-md-block">
        <div class="card" style="">
            <div class="card-body py-3">
                <h1 class="h5 mb-3">病毒资料</h1>
                <div class="overflow-auto" style="height:100px">
                <div id="bd_note">
                    <div class="text-sm mb-2"><i class="iconfont icon-point mr-2"></i><span id="note1"></span></div>
                    <div class="text-sm mb-2"><i class="iconfont icon-point mr-2"></i><span id="note2"></span></div>
                    <div class="text-sm mb-2"><i class="iconfont icon-point mr-2"></i><span id="note3"></span></div>
                </div>
                </div>
                <div class="d-flex flex-fill text-xs text-muted pt-2 mb-n2">
                    <span>数据来源:<a href= "https://ncov.dxy.cn/ncovh5/view/pneumonia" target="_blank" rel='external nofollow' style="color:#6c757d">丁香园</a></span>
                    <div class="flex-fill"></div>
                    <span><a href= "https://lab.isaaclin.cn/nCoV/" target="_blank" rel='external nofollow' style="color:#6c757d">API</a></span>
                </div>
            </div>
        </div>
    </div>
    <div class="col-12 col-md-6">
        <div class="card" style="">
            <div class="card-body py-3">
                <h1 class="h5 mb-3">疫情资讯</h1>
                <div class="overflow-auto" style="height:100px">
                    <div id="bd_news">
                    </div>
                </div>
                <div class="d-flex flex-fill text-xs text-muted pt-2 mb-n2">
                    <span>数据来源:<a href= "https://ncov.dxy.cn/ncovh5/view/pneumonia" target="_blank" rel='external nofollow' style="color:#6c757d">丁香园</a></span>
                    <div class="flex-fill"></div>
                    <span><a href= "https://lab.isaaclin.cn/nCoV/" target="_blank" rel='external nofollow' style="color:#6c757d">API</a></span>
                </div>
            </div>
        </div>
    </div>
    <div id="bd-loading" class="ajax-loading text-center rounded" style="position:absolute;display:flex;width:100%;top:-1rem;bottom:.5rem;background:rgba(125,125,125,.5)"><div id="bd-success" class="col align-self-center"><i class="iconfont icon-loading icon-spin icon-2x"></i></div></div>
</div>
<script>
    let url = "https://lab.isaaclin.cn/nCoV/api/overall";
    let newsurl = "https://lab.isaaclin.cn/nCoV/api/news";

    $.getJSON(url,function(data,status){
        let res = data["results"][0];
        $("#confirmedCount").text(res["confirmedCount"]);
        $("#confirmedIncr").text(res["confirmedIncr"] ? res["confirmedIncr"] : '待更新'); 
        $("#suspectedCount").text(res["suspectedCount"]);
        $("#suspectedIncr").text(res["suspectedIncr"] ? res["suspectedIncr"] : '待更新'); 
        $("#curedCount").text(res["curedCount"]);
        $("#curedIncr").text(res["curedIncr"] ? res["curedIncr"] : '待更新'); 
        $("#deadCount").text(res["deadCount"]);
        $("#deadIncr").text(res["deadIncr"] ? res["deadIncr"] : '待更新'); 
        $("#note1").text(res["note1"]); 
        $("#note2").text(res["note2"]); 
        $("#note3").text(res["note3"]); 
        $("#updateTime").text(timestampToTime(res["updateTime"],1)); 
        $("#bd-loading").hide();
    }).fail(function () {
        $("#bd-success").html('被api服务器屏蔽,请稍后再试,说明:<a href= "https://lab.isaaclin.cn/nCoV/" rel="external nofollow" target="_blank">API</a>'); 
    });
    $.getJSON(newsurl,function(data,status){
        let res = data["results"][0];
        let html = '';
        for(let item of data['results']) {
            html += '<div class="text-sm mb-2">'+timestampToTime(item['pubDate'],1,true)+'<a class="ml-2" href="'+item['sourceUrl']+'" target="_blank" rel="external nofollow">'+item['title']+'</a></div>';
        }
        
        $("#bd_news").html(html);
    }).fail(function () {
        $("#bd-success").html('被api服务器屏蔽,请稍后再试,说明:<a href= "https://lab.isaaclin.cn/nCoV/" rel="external nofollow" target="_blank">API</a>'); 
    });
    function timestampToTime(timestamp,s,time = false) {
        var date = new Date(timestamp * s);
        Y = date.getFullYear() + '-';
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        D = date.getDate() + ' ';
        h = date.getHours();
        m = ':' + (date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes());
        s = ':' + (date.getSeconds() < 10 ? '0'+(date.getSeconds()) : date.getSeconds());
        if(time)
            return h+m;
        else
            return Y+M+D+h+m+s;
    }
</script>
<?php

数据获取不到请使用站长接口:

let url = "https://china.wpon.cn/novelcoronavirus/DXY-COVID-19-Data-master/json/DXYOverall.json";
let newsurl = "https://china.wpon.cn/novelcoronavirus/DXY-COVID-19-Data-master/json/DXYNews.json";

更换地址:上面代码第100-101行直接替换即可!

注意:GitHub数据库仓库有1个小时左右的数据延时,但获取速度稳定。

演示排版:

新型冠状病毒数据

截至 2020-02-16 17:07:16

确诊

较昨日:2014

68589

疑似

较昨日:1918

8228

死亡

较昨日:142

1666

治愈

较昨日:1485

9586

4092882
等 4092882 人赞过
J2dcg1.png
猜你喜欢
  • Nginx添加跨域限制规则
  • 使用测速脚本对国内Linux服务器进行测速
  • 域名爆破之自动化信息收集脚本
  • 利用免费接口实现国家开放大学刷网课脚本
  • RiProV2定制导航条
  • 判断是否在微信浏览器打开
  • 微信内自动播放音频非百度方案
  • 利用veImageX加速您的网站,想不快都难!
  • SWAPIDC减少注册信息及防刷注册量教学
  • Python实现定时发送每日早报及生活指数
07 10月, 2024
10月07日,星期一, 每天60秒读懂世界!
夏柔
站长
夏山如碧 - 怀柔天下
1726
文章
25
评论
58145K
获赞
版权声明

文章采用创作共用版权 CC BY-NC-ND/2.5/CN 许可协议,与本站观点无关。

如果您认为本文侵犯了您的版权信息,请与我们联系修正或删除。
投诉邮箱wpsite@aliyun.com

栏目推荐
Python基础入门33
WordPress技术教程267
前沿技术情报所22
城市创新——新消费11
最近有哪些不可错过的热文23
程序员的养生之道0
节
春
  • 新鲜事
  • 疫情实况
  • UI素材
  • 技术教程
  • 音乐分享
  • 专题
  • 友情
  • 隐私
  • 云优化
Copyright © 2019-2025 WordPress极简博客. Designed by 夏柔. 辽公网安备21010502000474号 辽ICP备19017037号-2