redbull.py 文件源码

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

项目:beproudbot 作者: beproud 项目源码 文件源码
def show_redbull_history_csv(message):
    """RedBull??????????CSV?????

    :param message: slackbot?????????????class
    """
    s = Session()
    consume_hisotry = (s.query(RedbullHistory)
                       .filter(RedbullHistory.delta < 0)
                       .order_by(RedbullHistory.id.desc()))

    # func.month??????????groupby count?????
    # SQLite??MONTH()???????????Python?????
    def grouper(item):
        return item.ctime.year, item.ctime.month

    ret = []
    for ((year, month), items) in groupby(consume_hisotry, grouper):
        count = -sum(item.delta for item in items)
        ret.append(['{}/{}'.format(year, month), str(count)])

    output = StringIO()
    w = csv.writer(output)
    w.writerows(ret)

    param = {
        'token': settings.API_TOKEN,
        'channels': message.body['channel'],
        'title': 'RedBull History Check'
    }
    requests.post(settings.FILE_UPLOAD_URL,
                  params=param,
                  files={'file': output.getvalue()})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号