python guild_stats.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python guild_stats.py相关的知识,希望对你有一定的参考价值。

import requests
import json
import datetime
import pytz

GUILD_NAME = 'SSWL18'
GUILD_ID = 'rBa13VyKRl2CZAZRZtM2FA'
API_URL = 'https://gameinfo.albiononline.com/api/gameinfo/guilds/'

def cur_utc(local_tz='Europe/Moscow'):
    dt_now = datetime.datetime.now()
    local_pytz = pytz.timezone(local_tz)
    return local_pytz.localize(dt_now).astimezone(pytz.utc)

r = requests.get(API_URL + GUILD_ID + '/members')
members = json.loads(r.text)

with open(GUILD_NAME + '_' + cur_utc().strftime('%Y-%m-%d') + '.txt', 'w') as f:

    f.write('Scraping time: ' + str(cur_utc()) + ' (UTC)\n\n')

    f.write('\t'.join([
        'Name',
        'KillFame',
        'DeathFame',
        'FameRatio'
    ]) + '\n')

    members_sorted = sorted(members, key=lambda x: (-x['KillFame'], -x['DeathFame'], x['Name']))

    for m in members_sorted:
        f.write('\t'.join([
            m['Name'],
            str(m['KillFame']),
            str(m['DeathFame']),
            str(m['FameRatio'])
        ]) + '\n')

以上是关于python guild_stats.py的主要内容,如果未能解决你的问题,请参考以下文章

001--python全栈--基础知识--python安装

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python