stocks/tasks.py
def download_and_store_news(share_name, share_id):
    '''
    Downloads last news and stores them in database
    '''
    from_date, to_date = get_start_end_week_dates()
    logger = download_and_store_news.get_logger()
    logger.info('Downloading news for ' + share_name)
    articles_en = download_news_json(
        get_news_api_payload(
            share_name,
            NEWS_API_KEY,
            from_date,
            to_date
        )
    )
    articles_ru = download_news_json(
        get_news_api_payload(
            share_name,
            NEWS_API_KEY,
            from_date,
            to_date,
            'ru'
        )
    )
    articles = articles_ru + articles_en
    # Take every 2nd article
    for article in articles[:50:2]:
        if not Article.are_valid_arguments(article):
            continue
        db_article = Article(
            author=article['author'],
            title=article['title'],
            description=article['description'],
            url=article['url'],
            url_to_image=article['urlToImage'],
            content=article['content'],
            publish_dateTime=article['publishedAt'],
            share=Share.objects.get(id=share_id)
        )
        db_article.save()

    Downloads last news and stores them in database
    
Downloads last news and stores them in database
Downloads last news and stores them in database
def download_and_store_news(share_name, share_id):
    from_date, to_date = get_start_end_week_dates()
    logger = download_and_store_news.get_logger()
    logger.info('Downloading news for ' + share_name)
    articles_en = download_news_json(
        get_news_api_payload(
            share_name,
            NEWS_API_KEY,
            from_date,
            to_date
        )
    )
    articles_ru = download_news_json(
        get_news_api_payload(
            share_name,
            NEWS_API_KEY,
            from_date,
            to_date,
            'ru'
        )
    )
    articles = articles_ru + articles_en
    for article in articles[:50:2]:
        if not Article.are_valid_arguments(article):
            continue
        db_article = Article(
            author=article['author'],
            title=article['title'],
            description=article['description'],
            url=article['url'],
            url_to_image=article['urlToImage'],
            content=article['content'],
            publish_dateTime=article['publishedAt'],
            share=Share.objects.get(id=share_id)
        )
        db_article.save()
def download_and_store_news ( share_name , share_id ) : from_date , to_date = get_start_end_week_dates ( ) logger = download_and_store_news . get_logger ( ) logger . info ( 'Downloading news for ' + share_name ) articles_en = download_news_json ( get_news_api_payload ( share_name , NEWS_API_KEY , from_date , to_date ) ) articles_ru = download_news_json ( get_news_api_payload ( share_name , NEWS_API_KEY , from_date , to_date , 'ru' ) ) articles = articles_ru + articles_en for article in articles [ : 50 : 2 ] : if not Article . are_valid_arguments ( article ) : continue db_article = Article ( author = article [ 'author' ] , title = article [ 'title' ] , description = article [ 'description' ] , url = article [ 'url' ] , url_to_image = article [ 'urlToImage' ] , content = article [ 'content' ] , publish_dateTime = article [ 'publishedAt' ] , share = Share . objects . get ( id = share_id ) ) db_article . save ( )
Downloads last news and stores them in database
Downloads last news and stores them in database
'''
    Downloads last news and stores them in database
    ''' # Take every 2nd article
share_name
share_id