def add_news_articles_to_db_for_nonprofit(nonprofits_id): """Searches the web for news articles related to the nonprofit and stores them in the DB. Returns the IDs of the news articles found.""" logger.debug('Inside add_news_articles_to_db_for_nonprofit(nonprofit) for nonprofits_id {0}'.format(nonprofits_id)) nonprofit = DBSession.query(Nonprofit).get(nonprofits_id) query = DBSession.query(News_Article).filter(News_Article.nonprofits_id == nonprofits_id) already_retrieved_urls = [news_article.url for news_article in query.all()] news_articles = [] for article in news_searcher.find_news_articles(nonprofit.name, urls_to_ignore=already_retrieved_urls): news_articles.append(News_Article(nonprofit.nonprofits_id, article.url, article.headline, article.body)) DBSession.add_all(news_articles) DBSession.commit() return [news_article.news_articles_id for news_article in news_articles]
def add_news_articles_to_db_for_nonprofit(nonprofits_id): """Searches the web for news articles related to the nonprofit and stores them in the DB. Returns the IDs of the news articles found.""" logger.debug( 'Inside add_news_articles_to_db_for_nonprofit(nonprofit) for nonprofits_id {0}' .format(nonprofits_id)) nonprofit = DBSession.query(Nonprofit).get(nonprofits_id) query = DBSession.query(News_Article).filter( News_Article.nonprofits_id == nonprofits_id) already_retrieved_urls = [news_article.url for news_article in query.all()] news_articles = [] for article in news_searcher.find_news_articles( nonprofit.name, urls_to_ignore=already_retrieved_urls): news_articles.append( News_Article(nonprofit.nonprofits_id, article.url, article.headline, article.body)) DBSession.add_all(news_articles) DBSession.commit() return [news_article.news_articles_id for news_article in news_articles]