def main(): if os.getuid() != 0: print 'You must run this as root. Exiting.' else: args = sys.argv if len(args) == 3: ints = [int(x) for x in args[1:]] set_alarm(ints[0], ints[1]) elif len(args) > 4 and args[3] == '-i': ints = [int(x) for x in args[1:3]] if len(args) == 6: index = args[5] if index.isdigit(): index = int(index) else: print 'Index must be an integer' pass else: index = None query = args[4] info = itunes.searchPlay(query, index=index) if info != None: set_alarm(ints[0], ints[1], info=info, query=query, index=index) else: pass else: print 'Usage: sudo alarm <hour> <minute> [-i <song> [<index>]]\HT\nhour is in 24hr format\n-i optional flag followed by a query to select a song from your itunes library\nIf there is exactly one result from your query, it will be used.\nIf there is more than one, all results will be displayed and you must add an index number at the end of your query indicating which song you chose.\n\nExample: sudo alarm 17 30 -i Rain 2'
def main(args): wakeup_string = args[3] # cancel the wakeup in case there still is try: check_output(['pmset', 'schedule', 'cancel', 'wakeorpoweron', wakeup_string, 'alarm-cli']) except CalledProcessError, e: print e.output # assumes args are exactly as they should be and are valid # TODO: args parsing error query = args[1] index = args[2] if query == '@@@none@@@': query = None if index == '@@@none@@@': index = None else: index = int(index) itunes.searchPlay(query=query, index=index, play=True) if __name__ == "__main__": # always # play_itunes.py query index main(sys.argv)