def test_part_list() -> None: # Have to initial new to avoid time out error trends = tdc.TrendsCollector() builder = tdc.DesignerTrendsCollector(["test", "wordcloud"]) trends.builder = builder trends.find_related_queries() assert builder.trends.list_product_parts == "Product parts: related_queries"
def test_wordcloud() -> None: # Have to initial new to avoid time out error trends = tdc.TrendsCollector() builder = tdc.DesignerTrendsCollector(["test", "wordcloud"]) trends.builder = builder trends.make_wordcloud() assert type(builder.trends.return_product) == type(dict())
def four_step_trendsearch( keyword_list: list, timeframe: str = "today 5-y", language: str = "en-US", category: int = 0, timezone: int = 360, country: str = "", property_filter="", resolution: str = "COUNTRY", **kwargs, ) -> dict: """four step search A four step search includes: 1. Overtime 2. By regions 3. By related topics 4. By related queries Args: keyword_list (list): Keyword-list with the items to search for. timeframe (str, optional): Time frame, respectively, period to search for. Defaults to "today 5-y". language (str, optional): Search language. Defaults to "en-US". category (int, optional): Define a specific [search category](https://github.com/pat310/google-trends-api/wiki/Google-Trends-Categories). Defaults to 0. timezone (int, optional): [Search timezone](https://developers.google.com/maps/documentation/timezone/overview). Defaults to 360. country (str, optional): The country, where to search for. Defaults to "". property_filter (str, optional): Property filer of the search; only in news, images, YouTube, shopping. Defaults to "". resolution (str, optional): The resolution / zoom-factor, where to search for. Defaults to "COUNTRY". Returns: dict: Dictionary with the keys: 'interest_over_time', 'interest_by_region', 'related_topics', 'related_queries' and its dataframes. """ trends = trends_collector.TrendsCollector() builder = trends_collector.DesignerTrendsCollector( keyword_list=keyword_list, timeframe=timeframe, language=language, category=category, timezone=timezone, country=country, property_filter=property_filter, **kwargs, ) trends.builder = builder trends.find_interest_over_time() trends.find_interest_by_region(resolution=resolution) trends.find_related_topics() trends.find_related_queries() return builder.trends.return_product
""" """ ### Loading the model `trends_collector` """ from ai2business.kpi_collector import trends_collector """ Setup the search with the keyword list and write it into the `builder` """ keyword_list: list = ["Corona", "S&P 500", "Hope"] trends = trends_collector.TrendsCollector() builder = trends_collector.DesignerTrendsCollector(keyword_list=keyword_list) trends.builder = builder """ ### Add the `trend-search` functions, in this particular case: 1. Searching over time 2. Searching in a special area 3. Searching for related queries 4. Searching for realted topics All the information will be generated and stored in the `builder`. """ trends.find_interest_over_time()
"""Test-Enviroment for trends_collector.py""" import pandas as pd from ai2business.kpi_collector import trends_collector as tdc trends = tdc.TrendsCollector() builder = tdc.DesignerTrendsCollector(["AI", "Business", "AI2Business"]) trends.builder = builder def test_interest_over_time() -> None: trends.find_interest_over_time() assert type(builder.trends.return_product["interest_over_time"]) == type( pd.DataFrame()) def test_interest_by_region() -> None: trends.find_interest_by_region() assert type(builder.trends.return_product["interest_by_region"]) == type( pd.DataFrame()) def test_trending_searches() -> None: trends.find_trending_searches("japan") assert type(builder.trends.return_product["trending_searches"]) == type( pd.DataFrame()) def test_today_searches() -> None: trends.find_today_searches() assert type(builder.trends.return_product["today_searches"]) == type(