Skip to content

Instantly share code, notes, and snippets.

@deoxxa
Created June 6, 2016 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deoxxa/6f3525da551487be354cdd0ec912ce44 to your computer and use it in GitHub Desktop.
Save deoxxa/6f3525da551487be354cdd0ec912ce44 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import csv
import hashlib
import re
import sys
def slugify(s):
s = s.lower()
for c in [' ', '-', '.', '/']:
s = s.replace(c, '_')
s = re.sub('\W', '', s)
s = s.replace('_', ' ')
s = re.sub('\s+', ' ', s)
s = s.strip()
s = s.replace(' ', '-')
return s
writer = csv.writer(sys.stdout)
chain = sys.argv[2]
with open(sys.argv[1], 'rb') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
if row[0] == 'zipcode':
continue
product_id = hashlib.md5('Whole Foods Market##' + row[5]).hexdigest()
catalogue_id = slugify(chain) + '/1'
adjust_by = int(hashlib.md5(chain + '##' + product_id).hexdigest()[:2], 16) / 25
price = float(row[6][1:])
price = '$%.2f' % (price + price / 100 * adjust_by)
if hashlib.md5(chain + '##' + product_id).hexdigest() < 'b':
writer.writerow([chain, catalogue_id, slugify(row[3])+'/'+slugify(row[4]), product_id, price])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment