minecraft python api_Minecraft 国际正版信息查询(Python)

一个 Python 小程序,可以查询到玩家正版账号的相关信息。(目前只能查到 UUID,未来支持下披风、皮肤等)

程序技术含量不高,全靠吃 https://playerdb.co/ 的接口,就当练练手(捂脸)。

只能查询 Java 版,基岩版没找到合适的 API。

授权:CC BY 3.0 国际

注意:在 51 行需要把字符串换成你的用户代理字符串!

方法:用 Chrome 访问 chrome://version/ ,将『用户代理』一行信息(Mozilla/...)复制下来。

在 51 行 'user-agent' 对应的字符串换成你的用户代理。(B 站是 101 行,因为被插了一堆换行符)

屑站不给代码框,所以你们看到的都是没有高亮的鬼玩意。

然后就是代码被屑站插了一堆换行,所以还是等知乎发布后再抄吧...

或者说想想办法把多出来的换行符删掉。

代码从下面开始

doc = '''

==============================================================

一个查询 Minecraft Java Edition 正版 ID 的小玩意

基于 playerdb.co

By CYWVS

需要联网

使用方法:>>> [command] [ID]

其中,command 如下

info  提供账号信息(目前只有 UUID)。如果 ID 为 * ,则执行多次查询。

skin  获取皮肤并保存至当前目录(未制作)

就这些了 :( 功能不全

e.g.

>>> info CYWVS

>>> info *

\t[1] >>> CYWVS

\t[2] >>> Me

\t...

\t[n] >>> *

>>> skin CYWVS

That's fucking all and enjoy it XD

(查询 info 的函数是 mc_acc_info,需要的自己在代码里拿)

==============================================================

'''

def mc_acc_info(ID):

'''

一个获取 Minecraft 账户信息的函数 | A function of getting minecraft account information

基于 playerdb.co | Be based on playerdb.co

需要联网 | Need Internet

仅支持 Java 版 | Java Edition Only

参数 | args:

ID:

玩家 ID | Player's ID

函数将返回一个字典 | This func will return a dict:

{'id' : str, 'full_uuid' : str, 'trimmed_uuid' : str}

如果账户不存在将返回 None | If the account does not exist, it will return None

By CYWVS

'''

from urllib.request import urlopen, Request, quote

from urllib.error import HTTPError

import urllib

#伪装成正常浏览器

headers = {'user-agent':'Mozilla/5.0 ...(换掉这个字符串)'}#需要替换

url = Request('https://playerdb.co/api/player/minecraft/' + quote(ID), headers = headers)

try:

r = urlopen(url, timeout = 10) #返回一个 bytes 类型的“字典”

except: #打开失败 即不存在用户名

return None

temp_scope = {'true' : True, 'false' : False} #爬虫结果包含 true 和 false ,但是它们在 Python 未定义,所以这里重新定义了

info = eval(str(r.read(), encoding = "utf-8"), temp_scope)

if info['message'] == 'Successfully found player by given ID.':

return {

'id'           : info['data']['player']['username'] ,

'full_uuid'    : info['data']['player']['id']       ,

'trimmed_uuid' : info['data']['player']['raw_id']   }

elif info['message'] == 'Mojang API lookup failed.':

return None

else: return None

def print_mc_acc_info(ID):

print()

info = mc_acc_info(ID)

if info is None:

print('\t查询失败!\n\t1. 用户名不存在\n\t2. 未联网\n\t3. playerdb.co 失效')

else:

print('\t玩家名:'     , info['id']          , sep = '')

print('\t完整的 UUID:', info['full_uuid']   , sep = '')

print('\t简化的 UUID:', info['trimmed_uuid'], sep = '')

print()

print(doc)

while True:

try:

command, Minecraft_ID = input('>>> ').split()

except:

print('\t输入不合法。')

continue

if command == 'info':

if Minecraft_ID == '*':

print('\t请多次输入用户名并回车。如果想要停止,输入 * (请不要添加更多字符包括空格)。')

IDs = []

count = 1

while True:

ID = input('\t[' + str(count) + '] >>> ')

if ID == '*': break

else:

count += 1

IDs.append(ID)

print()

count = 1

for ID in IDs:

print('\t第', count, '个结果(ID:' + ID +'):')

count += 1

print_mc_acc_info(ID)

else:

print_mc_acc_info(Minecraft_ID)

elif command == 'skin':

print('\t功能还没写。')

else:

print('\t\'', command, '\' 未定义。', sep = '')

代码从上面结束

效果

其实这东西屁用没有

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值