Skip to content

Commit 56153a0

Browse files
author
Dario Varotto
committed
Version 1.0.28: dataset.count support
1 parent cc1367d commit 56153a0

File tree

6 files changed

+73
-12
lines changed

6 files changed

+73
-12
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
3+
## v1.0.28 (2019-05-15)
4+
**dataset.count method**
5+
6+
```python
7+
dataset = api.get_dataset('us30')
8+
data_count = ds.count(
9+
start_date='2018-01-05 18:00:00',
10+
end_date='2018-01-05 18:01:00',
11+
)
12+
# {'count': 11, 'stories': 10, 'entities': 6}
13+
14+
```

README.rst

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,19 @@ some time to complete.
117117
Streaming real-time data
118118
~~~~~~~~~~~~~~~~~~~~~~~~
119119

120-
It is possible to subscribe to a real-time stream for a dataset:
120+
It is possible to subscribe to a real-time stream for a dataset.
121121

122-
.. code:: python
122+
Once you create a streaming connection to the real-time feed with your
123+
dataset, you will receive analytics records as soon as they are
124+
published.
123125

124-
ds = api.get_dataset(dataset_id='us500')
125-
for record in ds.request_realtime():
126-
print(record)
127-
print(record.timestamp_utc, record.entity_name,
128-
record['event_relevance'])
126+
It is suggested to handle possible disconnection with a retry policy.
127+
You can find a `real-time streaming example
128+
here <ravenpackapi/examples/get_realtime_news.py>`__.
129129

130-
The Result object takes care of converting the various fields to the
131-
appropriate type, so ``record.timestamp_utc`` will be a ``datetime``
130+
The Result object handles the conversion of various fields into the
131+
appropriate type, i.e. ``record.timestamp_utc`` will be converted to
132+
``datetime``
132133

133134
Entity mapping
134135
~~~~~~~~~~~~~~
@@ -185,3 +186,29 @@ an Entity given the RP\_ENTITY\_ID
185186
for ticker in references.tickers:
186187
if ticker.is_valid():
187188
print(ticker)
189+
190+
Accessing the low-level requests
191+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
192+
193+
RavenPack API wrapper is using the `requests
194+
library <https://2.python-requests.org>`__ to do HTTPS requests, you can
195+
set common requests parameters to all the outbound calls by setting the
196+
``common_request_params`` attribute.
197+
198+
For example, to disable HTTPS certificate verification and to setup your
199+
internal proxy:
200+
201+
.. code:: python
202+
203+
api = RPApi()
204+
api.common_request_params.update(
205+
dict(
206+
proxies={'https': 'http://your_internal_proxy:9999'},
207+
verify=False,
208+
)
209+
)
210+
211+
# use the api to do requests
212+
213+
PS. For setting your internal proxies, requests will honor the
214+
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.constants import JSON_AVAILABLE_FIELDS, ENTITY_TYPES
1515

1616
_VALID_METHODS = ('get', 'post', 'put', 'delete')
17-
VERSION = '1.0.27'
17+
VERSION = '1.0.28'
1818

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

ravenpackapi/examples/query_datafile_rollup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22

33
from ravenpackapi import RPApi, Dataset
4-
from ravenpackapi.models.job import Job
54

65
logging.basicConfig(level=logging.INFO)
76
# initialize the API (here we use the RP_API_KEY in os.environ)

ravenpackapi/models/dataset.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,27 @@ def json(self,
181181
return Results(data['records'],
182182
name='JSON query for %s' % dataset_id)
183183

184+
@api_method
185+
def count(self, start_date, end_date):
186+
""" Get the count of stories, analytics records and entities over a period
187+
"""
188+
api = self.api
189+
dataset_id = self.id
190+
191+
# let's build the body, with all the defined fields
192+
body = {}
193+
for k in JSON_AVAILABLE_FIELDS:
194+
if locals().get(k) is not None:
195+
body[k] = locals().get(k)
196+
197+
response = api.request(
198+
endpoint="/datafile/{dataset_uuid}/count".format(dataset_uuid=dataset_id),
199+
method='post',
200+
data={"start_date": as_datetime_str(start_date),
201+
"end_date": as_datetime_str(end_date)}
202+
)
203+
return response.json()
204+
184205
@api_method
185206
def request_datafile(self, start_date, end_date,
186207
output_format='csv',

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.27'
3+
VERSION = '1.0.28'
44

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

0 commit comments

Comments
 (0)