import json
import gzip
import csv

def parse(path):
  g = gzip.open(path, 'r')
  for l in g:
    yield eval(l)

fields = ["asin", "title", "salesrank", "brand", "categories"]

csvOut = gzip.open("meta_Beauty.csv.gz", 'w')
writer = csv.writer(csvOut)

for product in parse("meta_Beauty.json.gz"):
  line = []
  for f in fields:
    if product.has_key(f): line.append(product[f])
  else: line.append("")
  writer.writerow(line)
