新增新用户统计脚本
This commit is contained in:
parent
acb428eecc
commit
ff1a0f37e2
66
cron/get_newuser_days.py
Normal file
66
cron/get_newuser_days.py
Normal file
@ -0,0 +1,66 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from ops.plog import define_logger
|
||||
import logging
|
||||
import sys
|
||||
import datetime
|
||||
from ops.mmysql import MysqlBase
|
||||
import pdb
|
||||
|
||||
define_logger("/data/logs/get_newusers_days.log")
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
DB = {'user': 'mytga', 'pswd': 'gzVwh4HGR68G', 'host': '10.10.3.5', 'db': 'games_report'}
|
||||
|
||||
mydb = MysqlBase(**DB)
|
||||
table_name = "new_users_days"
|
||||
|
||||
|
||||
def get_data(times, gameid, channelid):
|
||||
sql = f"""SELECT
|
||||
count(accountid) AS users,
|
||||
ad_channel
|
||||
FROM
|
||||
newuser
|
||||
WHERE
|
||||
gameid={gameid}
|
||||
AND channelid={channelid}
|
||||
AND date(register_time) ='{times}'
|
||||
|
||||
GROUP BY
|
||||
ad_channel;"""
|
||||
out = mydb.query(sql)
|
||||
data = []
|
||||
if out:
|
||||
try:
|
||||
for line in out:
|
||||
temp = {}
|
||||
temp['usernum'], temp['ad_channel'] = line
|
||||
data.append(temp)
|
||||
except Exception:
|
||||
log.error(f"split {line} error!")
|
||||
return data
|
||||
|
||||
|
||||
def write2db(data, times, gameid, channelid):
|
||||
for line in data:
|
||||
line['date'] = times
|
||||
line['key'] = f"{gameid}#{channelid}#{line['ad_channel']}"
|
||||
try:
|
||||
mydb.insert(table_name, line)
|
||||
except Exception:
|
||||
log.error(f" insert {line} to db failed", exc_info=True)
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) == 2:
|
||||
times = sys.argv[1]
|
||||
else:
|
||||
times = (datetime.date.today() - datetime.timedelta(days=1)).strftime('%Y-%m-%d')
|
||||
gameid = 2001
|
||||
channelid = 6001
|
||||
data = get_data(times, gameid, channelid)
|
||||
write2db(data, times, gameid, channelid)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
x
Reference in New Issue
Block a user