-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated resources and requirements & fixed errors
- fixed scraping errors (xpath) - added todo tasks - completed done tasks - 0.8.5 version preparation - efficiency/errors checks need
- Loading branch information
alvarob96
committed
May 17, 2019
1 parent
e7cd86f
commit 5263f0e
Showing
16 changed files
with
654 additions
and
584 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,13 @@ | |
__author__ = "Alvaro Bartolome <[email protected]>" | ||
|
||
import datetime | ||
import json | ||
from random import randint | ||
import unidecode | ||
|
||
import pandas as pd | ||
import pkg_resources | ||
import requests | ||
import json | ||
import unidecode | ||
from lxml.html import fromstring | ||
|
||
from investpy import user_agent as ua, equities as ts, funds as fs, etfs as es | ||
|
@@ -22,6 +22,8 @@ | |
# TODO: add country/market param and mapping of ‘resources/available_markets’ in order to allow users retrieve | ||
# historical data from different markets. | ||
|
||
# DONE: available_languages replaced by available_markets | ||
|
||
# TODO: create thread pools to increase scraping efficiency and improve ‘investpy’ performance => CHECK BOOK DOC | ||
|
||
# TODO: generate sphinx documentation for version 1.0 | ||
|
@@ -51,6 +53,12 @@ | |
|
||
# TODO: fix dosctrings and unify structure with Google docstrings or similar | ||
|
||
# WARNING: RE-GENERATE MARKET FILES BEFORE EVERY RELEASE | ||
|
||
# TODO: add 'clase de activo', 'isin' and 'emisor' to funds | ||
|
||
# DONE: updated equities, funds and etfs retrieval functions | ||
|
||
|
||
def get_equities_list(): | ||
""" | ||
|
@@ -164,10 +172,12 @@ def get_recent_data(equity, as_json=False, order='ascending'): | |
'recent': | ||
[value.equity_as_json() for value in result] | ||
} | ||
return json.dumps(json_) | ||
|
||
return json.dumps(json_, sort_keys=False) | ||
elif as_json is False: | ||
df = pd.DataFrame.from_records([value.equity_to_dict() for value in result]) | ||
df.set_index('Date', inplace=True) | ||
|
||
return df | ||
else: | ||
raise RuntimeError("ERR#004: data retrieval error while scraping.") | ||
|
@@ -364,7 +374,7 @@ def get_historical_data(equity, start, end, as_json=False, order='ascending'): | |
raise RuntimeError("ERR#004: data retrieval error while scraping.") | ||
|
||
if as_json is True: | ||
return json.dumps(final) | ||
return json.dumps(final, sort_keys=False) | ||
elif as_json is False: | ||
return pd.concat(final) | ||
else: | ||
|
@@ -592,10 +602,12 @@ def get_fund_recent_data(fund, as_json=False, order='ascending'): | |
'recent': | ||
[value.fund_as_json() for value in result] | ||
} | ||
return json.dumps(json_) | ||
|
||
return json.dumps(json_, sort_keys=False) | ||
elif as_json is False: | ||
df = pd.DataFrame.from_records([value.fund_to_dict() for value in result]) | ||
df.set_index('Date', inplace=True) | ||
|
||
return df | ||
|
||
else: | ||
|
@@ -768,7 +780,7 @@ def get_fund_historical_data(fund, start, end, as_json=False, order='ascending') | |
raise RuntimeError("ERR#004: data retrieval error while scraping.") | ||
|
||
if as_json is True: | ||
return json.dumps(final) | ||
return json.dumps(final, sort_keys=False) | ||
elif as_json is False: | ||
return pd.concat(final) | ||
else: | ||
|
@@ -1032,10 +1044,12 @@ def get_etf_recent_data(etf, as_json=False, order='ascending'): | |
'recent': | ||
[value.etf_as_json() for value in result] | ||
} | ||
return json.dumps(json_) | ||
|
||
return json.dumps(json_, sort_keys=False) | ||
elif as_json is False: | ||
df = pd.DataFrame.from_records([value.etf_to_dict() for value in result]) | ||
df.set_index('Date', inplace=True) | ||
|
||
return df | ||
|
||
else: | ||
|
@@ -1201,14 +1215,14 @@ 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: | ||
raise RuntimeError("ERR#004: data retrieval error while scraping.") | ||
|
||
if as_json is True: | ||
return json.dumps(final) | ||
return json.dumps(final, sort_keys=False) | ||
elif as_json is False: | ||
return pd.concat(final) | ||
else: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
|
||
__author__ = "Alvaro Bartolome <[email protected]>" | ||
|
||
import time | ||
|
||
import pandas as pd | ||
import requests | ||
import json | ||
|
@@ -40,7 +42,9 @@ def get_etf_names(): | |
raise ConnectionError("ERR#015: error " + req.status_code + ", try again later.") | ||
|
||
root_ = fromstring(req.text) | ||
path_ = root_.xpath(".//table[@id='etfs']/tbody/tr") | ||
path_ = root_.xpath(".//table[@id='etfs']" | ||
"/tbody" | ||
"/tr") | ||
|
||
results = list() | ||
|
||
|
@@ -99,11 +103,11 @@ def list_etfs(): | |
|
||
if etfs is None: | ||
raise IOError("ERR#009: etf list not found or unable to retrieve.") | ||
|
||
return etfs['name'].tolist() | ||
else: | ||
return etfs['name'].tolist() | ||
|
||
|
||
def dict_etfs(columns=['id', 'name', 'symbol', 'tag'], as_json=False): | ||
def dict_etfs(columns=None, 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' | ||
|
@@ -114,8 +118,11 @@ def dict_etfs(columns=['id', 'name', 'symbol', 'tag'], as_json=False): | |
: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 columns is None: | ||
columns = ['id', 'name', 'symbol', 'tag'] | ||
else: | ||
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.") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
id,name,symbol,tag | ||
37633,Lyxor Ibex 35 Doble Inverso Diario,2INVE,lyxor-ibex-35-x2-inverso | ||
37631,Lyxor Ibex 35 Doble Apalancado Diario C-EUR,IBEXA,lyxor-ibex-35-doble-apalancado | ||
37632,Accion IBEX 35 Cotizado Armonizado FI,BBVAI,bbva-accion-ibex-35 | ||
47649,BBVA Accion DJ Eurostoxx 50,BBVAE,bbva-accion-dj-eurostoxx-50 | ||
38897,Lyxor Ibex 35 Inverso Diario,INVEX,lyxor-ibex-35-invers | ||
38898,Lyxor Ibex35 (DR) D-EUR,LYXIB,lyxor-ibex-35 | ||
37632,Accion IBEX 35 Cotizado Armonizado FI,BBVAI,bbva-accion-ibex-35 | ||
38897,Lyxor Ibex 35 Inverso Diario,INVEX,lyxor-ibex-35-invers |
Oops, something went wrong.