Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
deal_mysql_data
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit d51476e6
authored
May 23, 2023
by
杨林龙
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
添加激活设备脚本
1 parent
abf5bade
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
0 deletions
deal_active/deal_active_record.py
deal_active/deal_active_record.py
0 → 100644
View file @
d51476e
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
=
"
%04
d-
%02
d-
%02
d
%02
d:
%02
d:
%02
d"
%
(
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)
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment