This commit is contained in:
pengtao 2020-02-12 14:24:50 +08:00
parent a2466e610c
commit 6faa712586
4 changed files with 217 additions and 74 deletions

23
.editorconfig Normal file
View File

@ -0,0 +1,23 @@
[*]
charset=utf-8
end_of_line=crlf
insert_final_newline=false
indent_style=space
indent_size=4
[*.json]
indent_style=space
indent_size=2
[{*.pyw,*.py}]
indent_style=tab
tab_width=4
[*.pyi]
indent_style=tab
tab_width=4
[{*.yml,*.yaml}]
indent_style=space
indent_size=2

View File

@ -119,3 +119,20 @@ def class2dict(a):
print("{} 转换到dict失败 ,{}".format(a, e)) print("{} 转换到dict失败 ,{}".format(a, e))
return None return None
return dd # a=open(filename,'r').read() # time.strftime("%Y%m%d %H:%M:%S") # print( '20180807 15:23:29') # # time.strptime("20180702","%Y%m%d") # time.struct_time(tm_year=2018, tm_mon=7, tm_mday=2, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=183, tm_isdst=-1) return dd # a=open(filename,'r').read() # time.strftime("%Y%m%d %H:%M:%S") # print( '20180807 15:23:29') # # time.strptime("20180702","%Y%m%d") # time.struct_time(tm_year=2018, tm_mon=7, tm_mday=2, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=0, tm_yday=183, tm_isdst=-1)
def is_number(s):
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
return False

View File

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
mysql_conn = {"host": "192.168.100.30", "user": "miles", "pswd": "aspect", "db": "wjtx_log01"}
db_tables = (
"act_recharge", "arena_$date", "cailiao_$date", "chat_$date", "copy_end_$date", "exp_flow_$date", "first_charge",
"gift_bag", "item_change_$date", "mail_$date", "match_$date", "money_change_$date", "multi_player_boss",
"offline_award_$date", "pet_hh", "player_info_$date", "player_login_$date", "player_logout_$date",
"power_detail_$date",
"qy_answer_$date", "qy_question_$date", "role_online_count_$date", "sev_jinjie", "skill_upgrade", "sqhw_$date",
"strength_equip_$date", "task_flow_$date", "team_gard", "tower", "treasure_$date", "tribe_battle_$date",
"tribe_copy",
"tricks_$date", "vip_change_$date$date")
tga_url = "http://10.10.3.17:8992/querySql"
appid = "f325f667ceba4ce58a2a6553c977977d"
key = "SLZlX1IfdTkT7zYsnjJHaDuz9J4UraP65os8gr2fPoOzruPjHIILBxDMNd6W2743"
tgaid = 1009
db_row = {"act_recharge": ('name', 'acount_id', 'nickname'), "arena": ('name', 'acount_id', 'nickname')}

86
wjtx_log2tga.py Normal file
View File

@ -0,0 +1,86 @@
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name wjtx_log2tga
Description :
Author : pengtao
date 2020/2/12
-------------------------------------------------
Change Activity:
2020/2/12:
-------------------------------------------------
"""
__author__ = 'pengtao'
from common.plog import define_logger
from common.mmysql import MysqlBase
from common.mtga import FromTga
from common.common import is_number
import logging
from conf.wjtx_log import *
import datetime
define_logger("/data/logs/ops/wjtx_log2tga.log")
log = logging.getLogger(__name__)
class Db2TGA:
def __init__(self, day):
self.tga = FromTga(tga_url, key)
self.tga.init_tga_write(tgaid)
self.mysql = MysqlBase(**mysql_conn)
self.day = day
def write2tga(self, data, event_name):
self.tga.put_event_data(data, event_name=event_name)
def check_data(self, data):
return data
def collect_table(self, table_name, rows):
data = []
row_name = " ".jion(rows)
sql = f"select {row_name} from {table_name} where time between '{self.day} 00:00:00' and '{self.day} 23:59:59'"
out = self.mysql.query(sql)
if out:
for line in out:
try:
temp = {}
for i in range(0, len(rows)):
temp[rows[i]] = line[i]
data.append(temp)
except Exception:
log.error(f"split {line} failed!", exc_info=True)
else:
log.error(f"get data from {table_name} failed!")
return data
def run(self):
if not datetime.datetime.strptime(self.day, "%Y%m%d"):
log.error(f"{self.day} unformat!", exc_info=True)
return False
for table in db_tables:
if table.split('_')[-1] == "$date":
table_name = f"{table.split('_')[0]}_{self.day}"
rows = db_row.get(table.split('_')[0], None)
event_name = table.split('_')[0]
else:
table_name = table
rows = db_row.get(table)
event_name = table
data = self.collect_table(table_name, rows)
new = self.check_data(data)
self.write2tga(new, event_name)
def main():
import sys
day = sys.argv[1]
if not day:
raise Exception(f"pls check inputs days={day}")
db2tga = Db2TGA(day)
db2tga.run()
if __name__ == "__main__":
main()