Feature: Added feed option to see recent transactions#56
Feature: Added feed option to see recent transactions#56cmilhaupt wants to merge 2 commits intozackhsi:masterfrom
Conversation
zackhsi
left a comment
There was a problem hiding this comment.
Thanks for the contribution, this is a neat feature!
I left a few comments, let me know if I can clarify anything.
Cheers.
| response = venmo.singletons.session().get(venmo.settings.PROFILE_URL) | ||
| return response.json()['data']['user']['id'] | ||
|
|
||
| def feed(limit=10): |
There was a problem hiding this comment.
Could you factor this out into two functions, one for data (feed) and one for presentation (print_feed)? The data function can be used when this library is imported, and the presentation function will be used for the CLI.
There was a problem hiding this comment.
This is the only one I'm not understanding. I can change the function argument to print_feed, but how do I call feed when the library is imported? Also how do you want to handle limit then? Cache n responses on load and query for more if limit > n?
There was a problem hiding this comment.
End the feed function on L54 with return response_dict['data']. This can be invoked when the library is imported.
Separately, create a print_feed function that calls feed then continues with the rest of the current feed function, the part that deals with presentation.
limit would be an argument on both feed and print_feed.
No need to deal with caching.
| def feed(limit=10): | ||
| venmo.auth.ensure_access_token() | ||
| user_id = get_profile_id() | ||
| response = venmo.singletons.session().get(venmo.settings.FEED_URL + user_id + "?limit=" + str(limit)) |
There was a problem hiding this comment.
The limit=limit part of the URL can be created with the params argument.
| d['date_created'].split('T')[0]) | ||
| else: | ||
| print(" " + d['payment']['actor']['display_name'] + " paid you $" + | ||
| str(d['payment']['amount']) + " on " + |
There was a problem hiding this comment.
Format the string for two decimal places. The locale module may serve nicely.
| if d['type'] == 'transfer': | ||
| print(" Transfered $" + str(d['transfer']['amount']) + " to '" + | ||
| d['transfer']['destination']['name'] + "' on " + | ||
| d['transfer']['date_requested'].split('T')[0]) |
There was a problem hiding this comment.
This will be more resilient if we parse and format the dates. datetime.datetime.parse with %Y-%m-%dT%H:%M:%S should work.
>>> from datetime import datetime
>>> datetime.strptime('2015-05-07T19:30:56', '%Y-%m-%dT%H:%M:%S')
datetime.datetime(2015, 5, 7, 19, 30, 56)
No description provided.