《明日方舟》Python版公開招募工具

zhouzl發表於2019-06-13

工具介紹

根據輸入的標籤,快速找出能夠招募4星,5星幹員的標籤組合,比如刷出了 重灌 | 男 | 支援 |術師 | 先鋒 五個標籤,輸入效果如下:

《明日方舟》Python版公開招募工具

注意:不支援高階幹員和資深高階幹員標籤

使用環境

  1. 安裝python3
  2. 安裝模組:requests、BeautifulSoup4

程式碼

import requests, sys, bs4, itertools

all_tags = set()

def parseData(data):
    worker_infos = []
    bsObj = bs4.BeautifulSoup(data, "html.parser")
    details = bsObj.findAll("div",{"class": "contentDetail"})
    for detail in details:
        if u"公開招募" not in detail.attrs["data-param1"]:
            continue
        name = detail.find("a").attrs["title"].strip()
        profes = detail.attrs["data-param1"].split(",")[0].strip()
        sex = detail.attrs["data-param1"].split(",")[1].strip()
        star = detail.attrs["data-param2"].strip()
        tags = set()
        for tag in detail.findAll("span", {"class": "tagText"}):
            tags.add(tag.getText().strip())
            all_tags.add(tag.getText().strip())
        tags.add(profes)
        tags.add(sex)
        all_tags.add(profes)
        all_tags.add(sex)
        info = [tags, star, "%s(%s星)" % (name, star)]
        worker_infos.append(info)
    return worker_infos


def printTip():
    tip = "\n可選標籤:\n"
    count = 0
    for tag in all_tags:
        tip = tip + tag + " | "
        count += 1
        if count % 9 == 0:
            tip += "\n"
    tip += "\n"
    print(tip)


def checkTags(tags):
    for tag in tags:
        if tag not in all_tags:
            print("\n" + tag + " 為無效標籤")


def getCombs(tags):
    combs = []
    for i in range(len(tags)):
        for iter in itertools.combinations(tags, i + 1):
            combs.append(set(iter))
    return combs


def getWorkers(tags, worker_infos):
    ret = []
    combs = getCombs(tags)
    for comb in combs:
        workers = []
        over4 = True
        for worker in worker_infos:
            if comb <= worker[0]:
                if int(worker[1]) == 4 or int(worker[1]) == 5:
                    workers.append(worker)
                elif int(worker[1]) == 3:
                    over4 = False
        if over4 == True and len(workers) > 0:
            ret.append([comb, workers])
    return ret


def printWorkers(workers):
    for worker in workers:
        tip = "\n| "
        for tag in worker[0]:
            tip = tip + tag + " | "
        tip += "可以招募以下幹員:\n"
        for info in worker[1]:
            tip = tip + info[2] + "\n"
        print(tip)

url = "http://wiki.joyme.com/arknights/公開招募工具"
res = requests.get(url)

if res.status_code == requests.codes.ok:
    infos = parseData(res.text)
    printTip()
        
    while True:
        input_tags = input("請輸入標籤,使用空格隔開:\n").split()
        checkTags(input_tags)
        
        workers = getWorkers(input_tags, infos)
        if len(workers) > 0:
            printWorkers(workers)
        else:
            print("不能招聘高星幹員")
        print("--------------------------------------\n")
else:
    print("獲取資料失敗")

資料來源

公開招募工具

相關文章