Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser(description='scrap yahoo earning')
    parser.add_argument('-output_prefix', type=str, default='data_tickers/investing_', help='output file prefix')
    args = parser.parse_args()

    # Index
    indices = investpy.get_indices()
    df_index = pd.DataFrame(indices)
    df_index.to_csv(args.output_prefix + 'index_info.csv')

    # Commodity
    commodities = investpy.get_commodities()
    commodities_dict = investpy.get_commodities_dict()
    commodity_info_list = []
    for commodity,country in zip(commodities['name'].to_list(),commodities['country'].to_list()):
        print(commodity,',',country)
        commodity_info_list.append(investpy.get_commodity_information(commodity,country))
        time.sleep(scrap_delay)

    df_commodity = pd.concat(commodity_info_list)
    df_commodity.to_csv(args.output_prefix + 'commodity_info.csv')

    # ETF
    etfs_dict_us = investpy.get_etfs_dict('united states')
    etfs_dict_canada = investpy.get_etfs_dict('canada')
    df_etfs = pd.DataFrame(etfs_dict_us + etfs_dict_canada)
    df_etfs.to_csv(args.output_prefix + 'etfs_info.csv')

    # Stock
    stocks_dict_us = investpy.get_stocks_dict('united states')
    stocks_dict_canada = investpy.get_stocks_dict('canada')
    df_stocks = pd.DataFrame(stocks_dict_us + stocks_dict_canada)
    df_stocks.to_csv(args.output_prefix + 'stock_info.csv')
Exemplo n.º 2
0
def test_investpy_commodities():
    """
    This function checks that commodity data retrieval functions listed in investpy work properly.
    """

    params = [
        {
            'group': 'metals',
        },
        {
            'group': None,
        },
    ]

    for param in params:
        investpy.get_commodities(group=param['group'])
        investpy.get_commodities_list(group=param['group'])

    params = [
        {
            'group': None,
            'columns': ['title', 'full_name', 'name'],
            'as_json': True
        },
        {
            'group': None,
            'columns': ['title', 'full_name', 'name'],
            'as_json': False
        },
        {
            'group': 'metals',
            'columns': ['title', 'full_name', 'name'],
            'as_json': True
        },
        {
            'group': 'metals',
            'columns': ['title', 'full_name', 'name'],
            'as_json': False
        },
        {
            'group': 'metals',
            'columns': None,
            'as_json': False
        },
    ]

    for param in params:
        investpy.get_commodities_dict(group=param['group'],
                                      columns=param['columns'],
                                      as_json=param['as_json'])

    investpy.get_commodity_groups()

    params = [
        {
            'country': None,
            'as_json': True,
            'order': 'ascending',
        },
        {
            'country': 'united states',
            'as_json': False,
            'order': 'ascending',
        },
        {
            'country': 'united states',
            'as_json': True,
            'order': 'descending',
        },
        {
            'country': 'united states',
            'as_json': False,
            'order': 'descending',
        },
    ]

    for param in params:
        investpy.get_commodity_recent_data(commodity='copper',
                                           country=param['country'],
                                           as_json=param['as_json'],
                                           order=param['order'],
                                           interval='Daily')

        investpy.get_commodity_historical_data(commodity='copper',
                                               from_date='01/01/1990',
                                               to_date='01/01/2019',
                                               country=param['country'],
                                               as_json=param['as_json'],
                                               order=param['order'],
                                               interval='Daily')

    params = [
        {
            'commodity': 'copper',
            'country': None,
            'as_json': False
        },
        {
            'commodity': 'copper',
            'country': 'united states',
            'as_json': True
        }
    ]

    for param in params:
        investpy.get_commodity_information(commodity=param['commodity'], country=param['country'], as_json=param['as_json'])
    
    params = [
        {
            'group': 'metals',
            'as_json': True,
            'n_results': 100
        },
        {
            'group': 'metals',
            'as_json': False,
            'n_results': 100
        }
    ]

    for param in params:
        investpy.get_commodities_overview(group=param['group'], as_json=param['as_json'], n_results=param['n_results'])

    investpy.search_commodities(by='name', value='gold')