篮球即时比分api接口调用示例代码 - 编程思维

分享篮球即时比分api接口调用的示例代码,可查看在线调用文档,需注册下https://www.feijing88.com/bas...

package com.huaying.demo.basketball;
 
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @API: 2.即时变化的比分数据
 * @Website: https://www.feijing88.com
 */
public class BasketballChange {
 
    public static void main(String[] args) {
        try {
            String content = getContent();
 
            JAXBContext jaxbContext = JAXBContext.newInstance(ChangeList.class);
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
 
            ChangeList list = (ChangeList) unmarshaller.unmarshal(new ByteArrayInputStream(content.getBytes()));
            list.getChangeList().forEach(System.out::println);
 
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
 
    /**
     * 获取API返回内容
     * <p>
     * Note: 这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容
     */
    private static String getContent() {
        try {
            StringBuilder builder = new StringBuilder();
            List<String> lines = Files.readAllLines(Paths.get("./src/main/resources/BasketballChange.xml"), StandardCharsets.UTF_8);
            lines.forEach(line -> builder.append(line));
            return builder.toString();
        } catch (Throwable t) {
            t.printStackTrace();
            return "";
        }
    }
 
 
    @XmlRootElement(name = "c")
    public static class ChangeList {
        @XmlElement(name = "h")
        private List<String> itemList;
 
        public List<Change> getChangeList() {
            return itemList.stream().map(s -> {
                Change change = new Change();
                change.parse(s);
                return change;
            }).collect(Collectors.toList());
        }
    }
 
    public static class Change {
        private String matchId;
        private int matchStatus;
        private String remainTime;
        private int homeScore;
        private int homeScoreFirst;
        private int homeScoreSecond;
        private int homeScoreThird;
        private int homeScoreFourth;
        private int homeScoreFirstOT;
        private int homeScoreSecondOT;
        private int homeScoreThirdOT;
        private int awayScore;
        private int awayScoreFirst;
        private int awayScoreSecond;
        private int awayScoreThird;
        private int awayScoreFourth;
        private int awayScoreFirstOT;
        private int awayScoreSecondOT;
        private int awayScoreThirdOT;
 
        public void parse(String data) {
            String[] values = data.split("\\^");
            matchId = values[0];
            matchStatus = parseInt(values[1]);
            remainTime = values[2];
            homeScore = parseInt(values[3]);
            homeScoreFirst = parseInt(values[5]);
            homeScoreSecond = parseInt(values[7]);
            homeScoreThird = parseInt(values[9]);
            homeScoreFourth = parseInt(values[11]);
            homeScoreFirstOT = parseInt(values[16]);
            homeScoreSecondOT = parseInt(values[18]);
            homeScoreThirdOT = parseInt(values[20]);
            awayScore = parseInt(values[4]);
            awayScoreFirst = parseInt(values[6]);
            awayScoreSecond = parseInt(values[8]);
            awayScoreThird = parseInt(values[10]);
            awayScoreFourth = parseInt(values[12]);
            awayScoreFirstOT = parseInt(values[17]);
            awayScoreSecondOT = parseInt(values[19]);
            awayScoreThirdOT = parseInt(values[21]);
        }
 
        private int parseInt(String data) {
            return data == null || data.isEmpty() ? 0 : Integer.valueOf(data);
        }
 
        @Override
        public String toString() {
            return "Change{" +
                    "matchId='" + matchId + '\'' +
                    ", matchStatus=" + matchStatus +
                    ", remainTime='" + remainTime + '\'' +
                    ", homeScore=" + homeScore +
                    ", homeScoreFirst=" + homeScoreFirst +
                    ", homeScoreSecond=" + homeScoreSecond +
                    ", homeScoreThird=" + homeScoreThird +
                    ", homeScoreFourth=" + homeScoreFourth +
                    ", homeScoreFirstOT=" + homeScoreFirstOT +
                    ", homeScoreSecondOT=" + homeScoreSecondOT +
                    ", homeScoreThirdOT=" + homeScoreThirdOT +
                    ", awayScore=" + awayScore +
                    ", awayScoreFirst=" + awayScoreFirst +
                    ", awayScoreSecond=" + awayScoreSecond +
                    ", awayScoreThird=" + awayScoreThird +
                    ", awayScoreFourth=" + awayScoreFourth +
                    ", awayScoreFirstOT=" + awayScoreFirstOT +
                    ", awayScoreSecondOT=" + awayScoreSecondOT +
                    ", awayScoreThirdOT=" + awayScoreThirdOT +
                    '}';
        }
    }
}

API 返回数据如下(部分):


Change{matchId='358749', matchStatus=-1, remainTime='', homeScore=86, homeScoreFirst=28, homeScoreSecond=22, homeScoreThird=13, homeScoreFourth=23, homeScoreFirstOT=0, homeScoreSecondOT=0, homeScoreThirdOT=0, awayScore=52, awayScoreFirst=20, awayScoreSecond=11, awayScoreThird=14, awayScoreFourth=7, awayScoreFirstOT=0, awayScoreSecondOT=0, awayScoreThirdOT=0}
Change{matchId='358761', matchStatus=2, remainTime='06:50', homeScore=20, homeScoreFirst=14, homeScoreSecond=6, homeScoreThird=0, homeScoreFourth=0, homeScoreFirstOT=0, homeScoreSecondOT=0, homeScoreThirdOT=0, awayScore=44, awayScoreFirst=31, awayScoreSecond=13, awayScoreThird=0, awayScoreFourth=0, awayScoreFirstOT=0, awayScoreSecondOT=0, awayScoreThirdOT=0}

版权声明:本文版权归作者所有,遵循 CC 4.0 BY-SA 许可协议, 转载请注明原文链接
https://segmentfault.com/a/1190000019902854

leetcode 622:设计循环队列 design circular queue - 编程思维

LeetCode 622:设计循环队列 Design Circular Queue 首先来看看队列这种数据结构: 队列:先入先出的数据结构 在 FIFO 数据结构中,将首先处理添加到队列中的第一个元素。 如上图所示,队列是典型的 FIFO 数据结构。插入(insert)操作也称作入队(enqueue),新元素始终被

leetcode 155:最小栈 min stack - 编程思维

LeetCode 155:最小栈 Min Stack 设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈。 push(x) -- 将元素 x 推入栈中。 pop() -- 删除栈顶的元素。 top() -- 获取栈顶元素。 getMin() -- 检索栈中的最小元素。 Design a

leetcode 430:扁平化多级双向链表 flatten a multilevel doubly linked list - 编程思维

您将获得一个双向链表,除了下一个和前一个指针之外,它还有一个子指针,可能指向单独的双向链表。这些子列表可能有一个或多个自己的子项,依此类推,生成多级数据结构,如下面的示例所示。 扁平化列表,使所有结点出现在单级双链表中。您将获得列表第一级的头部。 You are given a doubly linked list w

go 爬虫之 http 请求 quickstart - 编程思维

前几天在 "知乎想法" 谈到了一个话题,如何模仿学习,举了通过 net/http client 模仿 Pyhton 的requests的例子。但并未实践,难道想法真的只能是想法吗?当然不是,于是我决定先暂停一周 GO 笔记,来实践下自己的想法。 有些新的知识,我们可以通过模仿学习 本文将通过 GO 实现 request

pycharm的基本使用 - 编程思维

PyCharm是我一直在使用的python编辑器,今天具体讲一下PyCharm的使用。 下载 首先是下载PyCharm,PyCharm的下载地址:https://www.jetbrains.com/pycharm/这个是一个商业软件,大家可以选择购买,或者选择试用(免费试用30天),或者在网上找激活码。 创建项目 下载

python秒算24点,行还是不行? - 编程思维

周末闲来无事,看到隔壁家的老王在和隔壁家的媳妇玩24点,就进屋看了看。发现老王是真不行啊,那不行,这也不行。 就连个24点都玩不过他媳妇,给他媳妇气的,啥都不能满足,这不能,那也不能。 我坐下来和他媳妇玩了两把,那都是无出其右,把把赢! 我要走的时候,他媳妇还挽留我多玩几把,有意思。 为了能让老王在他媳妇面前抬起头来

prophet模型预测2018京东订单量 - 编程思维

背景 最近,即将要实习的公司经理给了一个关于Prophet预测模型的案例,让我去学习一下怎么调参数。正好我早就想体验一下传说中“会一手调参数,就可以在硕士圈混”的感受了,🤣🤣🤣。本文主要通过简单介绍Prophet模型及其重要参数,再结合京东订单量的例子,加深对Prophet模型的了解。 认识Prophet模型 简介 P