@@ -214,71 +214,3 @@ def glance(self, user, **kwargs):
214214 payload [key ] = value
215215
216216 return Request ("post" , GLANCE_URL , payload )
217-
218- def main ():
219- from ConfigParser import RawConfigParser , NoSectionError , NoOptionError
220- from argparse import ArgumentParser , RawDescriptionHelpFormatter
221- import os
222-
223- def read_config (config_path ):
224- config_path = os .path .expanduser (config_path )
225- config = RawConfigParser ()
226- params = {"users" : {}}
227- files = config .read (config_path )
228- if not files :
229- return params
230- params ["token" ] = config .get ("main" , "token" )
231- for name in config .sections ():
232- if name != "main" :
233- user = {}
234- user ["user_key" ] = config .get (name , "user_key" )
235- try :
236- user ["device" ] = config .get (name , "device" )
237- except NoOptionError :
238- user ["device" ] = None
239- params ["users" ][name ] = user
240- return params
241-
242- parser = ArgumentParser (description = "Send a message to pushover." ,
243- formatter_class = RawDescriptionHelpFormatter ,
244- epilog = """
245- For more details and bug reports, see: https://github.com/Thibauth/python-pushover""" )
246- parser .add_argument ("--token" , help = "API token" )
247- parser .add_argument ("--user" , "-u" , help = "User key or section name in the configuration" , required = True )
248- parser .add_argument ("-c" , "--config" , help = "configuration file\
249- (default: ~/.pushoverrc)" , default = "~/.pushoverrc" )
250- parser .add_argument ("message" , help = "message to send" )
251- parser .add_argument ("--url" , help = "additional url" )
252- parser .add_argument ("--url-title" , help = "url title" )
253- parser .add_argument ("--title" , "-t" , help = "message title" )
254- parser .add_argument ("--priority" , "-p" , help = "notification priority (-1, 0, 1 or 2)" , type = int )
255- parser .add_argument ("--retry" , "-r" , help = "resend interval in seconds (required for priority 2)" , type = int )
256- parser .add_argument ("--expire" , "-e" , help = "expiration time in seconds (required for priority 2)" , type = int )
257- parser .add_argument ("--version" , "-v" , action = "version" ,
258- help = "output version information and exit" ,
259- version = """
260- %(prog)s 1.0
261- Copyright (C) 2013-2018 Thibaut Horel <thibaut.horel@gmail.com>
262- License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
263- This is free software: you are free to change and redistribute it.
264- There is NO WARRANTY, to the extent permitted by law.""" )
265-
266- args = parser .parse_args ()
267- params = read_config (args .config )
268- if args .priority == 2 and (args .retry is None or args .expire is None ):
269- parser .error ("priority of 2 requires expire and retry" )
270- if args .user in params ["users" ]:
271- user_key = params ["users" ][args .user ]["user_key" ]
272- device = params ["users" ][args .user ]["device" ]
273- else :
274- user_key = args .user
275- device = None
276- token = args .token or params ["token" ]
277-
278- Pushover (token ).message (user_key , args .message , device = device ,
279- title = args .title , priority = args .priority , url = args .url ,
280- url_title = args .url_title , timestamp = True , retry = args .retry ,
281- expire = args .expire )
282-
283- if __name__ == "__main__" :
284- main ()
0 commit comments