class TongjicnzzTopProductsService:
    def __init__(self,files):
        self.data=TongjicnzzTopProductsCounter(files).get_data()

    def store(self):
        for value in self.data.values():
            value['name']=get_product_name(value['dp_id'])

        top20000products=sorted([(url,self.data[url]['count'],self.data[url]['dp_id'],self.data[url]['name']) for url in self.data.keys()],reverse=True,key=lambda x:x[1])[:20000]
        csvlines=[(i+1,)+top20000products[i] for i in range(20000)]
        with open('csv/top20000product.csv','wb') as f:
            w=unicodecsv.writer(f)
            w.writerow(('url','count','dp_id','name'))
            w.writerows(csvlines)
 def __init__(self,files):
     self.data=TongjicnzzTopProductsCounter(files).get_data()