diff --git a/pushover.py b/pushover.py index f539992..8a4dffb 100755 --- a/pushover.py +++ b/pushover.py @@ -4,6 +4,12 @@ import argparse import requests +def optional_int(value): + """Convert string to int, treating empty strings as None""" + if value == '': + return None + return int(value) + def get_args(): parser = argparse.ArgumentParser() parser.add_argument('--message', type=str, help='Message text') @@ -11,7 +17,7 @@ def get_args(): parser.add_argument('--url', type=str, help='Supplementary URL to show with your message') parser.add_argument('--url_title', type=str, help='title for your supplementary URL, otherwise just the URL is shown') parser.add_argument('--device', type=str, help='Device name to send the message directly to') - parser.add_argument('--priority', type=int, help='Notification priority (low-to-high: -2 to 1)') + parser.add_argument('--priority', type=optional_int, help='Notification priority (low-to-high: -2 to 1)') parser.add_argument('--sound', type=str, help='The name of a supported sound (https://pushover.net/api#sounds; custom sounds are supported)') args = parser.parse_args() return args @@ -48,7 +54,7 @@ def main(): if device: payload['device'] = device if priority: - payload['priority'] = priority + payload['priority'] = str(priority) if sound: payload['sound'] = sound