'Can't get data from ZenMoney API (OAuth2)
I am not good in AOuth2, so I am using ready for work specific library for ZenMoney: https://github.com/Felixoid/python-zenmoney
Here you can see the "simplest way to start":
oauth = OAuth2('ge9e572374ec89f3a1562e4*******', '2d14e80****', '***[email protected]', 'x3bTm***')
api = Request(oauth.token)
diff = api.diff(Diff(**{'serverTimestamp': 1}))
(I have hidden my credentials above)
After that, according to description in library, I can use "diff" to get data from API (https://github.com/zenmoney/ZenPlugins/wiki/ZenMoney-API#principles)
But all that I got is:
diff
> <diff.Diff at 0x171fcfd92e0>
Calling attributes show me the same:
diff.transaction
> [<transaction.Transaction at 0x171fd0fe670>,
<transaction.Transaction at 0x171fd0fe6a0>,
<transaction.Transaction at 0x171fd0fe6d0>,
<transaction.Transaction at 0x171fd0fe700>,
<transaction.Transaction at 0x171fd0fe730>,
<transaction.Transaction at 0x171fd0fe760>,
<transaction.Transaction at 0x171fd0fe790>,
<transaction.Transaction at 0x171fd0fe7c0>,
<transaction.Transaction at 0x171fd0fe7f0>,
<transaction.Transaction at 0x171fd0fe820>,
<transaction.Transaction at 0x171fd0fe850>,
<transaction.Transaction at 0x171fd0fe880>,
<transaction.Transaction at 0x171fd0fe8b0>,
<transaction.Transaction at 0x171fd0fe8e0>,
...
After diving in the code behind the library, I still dont know how to get data in json format or something like this
As I said above, I have never deal with AOuth2, but I was working with REST API, so may be this question can be obvious and I am doing something fundamentally wrong
Solution 1:[1]
You can use this construction for example (get yestarday's transaction):
import sys
from unidecode import unidecode
from datetime import date, timedelta
from zenmoney import *
yesterday=date.today()- timedelta(days=1)
yesterday=yesterday.strftime('%Y-%m-%d')
oauth = OAuth2('xxx', 'xxx', 'xxx', 'xxx')
api = Request(oauth.token)
#diff = api.diff(Diff(**{'serverTimestamp': 0}))
diff = api.diff(Diff(**{'serverTimestamp': 1}))
zen_transaction = ZenObject.to_dict(diff.transaction)
zen_transaction = sorted(zen_transaction, key=lambda k: k['date'])
for item in zen_transaction:
if item['date']==yesterday:
print(item)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sergey Bednyakov |
