.csv export, map and create new .csv - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: .csv export, map and create new .csv (/thread-10803.html) |
.csv export, map and create new .csv - jtouchais - Jun-07-2018 Hi Experts! After trying to "play" with VB and Excel and searching high and low for a suitable solution I discovered Python was probably the answer to my problem! BIG caveat: I'm a total noob when it comes to coding! Anyway, i was hoping someone out there had a similar issue and solved it already :) Here goes: I have an order export from my store producing a CSV file with set columns that I cannot change prior to the export (ORDER_EXPORT) My warehouse requires a csv file in order to receive the orders with a different set of columns (headers and order of the data) (SHIPPER_CSV) What I would need is a script that: 1. map the headers correctly (e.g. Shipping Name > recipient_name) 2. imports the data from ORDER_EXPORT to the correct SHIPPER_CSV columns 3. if ORDER_EXPORT header "Shipping Company" is not blank then SHIPPER_CSV "recipient_type" = B else SHIPPER_CSV "recipient_type" = C 3. saves SHIPPER_CSV as a .csv that can be imported Is this something easily doable? Help please! PS - below are the headers ORDER-EXPORT Name Financial Status Paid at Fulfillment Status Fulfilled at Accepts Marketing Currency Subtotal Shipping Taxes Total Discount Code Discount Amount Shipping Method Created at Lineitem quantity Lineitem name Lineitem price Lineitem compare at price Lineitem sku Lineitem requires shipping Lineitem taxable Lineitem fulfillment status Billing Name Billing Street Billing Address1 Billing Address2 Billing Company Billing City Billing Zip Billing Province Billing Country Billing Phone Shipping Name Shipping Street Shipping Address1 Shipping Address2 Shipping Company Shipping City Shipping Zip Shipping Province Shipping Country Shipping Phone Notes Note Attributes Cancelled at Payment Method Payment Reference Refunded Amount Vendor Id Tags Risk Level Source Lineitem discount Tax 1 Name Tax 1 Value Tax 2 Name Tax 2 Value Tax 3 Name Tax 3 Value Tax 4 Name Tax 4 Value Tax 5 Name Tax 5 Value Phone SHIPPER_CSV recipient_reference recipient_email recipient_name recipient_street1 recipient_house_no recipient_street2 recipient_name2 recipient_city recipient_zip recipient_state recipient_country recipient_phone recipient_comment recipient_language_code recipient_fax recipient_type RE: .csv export, map and create new .csv - Larz60+ - Jun-07-2018 We will not write code for you, but will be glad to help with problems encountered as you develop it yourself. Quote:saves SHIPPER_CSV as a .csv that can be importedWhy csv? why not SQL? Looks simple enough but these applications have a tendency to grow You may want to take a look at: https://pypi.org/search/?q=order+processing RE: .csv export, map and create new .csv - buran - Jun-07-2018 yes, that's relatively easy to do. 1. Create the mapping 2. For reading/writing csv files use csv module (and in particular csv.DictReader and csv.DictWriter, because of the mapping) 3. Transfer/populate the result file using the input file and derivative values (i.e. recipient_type) So, now the devil is in the details and mostly will depend on the specifications for the result file. Do you have perfect mapping (i.e. extra/missing data)? Any difference in specifications (e.g. limited length for some fields, forbidden chars, etc.)? It depends what extra functionality you want - e.g. keep mapping as separate config file for easy manipulation, GUI/CLI interface, etc... RE: .csv export, map and create new .csv - jtouchais - Jun-07-2018 Quote:We will not write code for you, but will be glad to help with problems encountered as you develop it yourself.Well that's fair enough! :) .csv as the shipper tool requires a .csv file to import. I'll have a browse through the link you shared (thank you!) RE: .csv export, map and create new .csv - buran - Jun-07-2018 Which systems do you use? Do they have an API, which may be more convenient to implement (e.g. there might be dedicated python package/SDK)? RE: .csv export, map and create new .csv - jtouchais - Jun-07-2018 Thanks for the replies! I use Shopify and need to pass the orders to DPD Shipper. In Shopify the header and columns are separated by comma (,), in DPD the header and columns are separated by semicolons (;) or pipes (|). I'll have a play with csv.DictReader and csv.DictWriter and try to read the export file (that I can already do yay!), re-write the header according to the import format, add missing data in rows for header "recipient_type" and paste the relevant data. Once I've got a few lines of /working/ code I'll post back ;) RE: .csv export, map and create new .csv - Larz60+ - Jun-07-2018 Shopify hasn't been worked on since June 24, 2011. Aparently it has been worked on. just left PyPi Perhaps not such a good choice (unless you pick up development yourself) |