def retrieve_urls_using_json()

in source/lambda/capture_news_feed/util/config_helper.py [0:0]


def retrieve_urls_using_json(param_str):
    """
    This function calls the newscatcher api and returns the urls to be invoked. The
    input parameter is a JSON string which is converted to a dictionary and then processed
    """
    logger.info(f"Parameters to retrieve list of urls to query: {param_str}")

    param_dict = json.loads(param_str)
    country = param_dict.get("country", None)
    language = param_dict.get("language", None)
    topics = param_dict.get("topic", None)

    url_list = list()

    topic_list = None
    if topics:
        topic_list = topics.split(",")

    if topic_list and len(topic_list) > 0 and "ALL" not in topic_list:
        for topic in topic_list:
            temp_url_list = retrieve_urls(
                country=country,
                language=language,
                topic=topic,
            )

            if temp_url_list:
                url_list = url_list + temp_url_list
    else:
        url_list = retrieve_urls(country=country, language=language)

    return url_list