Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu.miao committed May 27, 2018
1 parent 5cc2d4a commit 60e260c
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions g.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import datetime
import json
import time
import sched
import pymysql.cursors


def get_current_order_list():
def get_buy_order_list():
connection = pymysql.connect(host='localhost',
user='root',
password='password',
Expand All @@ -13,7 +14,7 @@ def get_current_order_list():
try:
with connection.cursor() as cursor:
# Create a new record
sql = "select * from order_item where status=1"
sql = "select *, CONVERT_TZ(buy_time,'+00:00','+8:00') as r_buy_time from order_item where status=1"
cursor.execute(sql)
# 使用 fetchone() 方法获取一条数据
data = cursor.fetchall()
Expand All @@ -25,34 +26,38 @@ def get_current_order_list():


# 下单后更新状态
def update_order_status(order):
connection = pymysql.connect(host='localhost',
user='root',
password='password',
db='hb',
cursorclass=pymysql.cursors.DictCursor)
try:
with connection.cursor() as cursor:
sql = "update order_item set status=2 where order_item_id=%s"
order_id = order["order_item_id"]
cursor.execute(sql, (order_id))
def set_buy_order(order):

print("update order status: ", order_id)
connection.commit()
finally:
connection.close()
now = datetime.datetime.now()
buy_time = order["r_buy_time"]
if now > buy_time:
connection = pymysql.connect(host='localhost',
user='root',
password='password',
db='hb',
cursorclass=pymysql.cursors.DictCursor)
try:
with connection.cursor() as cursor:
sql = "update order_item set status=2 where order_item_id=%s"
order_id = order["order_item_id"]
cursor.execute(sql, (order_id))

print("update order status: ", order_id)
connection.commit()
finally:
connection.close()

# 计数器,一个循环任务,总共让自己执行3次
def run_task():

# 打印信息
print("run time is ", time.time())
order_list = get_current_order_list();
order_list = get_buy_order_list();

print("current order list: ", len(order_list))

for order in order_list:
update_order_status(order)
set_buy_order(order)


# 只要没有让自己调用到第3次,那么继续重头开始执行本任务
Expand Down

0 comments on commit 60e260c

Please sign in to comment.