Python Forum
.csv export, map and create new .csv
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.csv export, map and create new .csv
#1
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
Email
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
Reply
#2
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 imported
Why 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
Reply
#3
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...
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
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!)
Reply
#5
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)?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#6
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 ;)
Reply
#7
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create synonyms of a word and export them to csv in different columns vijaymadhu 1 3,040 Jun-23-2017, 06:31 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020