Commit 793b4a18 authored by Vasyl Bodnaruk's avatar Vasyl Bodnaruk

Add functional for block teach model if it's not needed

parent 5d3bfe77
......@@ -25,9 +25,9 @@ class ExaPipeline(object):
create classifier for making tags
make Redis buffer for collect all news from DB
'''
self.teach = False
self.db = Database(**db)
self.classifier = Classifier(host=db['host'], user=db['user'], password=db['pwd'], db=db['database'], port=3306)
self.classifier.teach_model()
self.classifier = None
self.buffer = redis.StrictRedis()
self.ml_data = MLDataMaker(self.db)
for i in self.db.select('select url from wp_esi_news_accept'):
......@@ -37,6 +37,8 @@ class ExaPipeline(object):
def open_spider(self, spider):
spider.pipeline = self
self.teach = spider.teach
self.classifier = self._create_classifier()
def process_item(self, item, spider):
item['title'] = ''.join(item['title']).replace('\n', ' ')
......@@ -125,3 +127,11 @@ class ExaPipeline(object):
for i in data:
self.db.insert('INSERT INTO wp_esi_ml_data (news_id, tag_id) VALUES(%s, %s);',
(i.news_id, i.tags_id))
def _create_classifier(self):
if self.teach:
classifier = Classifier(host=db['host'], user=db['user'], password=db['pwd'], db=db['database'], port=3306)
classifier.teach_model()
return classifier
else:
return None
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment