Skip to content

Commit e09669a

Browse files
author
Dario Varotto
committed
Text analytics: retry_on_too_early on /metadata
1 parent 8f0b4f6 commit e09669a

File tree

5 files changed

+98
-94
lines changed

5 files changed

+98
-94
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v1.0.47 (2021-04-12)
4+
Text analytics: Handle retry if too early on /metadata endpoint
5+
36
## v1.0.46 (2021-04-05)
47
Compatibility with RavenPack Edge
58

README.rst

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Installation
1111

1212
::
1313

14-
pip install ravenpackapi
14+
pip install ravenpackapi
1515

1616
About
1717
-----
@@ -24,7 +24,7 @@ Usage
2424
-----
2525

2626
In order to be able to use the RavenPack API you will need an API KEY.
27-
If you dont already have one please contact your `customer
27+
If you don't already have one please contact your `customer
2828
support <mailto:sales@ravenpack.com>`__ representative.
2929

3030
To begin using the API you will need to instantiate an API object that
@@ -35,9 +35,9 @@ environment variable or set it in your code:
3535

3636
.. code:: python
3737
38-
from ravenpackapi import RPApi
38+
from ravenpackapi import RPApi
3939
40-
api = RPApi(api_key="YOUR_API_KEY")
40+
api = RPApi(api_key="YOUR_API_KEY")
4141
4242
Creating a new dataset
4343
~~~~~~~~~~~~~~~~~~~~~~
@@ -47,19 +47,19 @@ API with a Dataset instance.
4747

4848
.. code:: python
4949
50-
from ravenpackapi import Dataset
50+
from ravenpackapi import Dataset
5151
52-
ds = api.create_dataset(
53-
Dataset(
54-
name="New Dataset",
55-
filters={
56-
"relevance": {
57-
"$gte": 90
58-
}
59-
},
60-
)
61-
)
62-
print("Dataset created", ds)
52+
ds = api.create_dataset(
53+
Dataset(
54+
name="New Dataset",
55+
filters={
56+
"relevance": {
57+
"$gte": 90
58+
}
59+
},
60+
)
61+
)
62+
print("Dataset created", ds)
6363
6464
Getting data from the datasets
6565
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -71,10 +71,10 @@ Here is how you may get a dataset definition for a pre-existing dataset
7171

7272
.. code:: python
7373
74-
# Get the dataset description from the server, here we use 'us30'
75-
# one of RavenPack public datasets with the top30 companies in the US
74+
# Get the dataset description from the server, here we use 'us30'
75+
# one of RavenPack public datasets with the top30 companies in the US
7676
77-
ds = api.get_dataset(dataset_id='us30')
77+
ds = api.get_dataset(dataset_id='us30')
7878
7979
Downloads: json
8080
^^^^^^^^^^^^^^^
@@ -85,13 +85,13 @@ use the asynchronous datafile endpoint instead.
8585

8686
.. code:: python
8787
88-
data = ds.json(
89-
start_date='2018-01-05 18:00:00',
90-
end_date='2018-01-05 18:01:00',
91-
)
88+
data = ds.json(
89+
start_date='2018-01-05 18:00:00',
90+
end_date='2018-01-05 18:01:00',
91+
)
9292
93-
for record in data:
94-
print(record)
93+
for record in data:
94+
print(record)
9595
9696
Json queries are limited to
9797

@@ -110,13 +110,13 @@ some time to complete.
110110

111111
.. code:: python
112112
113-
job = ds.request_datafile(
114-
start_date='2018-01-05 18:00:00',
115-
end_date='2018-01-05 18:01:00',
116-
)
113+
job = ds.request_datafile(
114+
start_date='2018-01-05 18:00:00',
115+
end_date='2018-01-05 18:01:00',
116+
)
117117
118-
with open('output.csv') as fp:
119-
job.save_to_file(filename=fp.name)
118+
with open('output.csv') as fp:
119+
job.save_to_file(filename=fp.name)
120120
121121
Streaming real-time data
122122
~~~~~~~~~~~~~~~~~~~~~~~~
@@ -132,64 +132,64 @@ You can find a `real-time streaming example
132132
here <ravenpackapi/examples/get_realtime_news.py>`__.
133133

134134
The Result object handles the conversion of various fields into the
135-
appropriate type, i.e. \ ``record.timestamp_utc`` will be converted to
135+
appropriate type, i.e. ``record.timestamp_utc`` will be converted to
136136
``datetime``
137137

138138
Entity mapping
139139
~~~~~~~~~~~~~~
140140

141-
The entity mapping endpoint allow you to find the RP_ENTITY_ID mapped to
142-
your universe of entities.
141+
The entity mapping endpoint allow you to find the RP\_ENTITY\_ID mapped
142+
to your universe of entities.
143143

144144
.. code:: python
145145
146-
universe = [
147-
"RavenPack",
148-
{'ticker': 'AAPL'},
149-
'California USA',
150-
{ # Amazon, specifying various fields
151-
"client_id": "12345-A",
152-
"date": "2017-01-01",
153-
"name": "Amazon Inc.",
154-
"entity_type": "COMP",
155-
"isin": "US0231351067",
156-
"cusip": "023135106",
157-
"sedol": "B58WM62",
158-
"listing": "XNAS:AMZN"
159-
},
160-
161-
]
162-
mapping = api.get_entity_mapping(universe)
163-
164-
# in this case we match everything
165-
assert len(mapping.matched) == len(universe)
166-
assert [m.name for m in mapping.matched] == [
167-
"RavenPack International S.L.",
168-
"Apple Inc.",
169-
"California, U.S.",
170-
"Amazon.com Inc."
171-
]
146+
universe = [
147+
"RavenPack",
148+
{'ticker': 'AAPL'},
149+
'California USA',
150+
{ # Amazon, specifying various fields
151+
"client_id": "12345-A",
152+
"date": "2017-01-01",
153+
"name": "Amazon Inc.",
154+
"entity_type": "COMP",
155+
"isin": "US0231351067",
156+
"cusip": "023135106",
157+
"sedol": "B58WM62",
158+
"listing": "XNAS:AMZN"
159+
},
160+
161+
]
162+
mapping = api.get_entity_mapping(universe)
163+
164+
# in this case we match everything
165+
assert len(mapping.matched) == len(universe)
166+
assert [m.name for m in mapping.matched] == [
167+
"RavenPack International S.L.",
168+
"Apple Inc.",
169+
"California, U.S.",
170+
"Amazon.com Inc."
171+
]
172172
173173
Entity reference
174174
~~~~~~~~~~~~~~~~
175175

176176
The entity reference endpoint give you all the available information for
177-
an Entity given the RP_ENTITY_ID
177+
an Entity given the RP\_ENTITY\_ID
178178

179179
.. code:: python
180180
181-
ALPHABET_RP_ENTITY_ID = '4A6F00'
181+
ALPHABET_RP_ENTITY_ID = '4A6F00'
182182
183-
references = api.get_entity_reference(ALPHABET_RP_ENTITY_ID)
183+
references = api.get_entity_reference(ALPHABET_RP_ENTITY_ID)
184184
185-
# show all the names over history
186-
for name in references.names:
187-
print(name.value, name.start, name.end)
185+
# show all the names over history
186+
for name in references.names:
187+
print(name.value, name.start, name.end)
188188
189-
# print all the ticket valid today
190-
for ticker in references.tickers:
191-
if ticker.is_valid():
192-
print(ticker)
189+
# print all the ticket valid today
190+
for ticker in references.tickers:
191+
if ticker.is_valid():
192+
print(ticker)
193193
194194
Text Analytics
195195
~~~~~~~~~~~~~~
@@ -213,15 +213,15 @@ internal proxy:
213213

214214
.. code:: python
215215
216-
api = RPApi()
217-
api.common_request_params.update(
218-
dict(
219-
proxies={'https': 'http://your_internal_proxy:9999'},
220-
verify=False,
221-
)
222-
)
216+
api = RPApi()
217+
api.common_request_params.update(
218+
dict(
219+
proxies={'https': 'http://your_internal_proxy:9999'},
220+
verify=False,
221+
)
222+
)
223223
224-
# use the api to do requests
224+
# use the api to do requests
225225
226226
PS. For setting your internal proxies, requests will honor the
227-
HTTPS_PROXY environment variable.
227+
HTTPS\_PROXY environment variable.

ravenpackapi/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from ravenpackapi.utils.dynamic_sessions import DynamicSession
1515

1616
_VALID_METHODS = ('get', 'post', 'put', 'delete', 'patch')
17-
VERSION = '1.0.46'
17+
VERSION = '1.0.47'
1818

1919
logger = logging.getLogger("ravenpack.core")
2020

ravenpackapi/upload/models.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def get_metadata(self, force_refresh=False):
5454
if self.file_name and not force_refresh: # we already have the file metadata
5555
pass
5656
else:
57-
response = self.api.request('%s/files/%s/metadata' % (self.api._UPLOAD_BASE_URL, self.file_id))
57+
response = retry_on_too_early(self.api.request,
58+
'%s/files/%s/metadata' % (self.api._UPLOAD_BASE_URL, self.file_id))
5859
metadata = response.json()
5960
for field in FILE_FIELDS:
6061
setattr(self, field, metadata.get(field))
@@ -66,7 +67,7 @@ def get_metadata(self, force_refresh=False):
6667
@api_method
6768
def save_original(self, filename):
6869
response = retry_on_too_early(self.api.request,
69-
'%s/files/%s' % (self.api._UPLOAD_BASE_URL, self.file_id),
70+
'%s/files/%s' % (self.api._UPLOAD_BASE_URL, self.file_id),
7071
stream=True)
7172
with open(filename, 'wb') as f:
7273
for chunk in response.iter_content(chunk_size=self.api._CHUNK_SIZE):
@@ -76,11 +77,11 @@ def save_original(self, filename):
7677
def save_analytics(self, filename, output_format='application/json'):
7778
self.wait_for_completion()
7879
response = retry_on_too_early(self.api.request,
79-
'%s/files/%s/analytics' % (self.api._UPLOAD_BASE_URL, self.file_id,),
80+
'%s/files/%s/analytics' % (self.api._UPLOAD_BASE_URL, self.file_id,),
8081
headers=dict(
81-
Accept=output_format,
82-
**self.api.headers
83-
),
82+
Accept=output_format,
83+
**self.api.headers
84+
),
8485
stream=True)
8586
with open(filename, 'wb') as f:
8687
for chunk in response.iter_content(chunk_size=self.api._CHUNK_SIZE):
@@ -90,11 +91,11 @@ def save_analytics(self, filename, output_format='application/json'):
9091
def get_analytics(self, output_format='application/json'):
9192
self.wait_for_completion()
9293
response = retry_on_too_early(self.api.request,
93-
'%s/files/%s/analytics' % (self.api._UPLOAD_BASE_URL, self.file_id,),
94+
'%s/files/%s/analytics' % (self.api._UPLOAD_BASE_URL, self.file_id,),
9495
headers=dict(
95-
Accept=output_format,
96-
**self.api.headers
97-
))
96+
Accept=output_format,
97+
**self.api.headers
98+
))
9899
if output_format == 'application/json':
99100
return response.json()
100101
else:
@@ -104,7 +105,7 @@ def get_analytics(self, output_format='application/json'):
104105
def save_annotated(self, filename):
105106
self.wait_for_completion()
106107
response = retry_on_too_early(self.api.request,
107-
'%s/files/%s/annotated' % (self.api._UPLOAD_BASE_URL, self.file_id),
108+
'%s/files/%s/annotated' % (self.api._UPLOAD_BASE_URL, self.file_id),
108109
stream=True)
109110
with open(filename, 'wb') as f:
110111
for chunk in response.iter_content(chunk_size=self.api._CHUNK_SIZE):
@@ -114,14 +115,14 @@ def save_annotated(self, filename):
114115
def get_annotated(self):
115116
self.wait_for_completion()
116117
response = retry_on_too_early(self.api.request,
117-
'%s/files/%s/annotated' % (self.api._UPLOAD_BASE_URL, self.file_id)
118+
'%s/files/%s/annotated' % (self.api._UPLOAD_BASE_URL, self.file_id)
118119
)
119120
return response.text
120121

121122
@api_method
122123
def delete(self):
123124
response = retry_on_too_early(self.api.request,
124-
'%s/files/%s' % (self.api._UPLOAD_BASE_URL, self.file_id),
125+
'%s/files/%s' % (self.api._UPLOAD_BASE_URL, self.file_id),
125126
method='delete'
126127
)
127128
return response

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
VERSION = '1.0.46'
3+
VERSION = '1.0.47'
44

55
with open('README.rst') as readme_file:
66
readme = readme_file.read()

0 commit comments

Comments
 (0)