python dota2数据 1 API
python dota2数据 1 比赛历史
注册API Key
https://steamcommunity.com/dev/apikey
安装dota2api
使用python的dota2api库来调用API: pip3 install dota2api
参考文档
http://dota2api.readthedocs.io/en/latest/installation.html
获取最近5场使用英雄ID
添加API KEY:
在linux中: export D2_API_KEY=xxxxx
也可在python文件中初始化时将KEY作为dota2api.Initialise()的参数。
查找API
查找相关函数发现查询比赛用到的函数为get_match_history(),其参数为:
- account_id 包含玩家ID
- hero_id 查询的对应英雄的比赛,每个英雄对应一个ID
- game_mode 游戏模式
- skill 水平等级
- min_players 最少玩家数量
- league_id 所属联赛ID
- start_at_match_id 起始比赛ID
- matches_requested 查询数量,默认为100
- tournament_games_only 是否只包含联赛比赛
所有参数均为可选。
在这里我们需要用到的仅有account_id和matches_requested。
再查看get_matches_history()函数的返回内容:
{num_results - Number of matches within a single responsetotal_results - Total number of matches for this queryresults_remaining - Number of matches remaining to be retrieved with subsequent API calls[matches] - List of matches for this response{match_id - Unique match IDmatch_seq_num - Number indicating position in which this match was recordedstart_time - Unix timestamp of beginning of matchlobby_type - See lobby_type table[player] - List of players in the match{account_id - Unique account IDplayer_slot - Player's position within the teamhero_id - Unique hero ID}}
}
返回的是一个dictionary对象,其中最主要的是matches键,该值为一个list对象,其中包含了所查询的所有比赛信息。解析得到每一场比赛对应的dictionary,再进一步解析得到比赛的详细信息,如比赛ID,所有玩家ID和所用英雄ID。
其中matches中的players在原文档中显示为player,经测试应为players。
get_match_history.py
import dota2api
import sys
#初始化api
api = dota2api.Initialise()#接收命令行参数
#我的dota2用户ID
my_id = sys.argv[1]
#请求的比赛场数
matches = sys.argv[2]
#调用get_match_history函数
match_history = api.get_match_history(account_id = my_id, matches_requested = matches)
#解析获得的match_history字典对象,取其中的matches键
matches = match_history['matches']
#逐个解析每场比赛
for m in matches:#获取比赛IDm_id = m['match_id']#获取所有玩家players = m['players']#逐个解析每个玩家for p in players:#寻找自己if p['account_id'] == int(my_id):#获取所用英雄IDh_id = p['hero_id']breakprint('match id: ', m_id, 'hero: ', h_id)
python dota2数据 1 API相关推荐
- python dota2数据 2 英雄名和胜负
python dota2数据 2 英雄名和胜负 将英雄id转化为英雄名 API 查询英雄id和名字对应表的函数为get_heroes(),返回值为一个dictionary. {count - Numb ...
- python dota2数据 3 下载胜负数据
python dota2数据 3 下载胜负数据 目标:下载每场比赛获胜方或战败方的5个英雄,用于后续分析. 由于get_match_history()返回的内容中并不包括比赛胜负,还需要对每一场比赛使 ...
- GitHub 4K+Star!SpaceX火箭数据开放API接口,可用Python进行抓取分析
(推荐搜索) 梅宁航 发自 凹非寺 量子位 报道 | 公众号 QbitAI 马斯克用火箭把人送上天,SpaceX粉丝把火箭有关信息贴到GitHub. 4k+ Star,GitHub热榜,SpaceX粉 ...
- python 美团api接口对接_震惊!SpaceX火箭数据开放API接口,可用Python进行数据分析...
点击上方"数据管道",选择"置顶星标"公众号 干货福利,第一时间送达 梅宁航 发自 凹非寺 量子位 报道 | 公众号 QbitAI 马斯克用火箭把人送上天,Sp ...
- python爬去新浪微博_!如何通过python调用新浪微博的API来爬取数据
python抓取新浪微博,求教 爬手机端 可以参考的代码, #-*-coding:utf8-*- import smtplib from email.mime.text import MIMEText ...
- Dota2数据Dota2接口电竞api开发比分网分享
Dota2数据Dota2接口电竞api开发比分网分享@TOC 数据来自marz数据alan@marzesport.com 1.获取赛事 接口:{{host1}}/api/series/9870? {& ...
- 【Python】使用CDS API下载ECMWF气候数据
[Python]使用CDS API下载ECMWF气候数据 数据集简介 最近需要气象数据算东西,找到EC的数据~ECMWF是欧洲中期天气预报中心,他们的ERA模型提供全球的气象再分析和预报数据,最新的数 ...
- python 实现对地图的点击_利用python和百度地图API实现数据地图标注的方法
如题,先上效果图: 主要分为两大步骤 使用python语句,通过百度地图API,对已知的地名抓取经纬度 使用百度地图API官网的html例程,修改数据部分,实现呈现效果 一.使用python语句,通过 ...
- python爬虫怎么爬同一个网站的多页数据-如何用Python爬数据?(一)网页抓取
如何用Python爬数据?(一)网页抓取 你期待已久的Python网络数据爬虫教程来了.本文为你演示如何从网页里找到感兴趣的链接和说明文字,抓取并存储到Excel. 需求 我在公众号后台,经常可以收到 ...
最新文章
- 初识Android四大组件之一Activity(活动)
- Charles+安卓模拟器 抓取https请求
- Codeforces Round #700 (Div. 1) C. Continuous City 构造 + 二进制
- 新记录 Core 2 Duo E8600 被超频到6.25GHz
- Linux下Wireshark的Lua: Error during loading 和 couldn't run /usr/bin/dumpcap in child process 的解决方案
- SQL Server 全文索引创建
- mybatis log4j 在日志中打印sql_SpringBoot整合MyBatis+详细打印执行SQL语句
- php冒泡排序的用途,浅谈php冒泡排序
- mysql函数第一次返回字符串_Mysql字符串处理函数详细介绍、总结
- tensorflow手动实现算法之二多元线性回归
- Unity3D中GPS定位信息及经纬度转换方法
- 大学学python用记笔记吗_Python 应该怎么学?
- 安卓逆向系列教程 4.2 分析锁机软件
- windows版微信Hook开发SDK之C#版-微信二次开发
- 微信可以显示你的足迹了,快试试
- android+xposed插件,初探Xposed 插件开发
- redis 在32位系统安装以及使用
- 【个人网站搭建】服务器、域名准备
- LANDESK8.8版本操作说明书之服务器安装
- mysql数据库执行mysqladmin flush-hosts方法
热门文章
- WCH USB转多串口芯片相关型号
- GPS卫星授时服务器(GPS北斗授时钟系统)实施部署方案
- 互动投影技术的四大优势
- 双11数据大屏直播 / 双11作战大屏
- 【cs231n Lesson4】Backpropagation
- 基于visual Studio2013解决C语言竞赛题之0516人来人往
- 远程诊断爆发前夜,谁在领跑主动安全服务?
- OLDboy-python第八期运维教程
- 恒压供水(3托3) 功能: 三拖三(3台变频3台水泵),3台水泵循环软启,定时轮换工作
- VS2010环境下MFC使用DataGrid绑定数据源以及控件注册问题解决