Skip to content

Commit 964e401

Browse files
committed
Support for additional attributes
1 parent 6d43e94 commit 964e401

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

databox/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def process_kpi(self, **args):
3939
if date is not None:
4040
item['date'] = date
4141

42+
attributes = args.get('attributes', None)
43+
if attributes is not None:
44+
item = dict(item.items() + attributes.items())
45+
4246
return item
4347

4448
def _push_json(self, data=None, path="/"):

example.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,33 @@
99

1010
TOKEN = "adxg1kq5a4g04k0wk0s4wkssow8osw84"
1111

12-
key = 'temp.ljx'
13-
rows = []
14-
15-
for i, day in enumerate([date.today()-timedelta(days=d) for d in range(0, 14)]):
16-
n = 20 + randint(0, 15)
17-
rows.append({'key': key, 'value': n, 'date': day.strftime("%Y-%m-%d")})
18-
19-
if insert_all(rows, token=TOKEN):
20-
print "Inserted", len(rows), "rows."
21-
22-
2312
from databox import Client
2413

25-
client = Client('<access token>')
26-
client.push('sales.total', 1447.0)
27-
client.push('orders.total', 32, date='2015-01-01 09:00:00')
14+
client = Client(TOKEN)
15+
# client.push('sales.total', 1447.0)
16+
#client.push('orders.total', 32, date='2015-01-01 09:00:00')
17+
18+
# key = 'temp.ljx'
19+
# rows = []
20+
#
21+
# for i, day in enumerate([date.today()-timedelta(days=d) for d in range(0, 14)]):
22+
# n = 20 + randint(0, 15)
23+
# rows.append({'key': key, 'value': n, 'date': day.strftime("%Y-%m-%d")})
24+
#
25+
# if insert_all(rows, token=TOKEN):
26+
# print "Inserted", len(rows), "rows."
27+
#
28+
#
2829

29-
print client.last_push()
3030

31-
client.insert_all([
31+
print client.insert_all([
3232
{'key': 'temp.boston', 'value': 51},
3333
{'key': 'temp.boston', 'value': 49, 'date': '2015-01-01 17:00:00'},
34-
{'key': 'sales.total', 'value': 3000},
34+
{'key': 'sales.total', 'value': 3000, 'attributes': {
35+
'name': "Oto",
36+
'price': 199
37+
}},
3538
])
3639

40+
print client.last_push()
3741

38-
39-
from databox import push, insert_all, last_push
40-
push('sales.total', 1448.9, token=TOKEN)
41-
print last_push(TOKEN)

0 commit comments

Comments
 (0)