Skip to content

Commit

Permalink
version update setup
Browse files Browse the repository at this point in the history
- minor changes
- udpated TODO/DONE list
- JSON output of ETFs modified
  • Loading branch information
alvarob96 committed May 15, 2019
1 parent b4264d1 commit e7cd86f
Show file tree
Hide file tree
Showing 7 changed files with 491 additions and 146 deletions.
538 changes: 406 additions & 132 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ install:
- pip install requests==2.21.0
- pip install lxml==4.3.3
- pip install unidecode==1.0.23
- pip install investpy==0.8.4.2
- pip install investpy==0.8.4.3
- pip install pytest==4.1.1

script:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.3``
``pip install investpy==0.8.4.4``

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 Down Expand Up @@ -49,6 +49,8 @@ If needed you can open an [issue](https://github.com/alvarob96/investpy/issues)
* Internal fixes to improve its ease of adaptability
* Temporarily removed Python 2.7 support due to its warning of deprecation in January 1st of 2020
* Updated docstrings as reStructuredText (via PyCharm)
* Modified JSON output to fit current standard for historical data
* Added function to retrieve information from listed ETFs (id, name, symbol and tag)

## Additional Information

Expand Down
16 changes: 10 additions & 6 deletions investpy/Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
__author__ = "Alvaro Bartolome <[email protected]>"


# TODO: all lower case in objects to access it via dot operator (.)
# look for a proper justification of it

class Data(object):
"""
A class used to store the historical data of an equity, fund or etf
Expand Down Expand Up @@ -89,9 +92,10 @@ def etf_to_dict(self):
}

def etf_as_json(self):
return {self.date.strftime('%d/%m/%Y'): {
'Open': self.open,
'High': self.high,
'Low': self.low,
'Close': self.close,
}}
return {
'date': self.date.strftime('%d/%m/%Y'),
'open': self.open,
'high': self.high,
'low': self.low,
'close': self.close,
}
35 changes: 31 additions & 4 deletions investpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
from investpy.Data import Data


# TODO: add country/market param and mapping of 'resources/available_markets' in order to allow users retrieve
# TODO: add country/market param and mapping of resources/available_markets in order to allow users retrieve
# historical data from different markets.

# TODO: create thread pools to increase scraping efficiency and improve 'investpy' performance
# TODO: create thread pools to increase scraping efficiency and improve investpy performance => CHECK BOOK DOC

# TODO: generate sphinx documentation for version 1.0

Expand All @@ -32,10 +32,25 @@

# TODO: consider moving from es.investing to www.investing (long task - develop on developer branch)

# TODO: create API project built on Flask
# DONE: create API project built on Flask => 0.8.5

# TODO: add additional markets for equities/funds/etfs

# DONE: redefine JSON output for ETFs => 0.8.5
# https://eodhistoricaldata.com/api/eod/AAPL.US?api_token=OeAFFmMliFG5orCUuwAKQ8l4WWFQ67YX&period=d.&fmt=json

# TODO: keep HTML doc structure (remove get_text() functions or similar)

# TODO: improve project as described in ‘’Web Scraping with Python’'

# TODO: modify __init__ structure as functions are not supposed to be defined here?

# DONE: get etfs listed as dictionary with specified params

# DONE: updated docstrings

# TODO: fix dosctrings and unify structure with Google docstrings or similar


def get_equities_list():
"""
Expand Down Expand Up @@ -915,6 +930,18 @@ def get_etfs_list():
return es.list_etfs()


def get_etfs_dict(columns, as_json):
"""
This function retrieves a dictionary with the specfied columns of all the available etfs
Returns
-------
:returns a dictionary that contains all the available etf values specified in the columns
"""

return es.dict_etfs(columns=columns, as_json=as_json)


def get_etf_recent_data(etf, as_json=False, order='ascending'):
"""
This function retrieves recent historical data from the specified etf.
Expand Down Expand Up @@ -1174,7 +1201,7 @@ def get_etf_historical_data(etf, start, end, as_json=False, order='ascending'):
final.append(json_)
elif as_json is False:
df = pd.DataFrame.from_records([value.etf_to_dict() for value in result])
df.set_index('Date', inplace=True)
df.set_index('date', inplace=True)

final.append(df)
else:
Expand Down
38 changes: 38 additions & 0 deletions investpy/etfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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

Expand Down Expand Up @@ -100,3 +101,40 @@ def list_etfs():
raise IOError("ERR#009: etf list not found or unable to retrieve.")

return etfs['name'].tolist()


def dict_etfs(columns=['id', 'name', 'symbol', 'tag'], as_json=False):
"""
This function retrieves all the available etfs and returns a dictionary with the specified columns.
Available columns are: 'id', 'name', 'symbol' and 'tag'
All the available etfs can be found at: https://es.investing.com/etfs/spain-etfs
Returns
-------
:returns a dictionary that contains all the available etf values specified in the columns
"""

if not isinstance(columns, list):
raise ValueError("ERR#020: specified columns argument is not a list, it can just be list type.")

if not isinstance(as_json, bool):
raise ValueError("ERR#002: as_json argument can just be True or False, bool type.")

resource_package = __name__
resource_path = '/'.join(('resources', 'es', 'etfs.csv'))
if pkg_resources.resource_exists(resource_package, resource_path):
etfs = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
else:
names = get_etf_names()
etfs = pd.DataFrame(names)

if etfs is None:
raise IOError("ERR#009: etf list not found or unable to retrieve.")

if not all(column in etfs.columns.tolist() for column in columns):
raise ValueError("ERR#021: specified columns does not exist, available columns are <id, name, symbol, tag>")

if as_json:
return json.dumps(etfs[columns].to_dict(orient='records'))
else:
return etfs[columns].to_dict(orient='records')
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.3',
version='0.8.4.4',
packages=find_packages(),
url='https://github.com/alvarob96/investpy',
download_url='https://github.com/alvarob96/investpy/archive/0.8.4.3.tar.gz',
download_url='https://github.com/alvarob96/investpy/archive/0.8.4.4.tar.gz',
license='MIT License',
author='Alvaro Bartolome',
author_email='[email protected]',
Expand Down

0 comments on commit e7cd86f

Please sign in to comment.