Need help converting text to csv format

Chuck Connors donnyf at gmail.com
Fri Nov 21 10:18:55 EST 2008


Hey guys.  I'm working on a little program to help my wife catalog her/
our coupons.  I found a good resource but need help formatting the
text data so that I can import it into a mysql database. Here's the
data format:

409220000003 Life Fitness Products $1 (12-13-08) (CVS)
546500181141 Oust Air Sanitizer, any B1G1F up to $3.49 (1-17-09) .35
each
518000159258 Pillsbury Crescent Dinner Rolls, any .25 (2-14-09)
518000550406 Pillsbury Frozen Grands Biscuits, Cinnamon Rolls, Mini
Cinnamon Rolls, etc. .40 (2-14-09)

The first value (large number) is the UPC, the next element is the
coupon description, followed by a date in parenthesis.  Those are the
only three elements I am concerned with.  Can someone help me in
reformatting this:

409220000003 Life Fitness Products $1 (12-13-08) (CVS)
546500181141 Oust Air Sanitizer, any B1G1F up to $3.49 (1-17-09) .35
each
518000159258 Pillsbury Crescent Dinner Rolls, any .25 (2-14-09)
518000550406 Pillsbury Frozen Grands Biscuits, Cinnamon Rolls, Mini
Cinnamon Rolls, etc. .40 (2-14-09)

into something like this:

"409220000003","Life Fitness Products $1","12-13-08"
"546500181141","Oust Air Sanitizer, any B1G1F up to $3.49","1-17-09"
"518000159258","Pillsbury Crescent Dinner Rolls, any .25","2-14-09"
"518000550406","Pillsbury Frozen Grands Biscuits, Cinnamon Rolls, Mini
Cinnamon Rolls, etc. .40","2-14-09"

Any help, pseudo code, or whatever push in the right direction would
be most appreciated.  I am a novice Python programmer but I do have a
good bit of PHP programming experience.

Thanks for your time....



More information about the Python-list mailing list