gdq.py 文件源码

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

项目:sopel-modules 作者: phixion 项目源码 文件源码
def gdq(bot, trigger):
    now = datetime.utcnow()
    now = now.replace(tzinfo=timezone.utc)
    delta = datetime(2018,1,7,16,30,tzinfo=timezone.utc) - now
    textdate = "January 7"
    url = 'https://gamesdonequick.com/schedule'
    try:
        x = requests.get(url).content
    except:
        return bot.say("GDQ is {0} days away ({1})".format(delta.days,textdate))
    bs = BeautifulSoup(x)
    try:
        run = bs.find("table",{"id":"runTable"}).tbody
    except:
        return bot.say("GDQ is {0} days away ({1})".format(delta.days, textdate))
    try:
        gdqstart = datetime.strptime(run.td.getText(), '%Y-%m-%dT%H:%M:%SZ')
        gdqstart = gdqstart.replace(tzinfo=timezone.utc)
    except:
        return bot.say("GDQ is {0} days away ({1})".format(delta.days, textdate))
    (game, runner, console, comment, eta, nextgame, nextrunner, nexteta, nextconsole, nextcomment) = getinfo(run,now)
    if not nextgame:
        return bot.say("GDQ is {0} days away ({1})".format(delta.days,textdate))
    if now < gdqstart:
        tts = gdqstart - now
        if tts.days <= 3:
            return bot.say("GDQ is {0}H{1}M away.  First game: {2} by {3} ETA: {4} Comment: {5} | https://gamesdonequick.com/schedule".format(int(tts.total_seconds() // 3600),int((tts.total_seconds() % 3600) // 60), nextgame, nextrunner, nexteta, nextcomment))
        else:
            return bot.say("GDQ is {0} days away ({1}) | https://gamesdonequick.com/schedule".format(tts.days,gdqstart.strftime('%m/%d/%Y')))

    if nextgame == 'done':
        return bot.say("GDQ is {0} days away ({1} [estimated])".format(delta.days,textdate))
    if game:
        if comment:
            bot.say("Current Game: {0} by {1} ETA: {2} Comment: {3} | Next Game: {4} by {5} | http://www.twitch.tv/gamesdonequick | https://gamesdonequick.com/schedule".format(game, runner, eta, comment, nextgame, nextrunner))
        else:
            bot.say("Current Game: {0} by {1} ETA: {2} | Next Game: {3} by {4} | http://www.twitch.tv/gamesdonequick | https://gamesdonequick.com/schedule".format(game, runner, eta, nextgame, nextrunner))
    else:
        bot.say("Current Game: setup?? | Next Game {0} by {1} | http://www.twitch.tv/gamesdonequick | https://gamesdonequick.com/schedule".format(nextgame, nextrunner))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号