From a201b9f09cc9ac22482cad2a572ff7e4a2d45d7a Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sat, 29 Feb 2020 10:57:05 -0500 Subject: [PATCH] lib/MembershipWorks: Allow getting both CSV and json transactions data --- lib/MembershipWorks.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/MembershipWorks.py b/lib/MembershipWorks.py index 7903468..30537fc 100644 --- a/lib/MembershipWorks.py +++ b/lib/MembershipWorks.py @@ -182,19 +182,25 @@ class MembershipWorks: raise MembershipWorksRemoteError('csv generation', r) return list(csv.DictReader(StringIO(r.text))) - # TODO: doesn't return as much info as csv? - def get_transactions(self, start_date, end_date): + def get_transactions(self, start_date, end_date, json=False): """Get the transactions between start_date and end_date - Dates can be datetime.date or datetime.datetime""" + + Dates can be datetime.date or datetime.datetime + + json gets a different version of the transactions list, + which contains a different set information + """ r = self._get(BASE_URL + "csv", params={'crm': '12,13,14,18,19', # transaction types, see CRM - 'txl': '', # changes output type? - # without this, returns a csv with more info + **({'txl': ''} if json else {}), 'sdp': start_date.strftime('%s'), 'edp': end_date.strftime('%s')}) if r.status_code != 200: raise MembershipWorksRemoteError('csv generation', r) - return r.json() + if json: + return r.json() + else: + return list(csv.DictReader(StringIO(r.text))) def get_all_members(self): """Get all the data for all the members"""