import time
import pandas as pd
import pymysql
from datetime import datetime
import pandas as pd
from dateutil.relativedelta import relativedelta
now = datetime.now() #现在的时间
today = datetime.strftime(now,'%Y%m%d')
def custom():
now=datetime.now()
first_day = datetime.strftime(now, '%d') #当前时间 天
if first_day=='01' or first_day=='02':
starttime_time = now + relativedelta(months=-1)
starttime_time = datetime.strftime(starttime_time, '%Y/%m')
starttime = starttime_time + '/01'
else:
first_time = datetime.strftime(now, '%Y/%m')
starttime = first_time + '/01'
second_time =now + relativedelta(days=-1)
second_time =datetime.strftime(second_time,'%Y/%m/%d')
print(starttime)
print(second_time)
# 链接数据库下载每日销售订单数据
conn=pymysql.connect (host='xx.xx.xx.xx',port=3316,user= 'xxx', passwd= 'xxxxx', db= 'xxxx')
sql_time='SELECT * FROM re_customreport WHERE pay_time=(select MAX(pay_time) from re_customreport) '
toptime=pd.read_sql(sql_time,con=conn) #获取一下最高的时间 看看是否是自己需要的
print(toptime['pay_time'])
sql = "select * from re_customreport where pay_time >=\' " + starttime + "\'"
data = pd.read_sql(sql, con=conn)
data=data[['orderPlatformType','platform_adjust','siteId','sellerId_adjust','warehouseId_adjust','referenceNo','productBarcode','sellerResponsibleName','developResponsibleName','orderTotalAmount_adjust','asinOrItem',
'operatinggrossprofit','grossProfit','quantity_adjust','pay_time','destinationCountry','receivingCode','warehouselassify','developResponsibleName_newproduct',
'purchaseCost','salesID_thismonth','productTitle','salesJobnumber_thismonth','sellinggrossprofit']]
data.to_csv('订单.csv',encoding='utf_8_sig', index=None)
custom()
从数据库下载1号-昨天的订单数据
最新推荐文章于 2024-09-26 10:22:13 发布