core.py 918 Bytes
Newer Older
Sanjay Krishnan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
'''
The core module sets up the data structures and 
and references for this programming assignment.

2010
'''

import platform
import csv

if platform.system() == 'Windows':
  print("This assignment will not work on a windows computer")
  exit()


#defines an iterator over the google catalog
class Catalog():

    def __init__(self, filename):
      self.filename = filename

    def __iter__(self):
      f = open(self.filename, 'r', encoding = "ISO-8859-1")
      self.reader = csv.reader(f, delimiter=',', quotechar='"')
      next(self.reader)
      return self

    def __next__(self):
      row = next(self.reader)
      return {'id': row[0],
               'title': row[1],
               'description': row[2],
               'mfg': row[3],
               'price': row[4]
              }

def google_catalog():
    return Catalog('GoogleProducts.csv')

def amazon_catalog():
    return Catalog('Amazon.csv')