Skip to content

Commit e7cd86f

Browse files
author
alvarob96
committed
version update setup
- minor changes - udpated TODO/DONE list - JSON output of ETFs modified
1 parent b4264d1 commit e7cd86f

File tree

7 files changed

+491
-146
lines changed

7 files changed

+491
-146
lines changed

Diff for: .idea/workspace.xml

+406-132
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ install:
1212
- pip install requests==2.21.0
1313
- pip install lxml==4.3.3
1414
- pip install unidecode==1.0.23
15-
- pip install investpy==0.8.4.2
15+
- pip install investpy==0.8.4.3
1616
- pip install pytest==4.1.1
1717

1818
script:

Diff for: README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ To conclude this section, I am in the need to specify that this is not the final
1616

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

19-
``pip install investpy==0.8.4.3``
19+
``pip install investpy==0.8.4.4``
2020

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

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

5355
## Additional Information
5456

Diff for: investpy/Data.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
__author__ = "Alvaro Bartolome <[email protected]>"
77

88

9+
# TODO: all lower case in objects to access it via dot operator (.)
10+
# look for a proper justification of it
11+
912
class Data(object):
1013
"""
1114
A class used to store the historical data of an equity, fund or etf
@@ -89,9 +92,10 @@ def etf_to_dict(self):
8992
}
9093

9194
def etf_as_json(self):
92-
return {self.date.strftime('%d/%m/%Y'): {
93-
'Open': self.open,
94-
'High': self.high,
95-
'Low': self.low,
96-
'Close': self.close,
97-
}}
95+
return {
96+
'date': self.date.strftime('%d/%m/%Y'),
97+
'open': self.open,
98+
'high': self.high,
99+
'low': self.low,
100+
'close': self.close,
101+
}

Diff for: investpy/__init__.py

+31-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
from investpy.Data import Data
2020

2121

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

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

2727
# TODO: generate sphinx documentation for version 1.0
2828

@@ -32,10 +32,25 @@
3232

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

35-
# TODO: create API project built on Flask
35+
# DONE: create API project built on Flask => 0.8.5
3636

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

39+
# DONE: redefine JSON output for ETFs => 0.8.5
40+
# https://eodhistoricaldata.com/api/eod/AAPL.US?api_token=OeAFFmMliFG5orCUuwAKQ8l4WWFQ67YX&period=d.&fmt=json
41+
42+
# TODO: keep HTML doc structure (remove get_text() functions or similar)
43+
44+
# TODO: improve project as described in ‘’Web Scraping with Python’'
45+
46+
# TODO: modify __init__ structure as functions are not supposed to be defined here?
47+
48+
# DONE: get etfs listed as dictionary with specified params
49+
50+
# DONE: updated docstrings
51+
52+
# TODO: fix dosctrings and unify structure with Google docstrings or similar
53+
3954

4055
def get_equities_list():
4156
"""
@@ -915,6 +930,18 @@ def get_etfs_list():
915930
return es.list_etfs()
916931

917932

933+
def get_etfs_dict(columns, as_json):
934+
"""
935+
This function retrieves a dictionary with the specfied columns of all the available etfs
936+
937+
Returns
938+
-------
939+
:returns a dictionary that contains all the available etf values specified in the columns
940+
"""
941+
942+
return es.dict_etfs(columns=columns, as_json=as_json)
943+
944+
918945
def get_etf_recent_data(etf, as_json=False, order='ascending'):
919946
"""
920947
This function retrieves recent historical data from the specified etf.
@@ -1174,7 +1201,7 @@ def get_etf_historical_data(etf, start, end, as_json=False, order='ascending'):
11741201
final.append(json_)
11751202
elif as_json is False:
11761203
df = pd.DataFrame.from_records([value.etf_to_dict() for value in result])
1177-
df.set_index('Date', inplace=True)
1204+
df.set_index('date', inplace=True)
11781205

11791206
final.append(df)
11801207
else:

Diff for: investpy/etfs.py

+38
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pandas as pd
99
import requests
10+
import json
1011
import pkg_resources
1112
from lxml.html import fromstring
1213

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

102103
return etfs['name'].tolist()
104+
105+
106+
def dict_etfs(columns=['id', 'name', 'symbol', 'tag'], as_json=False):
107+
"""
108+
This function retrieves all the available etfs and returns a dictionary with the specified columns.
109+
Available columns are: 'id', 'name', 'symbol' and 'tag'
110+
All the available etfs can be found at: https://es.investing.com/etfs/spain-etfs
111+
112+
Returns
113+
-------
114+
:returns a dictionary that contains all the available etf values specified in the columns
115+
"""
116+
117+
if not isinstance(columns, list):
118+
raise ValueError("ERR#020: specified columns argument is not a list, it can just be list type.")
119+
120+
if not isinstance(as_json, bool):
121+
raise ValueError("ERR#002: as_json argument can just be True or False, bool type.")
122+
123+
resource_package = __name__
124+
resource_path = '/'.join(('resources', 'es', 'etfs.csv'))
125+
if pkg_resources.resource_exists(resource_package, resource_path):
126+
etfs = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
127+
else:
128+
names = get_etf_names()
129+
etfs = pd.DataFrame(names)
130+
131+
if etfs is None:
132+
raise IOError("ERR#009: etf list not found or unable to retrieve.")
133+
134+
if not all(column in etfs.columns.tolist() for column in columns):
135+
raise ValueError("ERR#021: specified columns does not exist, available columns are <id, name, symbol, tag>")
136+
137+
if as_json:
138+
return json.dumps(etfs[columns].to_dict(orient='records'))
139+
else:
140+
return etfs[columns].to_dict(orient='records')

Diff for: setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ def readme():
1111

1212
setup(
1313
name='investpy',
14-
version='0.8.4.3',
14+
version='0.8.4.4',
1515
packages=find_packages(),
1616
url='https://github.com/alvarob96/investpy',
17-
download_url='https://github.com/alvarob96/investpy/archive/0.8.4.3.tar.gz',
17+
download_url='https://github.com/alvarob96/investpy/archive/0.8.4.4.tar.gz',
1818
license='MIT License',
1919
author='Alvaro Bartolome',
2020
author_email='[email protected]',

0 commit comments

Comments
 (0)