Commit 8366c971 authored by Vasyl Bodnaruk's avatar Vasyl Bodnaruk

Refactor function for insert news

parent bfc6c7da
......@@ -46,16 +46,16 @@ class ExaPipeline(object):
print("DUPLICATE")
else:
print("UNIQUE")
self.insert_news(item)
article = self.get_article(item['url'])
text = article.text
tags = self.get_tags(article)
self.insert_news(item, tags, text)
return item
def insert_news(self, item):
article = self.get_article(item['url'])
tags = self.get_tags(article)
def insert_news(self, item, tags, text):
data = (item['title'], item['description'], item['url'], item['media_id'], item['type_id'],
item['region_id'], item['post_id'], item['date'], datetime.now(), item['company_id'], 0,
item['tags'], tags, article)
item['tags'], tags, text)
query = """INSERT INTO wp_esi_news_accept (title, description, URL, media_id, type_id, region_id, post_id,
publish_date, record_date, company_id, is_accepted, temp_tags, tags_id, text)
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);\n"""
......@@ -87,7 +87,7 @@ class ExaPipeline(object):
article = Article(url)
article.download()
article.parse()
return article.text
return article
def get_tags(self, text):
'''
......
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