1 Star 3 Fork 1

不得鸟的皮卡丘/淘宝客微信公众号服务端

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ztk_update.py 4.09 KB
一键复制 编辑 原始数据 按行查看 历史
不得鸟的皮卡丘 提交于 2020-03-14 01:29 . create object
# -*- 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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/pikaqiu2018/mp_taobaoke_py3.git
git@gitee.com:pikaqiu2018/mp_taobaoke_py3.git
pikaqiu2018
mp_taobaoke_py3
淘宝客微信公众号服务端
master

搜索帮助