代码拉取完成,页面将自动刷新
# -*- coding:utf8 -*-
import linksql
import time
import alimama
import logging
logger = logging.getLogger()
def truetime(order_scene=1):#实时20分钟订单
start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time() - 1200))
tk_orders = getTwentyOrders(start_time, order_scene)
if tk_orders:linksql.OrderDetailsAdd(tk_orders)
def twenty(start_time,order_scene):
tk_orders = getTwentyOrders(startTime=start_time,order_scene = order_scene)
if tk_orders:linksql.OrderDetailsAdd(tk_orders)
def getTwentyOrders(start_time,order_scene=2):#阿里巴巴淘宝联盟拉取订单的新代码alibaba.newOrders
struct_time = time.strptime(start_time,"%Y-%m-%d %H:%M:%S")
mktime = time.mktime(struct_time) + 1200 #获得20分钟后的时间
end_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(mktime))#转化为时间字符串
webdata = alimama.newOrders(start_time,end_time,order_scene=order_scene)
return webdata
def getThreeHoursOrders(start_time,order_scene=1):#获得指定日期的订单
struct_time = time.strptime(start_time,"%Y-%m-%d %H:%M:%S")
mktime = time.mktime(struct_time) + 10800 #获得3小时后的时间
end_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(mktime))#转化为时间字符串
tk_orders = alimama.newOrders(start_time,end_time,order_scene=order_scene)
return tk_orders
def updateTodayOrders(date,order_scene=1):#date格式%Y-%m-%d 将返回进度
start_time_list = ["00:00:00","03:00:00","06:00:00","09:00:00","12:00:00","15:00:00","18:00:00","21:00:00"]
logging.info("下面进行%s日期的订单收录"%(date))
for timetext in start_time_list:
start_time = date + " " + timetext
tk_orders = getThreeHoursOrders(start_time) #获得列表
tk_orders_nu = len(tk_orders)
logging.info(timetext + "共有%s个订单分别如下:"%(tk_orders_nu))
time.sleep(2)
for tk_order in tk_orders:
logging.info(tk_order['item_title'])
linksql.OrderDetailsAdd(tk_orders)
return None
def trueTimeTxt():#返回昨天的日期
timetxt = time.strftime("%Y-%m-%d",time.localtime(time.time() - 86400))#获得昨天的日期
return timetxt
def trueTimeDate():#返回今天的日期零点时间
timetxt = time.strftime("%Y-%m-%d", time.localtime(time.time())) + ' 00:00:00'
return timetxt
def reinclude():
timetxt = trueTimeTxt()#昨天的日期%Y-%m-%d
lstimetxt = lastIncludeTime()#上一次的执行时间%Y-%m-%d %H:%M:%S
if(timetxt in lstimetxt):#表示正在运行
struct_time = time.strptime(lstimetxt,'%Y-%m-%d %H:%M:%S') #获得时间元组
secs = time.mktime(struct_time) + 240#获得上次时间元组的时间戳,并计算得出目前的时间戳(加120s)
thistimetxt = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(secs))#
getTwentyOrders(thistimetxt,1)
else:
thistimetxt = timetxt + ' 00:00:00'
getTwentyOrders(thistimetxt,1)
writeIncludeTime(thistimetxt)
return thistimetxt
def ReIncludeFromArray(array_time, stay):#从一组时间中重新收录
for timestp in array_time:
if timestp and len(timestp) == 19:
getTwentyOrders(timestp,1)
print(timestp + " 已收录")
time.sleep(stay)#推迟执行
return None
def lastIncludeTime():#
f = open('includetime.txt','r')
timetxt = f.read()
f.close()
return timetxt
def writeIncludeTime(timetxt):
f = open('includetime.txt','w')
f.write(timetxt)
f.close()
return timetxt
def updateOrders():
orders = linksql.monthorder()
if orders:
logger.info('本月一共有%s个订单'%(str(len(orders))))
for order in orders:
tk_create_time = order[11];#订单创建时间
tk_orders = getTwentyOrders(tk_create_time)
if tk_orders:
for order in tk_orders:
linksql.updateorder(order)
else:
logger.warning('月订单更新出错')
time.sleep(4)#延迟40秒
else:
logger.warning('本月没有订单')
return None
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。