want to add url links to .csv datafeed using python

1.5k Views Asked by At

ive looked through the current related questions but have not managed to find anything similar to my needs.

Im in the process of creating a affiliate store using zencart - now one of the issues is that zencart is not designed for redirects and affiliate stores but it can be done. I will be changing the store so it acts like a showcase store showing prices.

There is a mod called easy populate which allows me to upload datafeeds. This is all well and good however my affiliate link will not be in each product. I can do it manually after uploading the data feed and going to each product and then adding it as an image with a redirect link - However when there are over 500 items its going to be a long repetitive and time consuming job.

I have been told that I can add the links to the data feed before uploading it to zencart and this should be done using python. Ive been reading about python for several days now and feel im looking for the wrong things. I was wondering if someone could please advise the simplest way for me to get this done.

I hope the question makes sense

thanks

abs

2

There are 2 best solutions below

1
On

You could craft a python script using csv module like this:

>>> import csv
>>> cartWriter = csv.writer(open('yourcart.csv', 'wb'))
>>> cartWriter.writerow(['Product', 'yourinfo', 'yourlink'])

You need to know how link should be formatted hoping that it could be composed using the other parameters present on csv file.

2
On

First, use the CSV module as systempuntoout told you, secondly, you will want to change your header to:

mimetype='text/csv'
Content-Disposition = 'attachment; filename=name_of_your_file.csv'

The way to do it depends very much of your website implementation. In pure Python you would probably do that with an HttpResponse object. In django, as well, but there are some shortcuts.

You can find a video demonstrating how to create CSV files with Python on showmedo. It's not free however.

Now, to provide a link to download the CSV, this depends of your Website. What is the technology behinds it : pure Python, Django, Pylons, Tubogear ?

If you can't answer the question, you should ask your boss a training about your infrastructure before trying to make change to it.