#-*-coding:utf-8-*- from Category import Category from Cookbook import Cookbook from Category import Category import sys cookbooks = Cookbook.objects() cats = Category.objects() total = 0 for c in cats: print c.name, c.count, c.url total += c.count #print total sys.exit() for c in cats: c.count = 0 c.save() for cb in cookbooks: #去重 if len(cb.category) != len(set(cb.category)): cb.category = list(set(cb.category)) cb.save() print 'save' #计算各分类cookbook数 for c in cb.category: if c.count is None: c.count = 0
#-*-coding:utf-8-*- from Category import Category from Cookbook import Cookbook from Category import Category import sys cookbooks = Cookbook.objects() cats = Category.objects() total = 0 for c in cats: print c.name, c.count,c.url total += c.count #print total sys.exit() for c in cats: c.count = 0 c.save() for cb in cookbooks : #去重 if len(cb.category) != len(set(cb.category)): cb.category = list(set(cb.category)) cb.save() print 'save' #计算各分类cookbook数 for c in cb.category: if c.count is None: c.count = 0
#-*-coding:utf-8-*- from Category import Category from Cookbook import Cookbook from Category import Category import sys cookbooks = Cookbook.objects(is_crawled=1)#.only('pk','is_crawled','item_id') #print cookbooks for cb in cookbooks.as_pymongo() : #print cb c = Cookbook.objects(item_id=cb['item_id']).only('pk','is_crawled','item_id')[0] print c print c.item_id print c.pk print c.id print c.is_crawled c.is_crawled = 0 try: c.save() except: pass
#-*-coding:utf-8-*- from Category import Category from Cookbook import Cookbook from Category import Category import sys cookbooks = Cookbook.objects(is_crawled=1) #.only('pk','is_crawled','item_id') #print cookbooks for cb in cookbooks.as_pymongo(): #print cb c = Cookbook.objects(item_id=cb['item_id']).only('pk', 'is_crawled', 'item_id')[0] print c print c.item_id print c.pk print c.id print c.is_crawled c.is_crawled = 0 try: c.save() except: pass