Skip to content

Commit

Permalink
minor changes to fix python 2.7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarob96 committed Apr 30, 2019
1 parent 7fe1d6e commit 331843c
Show file tree
Hide file tree
Showing 6 changed files with 520 additions and 340 deletions.
803 changes: 490 additions & 313 deletions .idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ dist: xenial
install:
- pip install pandas==0.24.2
- pip install requests==2.21.0
- pip install lxml==4.3.2
- pip install lxml==4.3.3
- pip install unidecode==1.0.23
- pip install investpy==0.8.3
- pip install investpy==0.8.4.1
- pip install pytest==4.1.1

script:
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Investing Scraper of historical data from continuous spanish stock market
# investpy - Spanish Stock Historical Data Scraper

[![Python Version](https://img.shields.io/pypi/pyversions/investpy.svg)](https://pypi.org/project/investpy/)
[![PyPi Version](https://img.shields.io/pypi/v/investpy.svg)](https://pypi.org/project/investpy/)
Expand All @@ -16,7 +16,7 @@ To conclude this section, I am in the need to specify that this is not the final

In order to get this package working you will need to install [**investpy**](https://pypi.org/project/investpy/) from PyPi via Terminal typing:

``pip install investpy==0.8.4``
``pip install investpy==0.8.4.1``

All the dependencies are already listed on the setup file of the package, but to sum them up, you will need the following requirements:

Expand All @@ -26,7 +26,7 @@ All the dependencies are already listed on the setup file of the package, but to
* [**unidecode 1.0.23**](https://pypi.org/project/unidecode/)
* [**pytest 4.1.1**](https://pypi.org/project/pytest/)

## Release Notes 0.8.4
## Release Notes 0.8.4.x

* Several fixes on minor bugs/errors
* Added support for Python 3.5
Expand All @@ -38,6 +38,7 @@ All the dependencies are already listed on the setup file of the package, but to
* Full company name for equities add
* Company Profile retrieval returned value is a dict with the source and the description
* Internal fixes to improve its ease of adaptability
* Python 2.7 unidecode error fix (warning Python 2.7 will be deprecated in 2020)

## Additional Information

Expand Down
35 changes: 18 additions & 17 deletions investpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
#!/usr/bin/env python

# Copyright 2018-2019 Alvaro Bartolome
Expand Down Expand Up @@ -70,7 +71,7 @@ def get_recent_data(equity, as_json=False, order='ascending'):
raise IOError("ERR#001: equities object not found or unable to retrieve.")

if unidecode.unidecode(equity.lower()) not in [unidecode.unidecode(value.lower()) for value in equities['name'].tolist()]:
raise RuntimeError("ERR#018: equity " + unidecode.unidecode(equity.lower()) + " not found, check if it is correct.")
raise RuntimeError("ERR#018: equity " + equity.lower() + " not found, check if it is correct.")

for row in equities.itertuples():
if unidecode.unidecode(row.name.lower()) == unidecode.unidecode(equity.lower()):
Expand Down Expand Up @@ -224,11 +225,11 @@ def get_historical_data(equity, start, end, as_json=False, order='ascending'):
if equities is None:
raise IOError("ERR#001: equities object not found or unable to retrieve.")

if unidecode.unidecode(equity.lower()) not in [unidecode.unidecode(value.lower()) for value in equities['name'].tolist()]:
raise RuntimeError("ERR#018: equity " + unidecode.unidecode(equity.lower()) + " not found, check if it is correct.")
if unidecode.unidecode(equity.lower()) not in [value.lower() for value in equities['name'].tolist()]:
raise RuntimeError("ERR#018: equity " + equity.lower() + " not found, check if it is correct.")

for row in equities.itertuples():
if unidecode.unidecode(row.name.lower()) == unidecode.unidecode(equity.lower()):
if row.name.lower() == unidecode.unidecode(equity.lower()):
final = list()

for index in range(len(date_interval['intervals'])):
Expand Down Expand Up @@ -367,16 +368,16 @@ def get_equity_company_profile(equity, language='english'):
if equities is None:
raise IOError("ERR#001: equities object not found or unable to retrieve.")

if unidecode.unidecode(equity.lower()) not in [unidecode.unidecode(value.lower()) for value in equities['name'].tolist()]:
raise RuntimeError("ERR#018: equity " + unidecode.unidecode(equity.lower()) + " not found, check if it is correct.")
if unidecode.unidecode(equity.lower()) not in [value.lower() for value in equities['name'].tolist()]:
raise RuntimeError("ERR#018: equity " + equity.lower() + " not found, check if it is correct.")

company_profile = {
'url': None,
'desc': None
}

for row in equities.itertuples():
if unidecode.unidecode(row.name.lower()) == unidecode.unidecode(equity.lower()):
if row.name.lower() == unidecode.unidecode(equity.lower()):
if selected_source == 'Bolsa de Madrid':
url = "http://www.bolsamadrid.es/esp/aspx/Empresas/FichaValor.aspx?ISIN=" + row.isin

Expand Down Expand Up @@ -489,8 +490,8 @@ def get_fund_recent_data(fund, as_json=False, order='ascending'):
if funds is None:
raise IOError("ERR#005: funds object not found or unable to retrieve.")

if unidecode.unidecode(fund.lower()) not in [unidecode.unidecode(value.lower()) for value in funds['name'].tolist()]:
raise RuntimeError("ERR#019: fund " + unidecode.unidecode(fund.lower()) + " not found, check if it is correct.")
if unidecode.unidecode(fund.lower()) not in [value.lower() for value in funds['name'].tolist()]:
raise RuntimeError("ERR#019: fund " + fund.lower() + " not found, check if it is correct.")

for row in funds.itertuples():
if row.name.lower() == unidecode.unidecode(fund.lower()):
Expand Down Expand Up @@ -637,8 +638,8 @@ def get_fund_historical_data(fund, start, end, as_json=False, order='ascending')
if funds is None:
raise IOError("ERR#005: funds object not found or unable to retrieve.")

if unidecode.unidecode(fund.lower()) not in [unidecode.unidecode(value.lower()) for value in funds['name'].tolist()]:
raise RuntimeError("ERR#019: fund " + unidecode.unidecode(fund.lower()) + " not found, check if it is correct.")
if unidecode.unidecode(fund.lower()) not in [value.lower() for value in funds['name'].tolist()]:
raise RuntimeError("ERR#019: fund " + fund.lower() + " not found, check if it is correct.")

for row in funds.itertuples():
if row.name.lower() == unidecode.unidecode(fund.lower()):
Expand Down Expand Up @@ -760,8 +761,8 @@ def get_fund_information(fund, as_json=False):
if funds is None:
raise IOError("ERR#005: funds object not found or unable to retrieve.")

if unidecode.unidecode(fund.lower()) not in [unidecode.unidecode(value.lower()) for value in funds['name'].tolist()]:
raise RuntimeError("ERR#019: fund " + unidecode.unidecode(fund.lower()) + " not found, check if it is correct.")
if unidecode.unidecode(fund.lower()) not in [value.lower() for value in funds['name'].tolist()]:
raise RuntimeError("ERR#019: fund " + fund.lower() + " not found, check if it is correct.")

for row in funds.itertuples():
if row.name.lower() == unidecode.unidecode(fund.lower()):
Expand Down Expand Up @@ -917,8 +918,8 @@ def get_etf_recent_data(etf, as_json=False, order='ascending'):
if etfs is None:
raise IOError("ERR#009: etfs object not found or unable to retrieve.")

if unidecode.unidecode(etf.lower()) not in [unidecode.unidecode(value.lower()) for value in etfs['name'].tolist()]:
raise RuntimeError("ERR#019: etf " + unidecode.unidecode(etf.lower()) + " not found, check if it is correct.")
if unidecode.unidecode(etf.lower()) not in [value.lower() for value in etfs['name'].tolist()]:
raise RuntimeError("ERR#019: etf " + etf.lower() + " not found, check if it is correct.")

for row in etfs.itertuples():
if row.name.lower() == unidecode.unidecode(etf.lower()):
Expand Down Expand Up @@ -1065,8 +1066,8 @@ def get_etf_historical_data(etf, start, end, as_json=False, order='ascending'):
if etfs is None:
raise IOError("ERR#009: etfs object not found or unable to retrieve.")

if unidecode.unidecode(etf.lower()) not in [unidecode.unidecode(value.lower()) for value in etfs['name'].tolist()]:
raise RuntimeError("ERR#019: etf " + unidecode.unidecode(etf.lower()) + " not found, check if it is correct.")
if unidecode.unidecode(etf.lower()) not in [value.lower() for value in etfs['name'].tolist()]:
raise RuntimeError("ERR#019: etf " + etf.lower() + " not found, check if it is correct.")

for row in etfs.itertuples():
if row.name.lower() == unidecode.unidecode(etf.lower()):
Expand Down
7 changes: 4 additions & 3 deletions investpy/equities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# Copyright 2018-2019 Alvaro Bartolome
# See LICENSE for details.

import time

import pandas as pd
import pkg_resources
import requests
import time
from lxml.html import fromstring
import pkg_resources

from investpy import user_agent as ua

Expand Down Expand Up @@ -60,7 +61,7 @@ def get_equity_names():
isin_ = get_isin_code(tag_)

data = {
"name": element_.text_content(),
"name": element_.text,
"full_name": full_name_.rstrip(),
"tag": tag_,
"isin": isin_,
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def readme():

setup(
name='investpy',
version='0.8.4',
version='0.8.4.1',
packages=find_packages(),
url='',
download_url='https://github.com/alvarob96/investpy/archive/0.8.4.tar.gz',
download_url='https://github.com/alvarob96/investpy/archive/0.8.4.1.tar.gz',
license='MIT License',
author='Alvaro Bartolome',
author_email='[email protected]',
Expand Down

0 comments on commit 331843c

Please sign in to comment.