最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Minecraft 國際正版信息查詢(Python)

2020-07-04 19:49 作者:CYWVS  | 我要投稿

一個 Python 小程序,可以查詢到玩家正版賬號的相關(guān)信息。(目前只能查到 UUID,未來支持下披風(fēng)、皮膚等)

程序技術(shù)含量不高,全靠吃 https://playerdb.co/ 的接口,就當(dāng)練練手(捂臉)。

只能查詢 Java 版,基巖版沒找到合適的 API。

授權(quán):CC BY 3.0 國際

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

方法:

  1. 用 Chrome 訪問 chrome://version/ ,將『用戶代理』一行信息(Mozilla/...)復(fù)制下來。

  2. 在 51 行 'user-agent' 對應(yīng)的字符串換成你的用戶代理。(B 站是 101?行,因為被插了一堆換行符)

屑站不給代碼框,所以你們看到的都是沒有高亮的鬼玩意。

然后就是代碼被屑站插了一堆換行,所以還是等知乎發(fā)布后再抄吧...

或者說想想辦法把多出來的換行符刪掉。

代碼從下面開始

doc = '''

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

一個查詢 Minecraft Java Edition 正版 ID 的小玩意

基于 playerdb.co

By CYWVS

需要聯(lián)網(wǎng)


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

? ? 其中,command 如下

? ? ? ? info? 提供賬號信息(目前只有 UUID)。如果 ID 為 * ,則執(zhí)行多次查詢。

? ? ? ? skin? 獲取皮膚并保存至當(dāng)前目錄(未制作)

? ? 就這些了 :( 功能不全

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 的函數(shù)是 mc_acc_info,需要的自己在代碼里拿)

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

'''


def mc_acc_info(ID):

? ? '''

? ? 一個獲取 Minecraft 賬戶信息的函數(shù) | A function of getting minecraft account information

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

? ? 需要聯(lián)網(wǎng) | Need Internet

? ? 僅支持 Java 版 | Java Edition Only


? ? 參數(shù) | args:?

? ? ? ? ID:?

? ? ? ? ? ? 玩家 ID | Player's ID?


? ? 函數(shù)將返回一個字典 | 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} #爬蟲結(jié)果包含 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. 未聯(lián)網(wǎng)\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, '個結(jié)果(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 = '')

代碼從上面結(jié)束

效果





















其實這東西屁用沒有


Minecraft 國際正版信息查詢(Python)的評論 (共 條)

分享到微博請遵守國家法律
台中市| 闽侯县| 富锦市| 开阳县| 衡山县| 通化县| 土默特左旗| 嘉定区| 东乌珠穆沁旗| 永和县| 教育| 师宗县| 廉江市| 奉节县| 龙口市| 安平县| 安龙县| 三门县| 霍城县| 三门峡市| 鲁甸县| 东至县| 中超| 巴东县| 南安市| 和田市| 望江县| 皮山县| 休宁县| 莲花县| 洛川县| 开原市| 团风县| 连州市| 建瓯市| 合山市| 丘北县| 乡宁县| 石林| 普兰店市| 宜宾县|