add tags field
This commit is contained in:
parent
c579a233ba
commit
614c8650a1
49
taptap/tap_split_tags.py
Normal file
49
taptap/tap_split_tags.py
Normal file
@ -0,0 +1,49 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from ops.mmysql import MysqlBase
|
||||
from ops.plog import define_logger
|
||||
import logging
|
||||
import datetime
|
||||
|
||||
define_logger("/data/logs/ops/split_tags.log")
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
db_conf = {'user': 'mytga', 'pswd': 'gzVwh4HGR68G', 'host': '10.10.3.5', 'db': 'external_data'}
|
||||
|
||||
|
||||
class SplitTapTags:
|
||||
def __init__(self, day):
|
||||
self.db_conn = MysqlBase(**db_conf)
|
||||
self.type = ['new', 'reserve']
|
||||
self.day = day
|
||||
|
||||
|
||||
def run(self):
|
||||
all = dict()
|
||||
for types in self.type:
|
||||
sql = f"""select
|
||||
tags
|
||||
from
|
||||
taptap_data
|
||||
where
|
||||
catename='{types}'
|
||||
and date='{self.day}' """
|
||||
tags = self.db_conn.query(sql)
|
||||
if tags:
|
||||
for line in tags:
|
||||
if line:
|
||||
try:
|
||||
for item in line.split(","):
|
||||
all[types][item] = all[types].get('item', 0) + 1
|
||||
except Exception:
|
||||
log.error(f"split {line} failed!", exc_info=True)
|
||||
print(all)
|
||||
|
||||
|
||||
def main():
|
||||
day = (datetime.date.today() - datetime.timedelta(days=1)).strftime('%Y-%m-%d')
|
||||
stt = SplitTapTags(day)
|
||||
stt.run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
x
Reference in New Issue
Block a user