Commit d51476e6 by 杨林龙

添加激活设备脚本

1 parent abf5bade
import os, inspect
current_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
os.chdir(current_dir)
import sys
sys.path.append("../")
import logging
import time
from datetime import datetime
from decimal import Decimal
import MySQLdb
from dateutil.relativedelta import *
from my_utils.MysqlUtility import MySQL
import random
import calendar
logger = logging.getLogger("deal_active_data")
logger.setLevel(logging.DEBUG)
fileHandler = logging.FileHandler("../deal_active/import.log")
fileHandler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
cnslhandler = logging.StreamHandler()
cnslhandler.setLevel(logging.DEBUG)
cnslhandler.setFormatter(formatter)
logger.addHandler(cnslhandler)
saas_shen_db_cfg = {
"host": "192.168.3.222",
"port": 3306,
"user": "biz_audit",
"passwd": "hqVIs6jF",
"db": "saas_shen_ft",
"charset": "utf8",
}
def deal_active_data():
bizConn = MySQL(saas_shen_db_cfg)
sql = """
SELECT `id`, settle_time FROM temp_dj_device_details_modify_serins where `device_type` IN (6,12501) and channel = '渠道' and active_time is null;
"""
if not bizConn.query(sql):
logger.error("deal_active_data fail, sql=%s", sql)
return
result = bizConn.fetchAllRows()
for row in result:
logger.info(row)
# 根据结算时间计算激活时间
active_time = calculate_acitve_time(row[1])
logger.info(active_time)
# sql01 = f"""
# UPDATE temp_dj_device_details_modify_serins set active_time = {active_time} WHERE is ={row[0]} ;
# """
# logger.info(sql01)
# bizConn.update(sql01)
def calculate_acitve_time(settle_time):
# activeDate = settle_time + relativedelta(months=random.randint(0, 2))
activeDate = settle_time + relativedelta(months=1)
monthRange = calendar.monthrange(activeDate.year, activeDate.month)
dayx = random.randint(activeDate.day, monthRange[1])
activeDate = activeDate.replace(day=dayx)
hour = random.randint(0, 199) % 13 + 8 # 8点开始
munite = random.randint(0, 199) % 60
sencond = random.randint(0, 199) % 60
activeTime = "%04d-%02d-%02d %02d:%02d:%02d" % (
activeDate.year,
activeDate.month,
activeDate.day,
hour,
munite,
sencond,
)
if activeTime >= "2023-02-01 00:00:00":
calculate_acitve_time(settle_time)
return activeTime
if __name__ == "__main__":
deal_active_data()
# activeTime = calculate_acitve_time(datetime.strptime("2020-01-01", "%Y-%m-%d"))
# logger.info(activeTime)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!