Skip to content

Commit

Permalink
Merge pull request #1 from aneisch/dev
Browse files Browse the repository at this point in the history
Fix master
  • Loading branch information
aneisch committed Feb 15, 2020
2 parents 53d254f + 11f327a commit 32782c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Retrieves USPS mail and package info from informed delivery emails via IMAP. Pub
* https://www.awesome-automations.com/blog/usps/
* https://community.home-assistant.io/t/a-working-usps-component-solved-for-now/41012/14

https://hub.docker.com/r/aneisch/informed-delivery-home-assistant

## Usage

Expand Down
18 changes: 7 additions & 11 deletions retrieve_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ def get_mails(account):
'(FROM "USPS" SUBJECT "Informed Delivery Daily Digest" SINCE "' +
today + '")')
if rv == 'OK':

message_count = len(str(data[0]).split(" "))
print_message('Found {} Informed Delivery messages'.format(message_count))
message_count = len(str(data[0]).split(" ")) - 1
print_message("Found {} Informed Delivery messages".format(message_count))

for num in data[0].split():
rv, data = account.fetch(num, '(RFC822)')
Expand All @@ -75,7 +74,7 @@ def get_mails(account):
if part.get('Content-Disposition') is None:
continue
if '_' in part.get_filename():
print_message('Found an advertisement, skipping it!')
print_message("Found an advertisement, skipping it!")
continue

filepath = '/output/' + part.get_filename()
Expand All @@ -85,7 +84,7 @@ def get_mails(account):
image_count = image_count + 1
fp.close()

print_message ('Found {} mails and images in your email.'.format(image_count))
print_message ("Found {} mails and images in your email".format(image_count))

if image_count > 0:
all_images = ""
Expand All @@ -94,15 +93,15 @@ def get_mails(account):
all_images += image + " "

print_message ("Creating animated GIF out of {} images.".format(image_count))
os.system( GIF_MAKER_OPTIONS + all_images +
os.system( GIF_MAKER_OPTIONS + " " + all_images +
'/output/' + GIF_FILE_NAME )

print_message ("Cleaning up...")
for image in images:
os.remove(image)

if (image_count == 0):
print_message("Found '{}' mails".format(image_count))
print_message("Found {} mails".format(image_count))

return image_count

Expand All @@ -124,7 +123,7 @@ def package_count(account):
if rv == 'OK':
count = len(data[0].split())

print_message("Found '{}' packages".format(count))
print_message("Found {} packages".format(count))

return count

Expand Down Expand Up @@ -157,9 +156,6 @@ def on_log(mosq, obj, level, string):
# Set event callbacks
mqttc.on_connect = on_connect

# Uncomment below line to enable debug/console messages
# mqttc.on_log = on_log

# Connect to MQTT using the username/password set above
mqttc.username_pw_set(MQTT_USERNAME, MQTT_PASSWORD)
mqttc.connect(MQTT_SERVER, MQTT_SERVER_PORT)
Expand Down

0 comments on commit 32782c7

Please sign in to comment.