Need to use python retrieve woocommerce order data based on modified date?

Viewed 90

I need to generate some excel reports and the data are from WooCommerce. I already have a C# program and MSSQL to generate 6 reports.

Everyday I need to MANUALLY export Order from WC in csv and run the C# program to import the csv data into MSSQL and then generate the report and send to branches.

I don't know python before this but I'm still wish to write a python program to automate the process.

I have follow the instruction and able to use python call wc and also download all orders.

But I really need some help here

How to retrieve orders based on modified date. How to extract the order data + meta data for all retrieved orders and load into MSSQL and use the SP to generate the 6 reports.

What I planned to do is

  1. Connect to WooCommerce using Python - This I successfully connect WC from Python
  2. Retrieve data from WooCommerce by date (last 7 days data) - I still not able to filter by date, my code at below.
  3. Only selected fields are going to insert into MSSQL - Not sure how to select date from fields needed, still working on it.
  4. Modify SP from MSSQL, this part is done. But the table structure is different. So need to modify. This totally no problem for me.
  5. Python call the SP from MSSQL - Haven't start research
  6. Python export the return data to Excel template based on branch. So need to asynchronous way to export to save time. - Haven't start research
  7. Python to send the exported file to the particular branch. - Haven't start research

Here is my code to do download Orders data filtered by modified date (I assume new create and updated date) What I wanted to achieve is only extract latest 7 days data.

    page = 1 #The first page number to loop is page 1 
    orders = []
    while True:
        ords = wcapi.get('orders', params={'per_page': 100, 'date_modified': '2021-07-23', 'page': page}).json()
        page += 1
        if not ords:
            break
        orders.append(ords)
    jsonString = json.dumps(orders, ensure_ascii=False, indent=2)
    jsonFile = open("orders.json", "w")
    jsonFile.write(jsonString)
    jsonFile.close()

Really need some guide, please help.

0 Answers
Related