涉及模块
1、python日期与时间戳的转换
2. 获取非当前日期时间戳
3. 更新sql数据
4. 接口调用
需求点
修改data_user_cpl_reward表中数据A为前一日数据
调用清除缓存接口
导入模块
import mysql.connector
import requests,json
import time
from datetime import datetime,timedelta
获取昨日当前时间戳
def yestoday():
current_time = datetime.today()
Adjust_time = current_time - timedelta(days=1)#时间前推一天
untime = time.mktime(Adjust_time.timetuple())#mktime() 函数执行与gmtime(), localtime()相反的操作,它接收struct_time对象作为参数,返回用秒数来表示时间的浮点数
return int(untime)
yt_time = yestoday()
查询当前时间
def nowTime():
now = time.time()
N_t = time.localtime(now)
N_tt = time.strftime("%Y-%m-%d %H:%M:%S",N_t)#时间戳转具体日期
return N_tt
current_time = nowTime()
print("当前时间为:",current_time)
连接数据库
config = {
'host':'47.XX.XX.33',
'user':'XX',
'password':'NewXXXXXXTIFIED1',
'port':'3306',
'database':'XXX',
'charset':'utf8'
}
检查数据库状态
try:
cnn = mysql.connector.connect(**config)
print("数据库连接成功")
except mysql.connector.Error as e:
print("数据库连接失败")
更新sql表中时间戳
def update_cpa():
cursor = cnn.cursor(buffered=True)
try:
update = "update data_us