Archive for January, 2008

Ebay File Exchange .csv Gotcha Fixed with gsub

Hey All

Been awhile, I know. While working on one of my projects, it came up that we would need to import thousands of ebay items into the shop, and be able to export them using the ebay file exchange, which dumps out a .csv file. It seems .csv parsers are the most common task I perform, I have written like a million for rails and php over the years, so I slapped something together quickly to do it and oops, I didn’t notice that ebay lists the item’s price with a comma. Ack, Comma Separated File, and there is a comma in one of the values, it’s easy to forget, but can really mess you up. Well, since I was using rails which means ruby, this is not such a problem, I can fix that easy enough with some regex.

To make a long story short, and since the price field was and will only forever be the offending field, I got away clean with a simple quick fix:

fields = line.gsub((\d+),(\d)/,"\\1\\2").split(',')

Got rid of that offending , and the £ sign to boot since we save currency amounts as floats, the £ sign is independent of that, and we use number_to_currency for that. Simple I know, but man, what an effing pain sometimes.

Well, gotta get back to relearning Rails, with the release of 2.0, there’s so much new stuff that it’s driving me nuts. Personally, I don’t see 2.0 as an improvement, except for the caching stuff, and the sexy migrations, those are cool…but that’s it.

Comments