Skip to content

Commit

Permalink
Merge branch 'release/1.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
RomelTorres committed Feb 11, 2018
2 parents 1c97798 + 277d22f commit 6ba2d52
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 312 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ python:
install:
- pip install simplejson
- pip install pandas==0.19.2
- pip install requests
- pip install requests-mock
script:
nosetests --nocapture test_alpha_vantage/test_alphavantage.py
allow_failure:
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ Alpha Vantage delivers a free API for real time financial data and most used fin
Vantage (http://www.alphavantage.co/). It requires a free API, that can be requested on http://www.alphavantage.co/support/#api-key. You can have a look at all the api calls available in their documentation http://www.alphavantage.co/documentation

## News
From version 1.8.0 onwards, the column names of the data frames have changed, they are now exactly what alphavantage gives back in their json response. You can see the examples in better detail in the following git repo: https://github.com/RomelTorres/av_example
* From version 1.9.0 onwards, the urllib was substituted by pythons request library that is thread safe. If you have any error, post an issue.
* From version 1.8.0 onwards, the column names of the data frames have changed, they are now exactly what alphavantage gives back in their json response. You can see the examples in better detail in the following git repo: https://github.com/RomelTorres/av_example
* From version 1.6.0, pandas was taken out as a hard dependency.

## Install
To install the package use:
```shell
pip install alpha_vantage
```
Since version 1.6.0 pandas was taken out as a hard dependency, so if you want to have pandas support install pandas too:
Or install with pandas support, simply install pandas too:
```shell
pip install alpha_vantage, pandas
```
Expand Down
20 changes: 6 additions & 14 deletions alpha_vantage/alphavantage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import urllib
import requests
import sys
from functools import wraps
import inspect
Expand Down Expand Up @@ -143,7 +143,7 @@ def _call_wrapper(self, *args, **kwargs):
url = '{}&{}={}'.format(url, arg_name, arg_value)
# Allow the output format to be json or csv (supported by
# alphavantage api). Pandas is simply json converted.
if 'json' or 'csv' in self.output_format.lower():
if 'json' in self.output_format.lower() or 'csv' in self.output_format.lower():
oformat = self.output_format.lower()
elif 'pandas' in self.output_format.lower():
oformat = 'json'
Expand Down Expand Up @@ -254,25 +254,17 @@ def _handle_api_call(self, url):
meta_data_key: The key for getting the meta data information out
of the json object
"""
# In order to keep supporting python 2.7, we have to do this.
if sys.version_info.major == 3:
response = urllib.request.urlopen(url)
else:
response = urllib.urlopen(url)
url_response = response.read()
response = requests.get(url)
if 'json' in self.output_format.lower() or 'pandas' in \
self.output_format.lower():
json_response = loads(url_response)
if not json_response:
raise ValueError(
'Error getting data from the api, no return was given.')
elif "Error Message" in json_response:
json_response = response.json()
if "Error Message" in json_response:
raise ValueError(json_response["Error Message"])
elif "Information" in json_response and self.treat_info_as_error:
raise ValueError(json_response["Information"])
return json_response
else:
csv_response = csv.reader(url_response.splitlines())
csv_response = csv.reader(response.text.splitlines())
if not csv_response:
raise ValueError(
'Error getting data from the api, no return was given.')
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name='alpha_vantage',
version='1.8.1',
version='1.9.0',
author='Romel J. Torres',
author_email='[email protected]',
license='MIT',
Expand All @@ -29,11 +29,11 @@
],
url='https://github.com/RomelTorres/alpha_vantage',
install_requires=[
'simplejson',
'requests',
],
test_requires=[
'nose',
'simplejson'
'requests_mock'
],
extras_requires={
'pandas': ['pandas'],
Expand Down
368 changes: 75 additions & 293 deletions test_alpha_vantage/test_alphavantage.py

Large diffs are not rendered by default.

File renamed without changes.

0 comments on commit 6ba2d52

Please sign in to comment.