从数据库下载1号-昨天的订单数据

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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值