def check_election(county, date): date_parsed = datetime.strptime(date, '%Y%m%d').replace(hour=12) if date_parsed > now: # Parse the output of `atq`: # The output consists of `jobid date queue user`, but date has # lots of whitespace, so we split, throw away the ends, and join # it again. jobs = [' '.join(bits.split()[1:-2]) for bits in sh.atq().split('\n') if bits] for job in jobs: if datetime.strptime(job, '%a %b %d %H:%M:%S %Y') == date_parsed: # Job already exists break else: print("There's a new election coming up in {} at {}!".format(county, date_parsed)) sh.at('-t', '{}1200'.format(date), _in="{} election.py -l".format(sys.executable))
def schedule(self, nminutes, eg, options): fileurl = "{}/{}".format(self.PREFIX, uuid.uuid4()) egauge_config.write_url((eg, options), fileurl, use_pickle=True) cmd_file = "{}/{}".format(self.PREFIX, uuid.uuid4()) with open(cmd_file, "wt") as fl: fl.write( schedule_script.format(eg.devurl.netloc, os.path.realpath(__file__).replace(".pyc", ".py"), fileurl) ) print "bash {}".format(cmd_file) if self.SCHED is True: # write command to a file from sh import at at("-f", cmd_file, "now+{}minutes".format(nminutes))
def _remove_from_picklist_in_future(self, ticker, hours): """Use the system 'at' command to run 'unpick' at a future time.""" job_id = None script = os.path.abspath(__file__) cmd = '{} unpick {}'.format(script, ticker) when = 'now + {} hours'.format(hours) for line in at(when, _in=cmd, _iter=True, _err_to_out=True): if job_id is None and 'job' in line: words = line.split() job_id = int(words[words.index('job') + 1]) # next word after 'job' return job_id
def args_process_show(in_args): global g_conn password_name = str(in_args.__getattribute__("pass-name")) if not store_password_exists(password_name): stderr_out("Error: %s is not in the password store.\n" % password_name) else: def _str(val): return val if val is not None else "" if in_args.history: op_cnt = int( sqlite_get_one_value( """SELECT count(*) FROM passwords WHERE password_name = ? AND group_id = 1""", [password_name])) if op_cnt > 1: print("Decrypting passwords...") table = PrettyTable( ["Current", "Password", "Created at", "Login", "Description"]) console_progress_bar(0, op_cnt) for rec in enumerate(g_conn.execute( """SELECT deleted_bool, created_at, login, description, encrypted_value FROM passwords WHERE password_name = ? AND group_id = 1 ORDER BY password_id DESC""", [password_name]), start=1): row = rec[1] table.add_row([ "[x]" if row[0] == 0 else "", gpg_decrypt(row[4]), _str(row[1]), _str(row[2]), _str(row[3]) ]) console_progress_bar(rec[0], op_cnt) print(table) elif in_args.full: table = PrettyTable( ["Password", "Created at", "Login", "Description"]) for row in g_conn.execute( """SELECT created_at, login, description, encrypted_value FROM passwords WHERE password_name = ? AND deleted_bool = 0 AND group_id = 1""", [password_name]): table.add_row([ gpg_decrypt(row[3]), _str(row[0]), _str(row[1]), _str(row[2]) ]) print(table) else: decrypted_password = store_get_password(password_name) if in_args.clip: p = subprocess.Popen(["xclip", "-d", ":0", "-selection", "c"], stdin=subprocess.PIPE, close_fds=True) p.communicate(input=decrypted_password.encode("utf-8")) exec_at = str(date("+%Y%m%d%H%M.%S", date="now +45 seconds")).strip("\n") at(printf("printf '' | xclip -d :0 -selection c"), "-t", exec_at) print("Copied %s to clipboard. Will clear in 45 seconds." % password_name) else: print(decrypted_password)