mirror of
https://github.com/hydrosquall/tiingo-python.git
synced 2025-12-18 20:24:19 +01:00
Update get_news() to work when no sources are provided.
Currently, `sources=[]` by default, which will become "" once the list is `joined` to form a csv string. The tiingo api appears to interpret the empty string as "don't match any sources" instead of "match all sources". This commit fixes the problem by setting `sources` to `None` if the list is empty. Adds unit test for empty new sources list. Updates HISTORY.rst with note about bug fix.
This commit is contained in:
committed by
DavidMinnen
parent
f6ef473b0d
commit
aed36edb65
@@ -15,4 +15,5 @@ Contributors
|
|||||||
* Stephen Clark <steveclarkcode@gmail.com>
|
* Stephen Clark <steveclarkcode@gmail.com>
|
||||||
* Davis Thames
|
* Davis Thames
|
||||||
* Nima Yazdanmehr
|
* Nima Yazdanmehr
|
||||||
* Michael MacCormack
|
* Michael MacCormack
|
||||||
|
* David Minnen
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ History
|
|||||||
--------------------------------
|
--------------------------------
|
||||||
* Feature (Name #Number)
|
* Feature (Name #Number)
|
||||||
* Development: Run tests in Github Actions instead of Travis.org
|
* Development: Run tests in Github Actions instead of Travis.org
|
||||||
|
* [/news] Fix bug in get_news() when sources list is empty (#566)
|
||||||
|
|
||||||
0.13.0 (2020-12-12)
|
0.13.0 (2020-12-12)
|
||||||
--------------------------------
|
--------------------------------
|
||||||
|
|||||||
47
tests/fixtures/news_empty_sources.yaml
vendored
Normal file
47
tests/fixtures/news_empty_sources.yaml
vendored
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
interactions:
|
||||||
|
- request:
|
||||||
|
body: null
|
||||||
|
headers:
|
||||||
|
Accept:
|
||||||
|
- '*/*'
|
||||||
|
Accept-Encoding:
|
||||||
|
- gzip, deflate
|
||||||
|
Authorization:
|
||||||
|
- Token 0000000000000000000000000000000000000000
|
||||||
|
Connection:
|
||||||
|
- keep-alive
|
||||||
|
Content-Type:
|
||||||
|
- application/json
|
||||||
|
User-Agent:
|
||||||
|
- tiingo-python-client 0.13.0
|
||||||
|
method: GET
|
||||||
|
uri: https://api.tiingo.com/tiingo/news?limit=1&offset=0&sortBy=publishedDate&tickers=aapl&tickers=googl&tags=Technology&tags=Bitcoin&startDate=2016-01-01&endDate=2017-08-31&onlyWithTickers=False
|
||||||
|
response:
|
||||||
|
body:
|
||||||
|
string: "[{\"source\":\"finance.yahoo.com\",\"description\":\"Elon Musk disupted\
|
||||||
|
\ claims of a Gigafactory Bitcoin ATM, BitMEX hired a head of compliance and\
|
||||||
|
\ there's nearly $1.5 billion worth of Ethereum-tokenized bitcoin.\",\"tags\"\
|
||||||
|
:[\"Bitcoin\",\"CryptoCurrency\",\"Defi\",\"Ethereum\",\"Stock\",\"Technology\"\
|
||||||
|
,\"Unknown Sector\"],\"tickers\":[\"defi\",\"goog\",\"googl\"],\"publishedDate\"\
|
||||||
|
:\"2020-10-12T16:45:48Z\",\"url\":\"https://finance.yahoo.com/news/blockchain-bites-bitcoin-ethereum-whos-164548067.html\"\
|
||||||
|
,\"title\":\"Blockchain Bites: Bitcoin on Ethereum \u2013 The Whos, Whats\
|
||||||
|
\ and Whys\",\"crawlDate\":\"2020-10-12T17:57:59.290788Z\",\"id\":29484963}]"
|
||||||
|
headers:
|
||||||
|
allow:
|
||||||
|
- GET, HEAD, OPTIONS
|
||||||
|
content-length:
|
||||||
|
- '598'
|
||||||
|
content-type:
|
||||||
|
- application/json
|
||||||
|
date:
|
||||||
|
- Mon, 11 Jan 2021 04:16:10 GMT
|
||||||
|
server:
|
||||||
|
- nginx/1.14.0 (Ubuntu)
|
||||||
|
vary:
|
||||||
|
- Cookie, Origin
|
||||||
|
x-frame-options:
|
||||||
|
- SAMEORIGIN
|
||||||
|
status:
|
||||||
|
code: 200
|
||||||
|
message: OK
|
||||||
|
version: 1
|
||||||
@@ -183,6 +183,15 @@ class TestNews(TestCase):
|
|||||||
for article in articles:
|
for article in articles:
|
||||||
assert all(key in article for key in self.article_keys)
|
assert all(key in article for key in self.article_keys)
|
||||||
|
|
||||||
|
@vcr.use_cassette('tests/fixtures/news_empty_sources.yaml')
|
||||||
|
def test_get_news_empty_sources(self):
|
||||||
|
search_params = self.search_params.copy()
|
||||||
|
search_params['sources'] = []
|
||||||
|
articles = self._client.get_news(**search_params)
|
||||||
|
assert len(articles) == self.num_articles
|
||||||
|
for article in articles:
|
||||||
|
assert all(key in article for key in self.article_keys)
|
||||||
|
|
||||||
@vcr.use_cassette('tests/fixtures/news_bulk.yaml')
|
@vcr.use_cassette('tests/fixtures/news_bulk.yaml')
|
||||||
def test_get_news_bulk(self):
|
def test_get_news_bulk(self):
|
||||||
"""Fails because this API key lacks institutional license"""
|
"""Fails because this API key lacks institutional license"""
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ class TiingoClient(RestClient):
|
|||||||
'offset': offset,
|
'offset': offset,
|
||||||
'sortBy': sortBy,
|
'sortBy': sortBy,
|
||||||
'tickers': tickers,
|
'tickers': tickers,
|
||||||
'source': (",").join(sources),
|
'source': (",").join(sources) if sources else None,
|
||||||
'tags': tags,
|
'tags': tags,
|
||||||
'startDate': startDate,
|
'startDate': startDate,
|
||||||
'endDate': endDate,
|
'endDate': endDate,
|
||||||
|
|||||||
Reference in New Issue
Block a user