games.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Harmonbot 作者: Harmon758 项目源码 文件源码
def generate_erps_dict(self):
        async with clients.aiohttp_session.get("http://www.umop.com/rps101/alloutcomes.htm") as resp:
            data = await resp.text()
        raw_text = BeautifulSoup(data).text
        raw_text = re.sub("\n+", '\n', raw_text).strip()
        raw_text = raw_text.lower().replace("video game", "game")
        raw_text = raw_text.split('\n')[:-1]
        objects = {}
        object = raw_text[0].split()[-1]
        object_info = {}
        for line in raw_text[1:]:
            if line[0].isdigit():
                objects[object] = object_info
                object = line.split()[-1]
                object_info = {}
            else:
                object_info[line.split()[-1]] = ' '.join(line.split()[:-1])
        objects[object] = object_info
        with open("data/erps_dict.json", 'w') as erps_file:
            json.dump(objects, erps_file, indent = 4)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号