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
- Connect to WooCommerce using Python - This I successfully connect WC from Python
- Retrieve data from WooCommerce by date (last 7 days data) - I still not able to filter by date, my code at below.
- Only selected fields are going to insert into MSSQL - Not sure how to select date from fields needed, still working on it.
- Modify SP from MSSQL, this part is done. But the table structure is different. So need to modify. This totally no problem for me.
- Python call the SP from MSSQL - Haven't start research
- 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
- 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.