Skip to content

Instantly share code, notes, and snippets.

@kjmancuso
Last active December 27, 2015 07:09
Show Gist options
  • Save kjmancuso/7286856 to your computer and use it in GitHub Desktop.
Save kjmancuso/7286856 to your computer and use it in GitHub Desktop.
Take Chase alert email, feed it into procmail and then feed it into Prowl.
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
import sys
import email
import html2text
import re
import datetime
import prowler
TIME_FORMAT = '%m/%d %H:%M'
GROWL_KEY = 'APIKEY'
stdin = "".join(sys.stdin).rstrip('=')
message = email.message_from_string(stdin)
plaintext = html2text.html2text(message.get_payload(decode=True))
match1 = plaintext.find('As you requested, we are notifying you of any charges over the amount of') + 142
match2 = plaintext.find('Do not reply') - 4
temp_string = plaintext[match1:match2]
info_charge_amt = temp_string[0:temp_string.find(' at')]
temp_string = re.sub('^.*at\n', '', temp_string)
info_vendor = temp_string[0:temp_string.find('has been authorized')]
temp_string = re.sub('^.*has been authorized on ', '', temp_string)
temp_string = re.sub('E[SD]T.\n', '', temp_string)
try:
info_time = datetime.datetime.strptime(temp_string, '%m/%d/%Y %I:%M:%S %p ')
except:
info_time = temp_string
try:
message = '%s - $%s - %s' % (info_vendor, info_charge_amt, info_time.strftime(TIME_FORMAT))
except AttributeError:
message = '%s - $%s - %s' % (info_vendor, info_charge_amt, info_time)
prowler.post(GROWL_KEY, message, priority=-2, app='Card Alert', event='Charge')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment