Skip to content

Commit dc34515

Browse files
author
Dario Varotto
committed
Timezone support for the datafile
Example to copy, modify and save
1 parent 420e396 commit dc34515

File tree

4 files changed

+97
-5
lines changed

4 files changed

+97
-5
lines changed

ravenpackapi/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from ravenpackapi.utils.constants import JSON_AVAILABLE_FIELDS
1414

1515
_VALID_METHODS = ('get', 'post', 'put', 'delete')
16-
VERSION = '1.0.13'
16+
VERSION = '1.0.14'
1717

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
from ravenpackapi import RPApi, Dataset
2+
import logging
3+
4+
logging.basicConfig(level=logging.INFO)
5+
# initialize the API (here we use the RP_API_KEY in os.environ)
6+
api = RPApi()
7+
8+
# get the us30 dataset (its filters contain the top 30 US companies)
9+
us30 = Dataset(api=api, id='us30')
10+
11+
print(us30.filters)
12+
13+
new_filters = {"$and": [
14+
us30.filters,
15+
{"relevance": {
16+
"$gte": 90
17+
}
18+
},
19+
{
20+
"event_similarity_days": {
21+
"$gte": 1
22+
}
23+
}
24+
]}
25+
new_fields = [
26+
{
27+
"daily_average_ess_1d": {
28+
"avg": {
29+
"field": "EVENT_SENTIMENT_SCORE",
30+
"lookback": 1,
31+
"mode": "daily"
32+
}
33+
}
34+
},
35+
{
36+
"daily_average_ess_90d": {
37+
"avg": {
38+
"field": "EVENT_SENTIMENT_SCORE",
39+
"lookback": 90,
40+
"mode": "daily"
41+
}
42+
}
43+
},
44+
{
45+
"buzz": {
46+
"buzz": {
47+
"field": "RP_ENTITY_ID",
48+
"lookback": 2
49+
}
50+
}
51+
},
52+
{
53+
"news_count_1d": {
54+
"count": {
55+
"field": "RP_ENTITY_ID"
56+
}
57+
}
58+
},
59+
{
60+
"average_news_count_90d": {
61+
"avg": {
62+
"field": "news_count_1d",
63+
"lookback": 90
64+
}
65+
}
66+
}
67+
]
68+
custom_dataset = Dataset(api=api,
69+
name="Us30 indicators",
70+
filters=us30.filters,
71+
fields=new_fields,
72+
frequency='daily'
73+
)
74+
custom_dataset.save()
75+
print(custom_dataset)
76+
job = custom_dataset.request_datafile(
77+
start_date='2017-01-01 19:30',
78+
end_date='2017-01-02 19:30',
79+
compressed=True,
80+
time_zone='Europe/London',
81+
)
82+
83+
job.save_to_file('output.csv')

ravenpackapi/models/dataset.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def __init__(self, api=None, **kwargs):
2222
:type api: RPApi
2323
"""
2424
super(Dataset, self).__init__()
25+
if 'id' in kwargs:
26+
kwargs['uuid'] = kwargs.pop('id')
2527
self._data = kwargs
2628
self.api = api
2729
# the dataset can be initialized with just the uuid
@@ -44,16 +46,20 @@ def __setattr__(self, field, value):
4446
if field in Dataset._VALID_FIELDS:
4547
self._data[field] = value
4648
else:
47-
return super(Dataset, self).__setattr__(field, value)
49+
object.__setattr__(self, field, value)
4850

4951
@property
5052
def id(self): # an alias for the dataset unique id
5153
return self.uuid
5254

5355
def __getattr__(self, field):
5456
if field in Dataset._VALID_FIELDS:
55-
if field not in self._data:
57+
if field not in self._data and 'uuid' in self._data:
58+
# get the missing fields
5659
self.get_from_server()
60+
if field == 'uuid' and field not in self._data:
61+
# we can't get the uuid of a new dataset
62+
return None
5763
return self._data[field]
5864
else:
5965
return self.__getattribute__(field)
@@ -148,7 +154,9 @@ def request_datafile(self, start_date, end_date,
148154
compressed=False,
149155
tags=None,
150156
notify=False,
151-
allow_empty=True):
157+
allow_empty=True,
158+
time_zone='UTC'
159+
):
152160
""" Request a datafile with data in the requested date
153161
This is asyncronous: it returns a job that you can wait for
154162
if allow_empty is True, it may return None meaning that the job will have no data
@@ -160,6 +168,7 @@ def request_datafile(self, start_date, end_date,
160168
"format": output_format,
161169
"compressed": compressed,
162170
"notify": notify,
171+
"time_zone": time_zone,
163172
}
164173
if tags:
165174
data['tags'] = tags

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.13'
3+
VERSION = '1.0.14'
44

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

0 commit comments

Comments
 (0)