Last active
September 5, 2019 10:32
-
-
Save nicholas-gh/082c51de8b3dd8a55b08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Print a count of how many receipts were filed for each month | |
# put in receiptbank.ini | |
""" | |
[credentials] | |
login = email@example.com | |
password = yourpassword | |
""" | |
import requests | |
import datetime | |
from collections import Counter | |
import ConfigParser | |
count = Counter() | |
first_day_of_current_month = datetime.date.today().replace(day=1) | |
last_day_of_previous_month = first_day_of_current_month - datetime.timedelta(days=1) | |
first_day_of_previous_month = last_day_of_previous_month.replace(day=1) | |
config = ConfigParser.ConfigParser() | |
config.read("receiptbank.ini") | |
sessionid = requests.get("https://app.receipt-bank.com/api/login", | |
params = dict(config.items('credentials'))).json()['sessionid'] | |
# doesn't seem to be an API call for searching, so get all the records | |
r = requests.get("https://app.receipt-bank.com/api/receipts", | |
params = {'sessionid': sessionid}) | |
# doesn't seem to be a value for 'submitted date', so use the | |
# receipt-transaction-date | |
for receipt in r.json()['receipts']: | |
try: | |
receipt_date = datetime.datetime.strptime(receipt['date'], "%Y-%m-%d").date() | |
except ValueError, e: | |
print receipt, e | |
continue | |
count[(receipt_date.year, receipt_date.month)] += 1 | |
for date in sorted(count): | |
print "{1:04} {2:02}: {0:4}".format(count[date], *date) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment