新增周报脚本
This commit is contained in:
parent
9934c35166
commit
dbafe755e9
62
taptap/tap_weekly_mail.py
Normal file
62
taptap/tap_weekly_mail.py
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from ops.mmysql import MysqlBase
|
||||||
|
from ops.plog import define_logger
|
||||||
|
import logging
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
define_logger("/data/logs/ops/tap_weekly.log")
|
||||||
|
|
||||||
|
db_conf = {'user': 'mytga', 'pswd': 'gzVwh4HGR68G', 'host': '10.10.3.5', 'db': 'external_data'}
|
||||||
|
|
||||||
|
|
||||||
|
class TapWeeklyReport:
|
||||||
|
def __init__(self, day):
|
||||||
|
self.day = day
|
||||||
|
self.db_conn = MysqlBase(**db_conf)
|
||||||
|
self.limit = 20
|
||||||
|
|
||||||
|
def get_weekly_days(self):
|
||||||
|
weekly_days = []
|
||||||
|
for i in range(0, 7):
|
||||||
|
current_day = (datetime.datetime.strptime(self.day, '%Y-%m-%d') - datetime.timedelta(days=i)).strftime(
|
||||||
|
'%Y-%m-%d')
|
||||||
|
weekly_days.append(current_day)
|
||||||
|
return weekly_days
|
||||||
|
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
weekly_day = self.get_weekly_days()
|
||||||
|
tap_type = "new"
|
||||||
|
|
||||||
|
sql = f"""select
|
||||||
|
gameid,
|
||||||
|
title,
|
||||||
|
sum(diff_order),
|
||||||
|
score
|
||||||
|
from
|
||||||
|
taptap_collect
|
||||||
|
where
|
||||||
|
catename='{tap_type}'
|
||||||
|
and date in {weekly_day}
|
||||||
|
group by
|
||||||
|
gameid
|
||||||
|
order by
|
||||||
|
sum(diff_order) desc limit {self.limit};"""
|
||||||
|
|
||||||
|
data = self.db_conn.query(sql)
|
||||||
|
if data:
|
||||||
|
return data
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
data = self.build()
|
||||||
|
print(data)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
day = (datetime.date.today() - datetime.timedelta(days=1)).strftime('%Y-%m-%d')
|
||||||
|
twr = TapWeeklyReport(day)
|
||||||
|
twr.run()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
x
Reference in New Issue
Block a user