lib/MembershipWorks: Allow getting both CSV and json transactions data

This commit is contained in:
Adam Goldsmith 2020-02-29 10:57:05 -05:00
parent 06516ad0cd
commit a201b9f09c

View File

@ -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"""