def worker(news_text): key_word_list = key_words.get_key_word(news_text.text, news_text.news.title) for word in key_word_list: key_word, is_created = KeyWord.objects.get_or_create(word=word) key_word.news.add(news_text.news) news_text.is_keywords_extracted = True news_text.save() return news_text.pk, len(key_word_list)
def key_words_create(): for newstext in NewsText.objects.filter(is_keywords_extracted=False).iterator(): if newstext.text: key_word_list = key_words.get_key_word(newstext.text, newstext.news.title) print(key_word_list) for word in key_word_list: try: key_word = KeyWord.objects.get(word=word) except: key_word = KeyWord(word=word) key_word.save() key_word.news.add(newstext.news)
def worker(work_obj): news_pk, news_title, news_text = work_obj key_word_list = key_words.get_key_word(news_text, news_title) print("news_id {}\t num of keywords {}".format(news_pk, len(key_word_list))) return news_pk, key_word_list