[개발] 스몬 좀 잘해보자[2]

in #sct5 years ago

이전 글에서 스몬 대전 정보가 모여있는 사이트에서 특정 조건의 대전 정보를 읽는 방법을 알아보았습니다.

오늘은 이 모든 정보를 받아서 파일에 저장하는 부분을 설명합니다.
저장되어 있는 정보는 leagues 별, 마나 별,규칙 별로 별도 html 문서로 검색이 가능합니다. 따라서 아래와 같이 전체 자료를 가져오는 함수를 만들어 봅니다.

특이하게도 규칙(ruleset)에 공란이 '_'로 채워져 있어서 이것을 제거하는 부분을 추가하였습니다. 대전 정보를 추출할 html 문서 명을 만든 후 해당 문서로 받을 수 있는 대전 정보를 파일에 저장하는 부분까지 추가하였습니다.

RULE_SETS = [
    "Aim True","Armored Up","Back to Basics","Broken Arrows","Earthquake","Fog of War","Healed Out","Keep Your Distance",
    "Little League","Lost Legendaries","Melee Mayhem","Reverse Speed","Rise of the Commons","Silenced Summoners","Standard"
]
LEAGUES = ['novice', 'bronze', 'silver', 'gold', 'diamond']
def    make_battle_data(self) :
    for league in LEAGUES :
        for mana in range(15, 33) :
            print('[', mana,']')
            deck_info = []
            for rule in RULE_SETS :
                rule = rule.replace(' ', '_')
                rule = rule.replace(' ', '_')
                rule = rule.replace(' ', '_')
                self.ext_holgers(deck_info, league, mana, rule)
        
            name = league + str(mana)
            if (deck_info != []) :
                save_to_file_json(name, deck_info)

파일에 저장하는 형태는 최대한 간단하게 하였습니다. 저장되어 있는 형태는 아래와 같습니다.

{
        "mana": 27,
        "num_won": 10,
        "num_lose": 1,
        "color": "Green"
        "ruleset": "Aim True",
        "summoner": "Prince Rennyn",
        "monsters": {
            "0": "Flesh Golem",
            "1": "Earth Elemental",
            "2": "Swamp Thing",
            "3": "Wood Nymph",
            "4": "Magi of the Forest",
            "5": "Highland Archer"
        },
    },

아래 그림과 같이 스몬에서 최근에 한 대전 정보를 검색할 수 있는 api가 있습니다.
https://steemmonsters.com/battle/history?player=계정명

그리고 그 구조는 아래와 같습니다.

조금 복잡하기는 하지만 details에 보면 누가 어떤 덱으로 이겼는지 정보도 확인이 가능합니다.

https://beempy.com 에서 제공하는 대전 정보 뿐 아니라, 본인이 한 게임 정보도 누적을 시키는 것이 좋을 것 같습니다. 두 사이트의 정보가 상이한 부분이 있기 때문에 본인이 정의한 정보로 변환하여 보관하고 있어야 할 것 같습니다. 특히 대전 정보는 최근 50개에 대한 정보만 볼 수 있기 때문에 수시로 백업을 받아 놓는 것이 좋을 것 같습니다.

Sort:  

jcar토큰 보팅입니다.
8월이 30일, 31일 이틀밖에 남지 않았네요. 잘 마무리 하시기 바랍니다. ^^

Thank you for your continued support towards JJM. For each 1000 JJM you are holding, you can get an additional 1% of upvote. 10,000JJM would give you a 11% daily voting from the 700K SP virus707 account.

Hi @tradingideas!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 4.404 which ranks you at #2447 across all Steem accounts.
Your rank has dropped 49 places in the last three days (old rank 2398).

In our last Algorithmic Curation Round, consisting of 136 contributions, your post is ranked at #91.

Evaluation of your UA score:
  • Some people are already following you, keep going!
  • You have already convinced some users to vote for your post, keep trying!
  • Try to work on user engagement: the more people that interact with you via the comments, the higher your UA score!

Feel free to join our @steem-ua Discord server

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63117.29
ETH 2601.03
USDT 1.00
SBD 2.76