def changeConfig(data): target = data.get('target', None) database = data.get('database', None) host = data.get('host', None) user = data.get('user', None) password = data.get('password', None) filename = data.get('filename', 'target') fp = "{}/conf/server.conf".format(base_dir) conf = json.loads(slurp(fp)) if os.path.isfile(fp) else {} zargs= zip(['target','database','host','user','password'], [target, database, host, user, password ]) args_map = {x:y for x,y in filter(lambda o: o[1], zargs)} config = dict(conf, **args_map) out = json.dumps(config, sort_keys=True, indent=4, separators=(',', ': ')) spit(fp, out, True) spit('{}/conf/{}.cfg'.format(base_dir, filename), 'EMAIL_TARGET="{}"\n'.format(config["target"]), True) tangelo.content_type("application/json") return { 'target' : config["target"], 'config' : filename + ".cfg" }
def changeConfig(data): target = data.get('target', None) database = data.get('database', None) host = data.get('host', None) user = data.get('user', None) password = data.get('password', None) filename = data.get('filename', 'target') fp = "{}/conf/server.conf".format(base_dir) conf = json.loads(slurp(fp)) if os.path.isfile(fp) else {} zargs = zip(['target', 'database', 'host', 'user', 'password'], [target, database, host, user, password]) args_map = {x: y for x, y in filter(lambda o: o[1], zargs)} config = dict(conf, **args_map) out = json.dumps(config, sort_keys=True, indent=4, separators=(',', ': ')) spit(fp, out, True) spit('{}/conf/{}.cfg'.format(base_dir, filename), 'EMAIL_TARGET="{}"\n'.format(config["target"]), True) tangelo.content_type("application/json") return {'target': config["target"], 'config': filename + ".cfg"}
def getIngestLog(*args): job_id = nth(args, 0) logfile = "{}/{}.tee.log".format(work_dir, job_id) sz = slurp(logfile) tangelo.content_type("application/json") return {'log': sz}
def getState(*args): email_addr = nth(args, 0) logfile = "{}/{}.log".format(work_dir, email_addr) sz = slurp(logfile) tangelo.content_type("application/json") return {'log': sz}
formatter_class=argparse.RawDescriptionHelpFormatter, epilog=desc) parser.add_argument("-a","--header", action='store_true', help="add header to output") parser.add_argument("-s","--start", type=int, default=0, help="start at line #") parser.add_argument("-l", "--limit", type=int, default=0, help="end at line #") parser.add_argument("target_email", help="Target Email") parser.add_argument("out_dir", help="Output Directory") parser.add_argument("infile", nargs='?', type=argparse.FileType('r'), default=sys.stdin, help="Input File") args = parser.parse_args() outfile = "{}/output.csv".format(args.out_dir) mkdirp("{}/emails".format(args.out_dir)) if args.header: spit(outfile, email_extract.headerrow() + "\n") for i, line in enumerate(skip(args.infile, at_start=args.start)): if ((not args.limit == 0) and (i >= args.limit)): break; try: fp = line.strip() guid = email_extract.md5(fp) category = email_extract.categoryList(fp) buff = slurp(fp) row = email_extract.extract(guid, buff, args.out_dir, category, args.target_email) spit(outfile, row + "\n") except Exception as e: print "exception line: {} | {} ".format(i, e.message) if i % 100 == 0: prn("completed line: {}".format(i + args.start))
cat input_file.tsv | ./printview.py ''' parser = argparse.ArgumentParser( description="printview", formatter_class=argparse.RawDescriptionHelpFormatter, epilog=desc) parser.add_argument("target", help="target email") parser.add_argument("tmpl", help="path to template file") parser.add_argument("infile", nargs='?', type=argparse.FileType('r'), default=sys.stdin, help="Input File") args = parser.parse_args() T = Template(slurp(args.tmpl)) def split(x, c): a = x.split(c) if x else '' return a if a else [] def formatName(n): a = n.split() if n else [] return ' '.join(a[:5]) def formatScore(s): x = float(s) * 100 return "{:10.2f}%".format(x) def getTopics(_id): with newman_connector() as cnx:
parser.add_argument("target_email", help="Target Email") parser.add_argument("out_dir", help="Output Directory") parser.add_argument("infile", nargs='?', type=argparse.FileType('r'), default=sys.stdin, help="Input File") args = parser.parse_args() outfile = "{}/output.csv".format(args.out_dir) mkdirp("{}/emails".format(args.out_dir)) if args.header: spit(outfile, email_extract.headerrow() + "\n") for i, line in enumerate(skip(args.infile, at_start=args.start)): if ((not args.limit == 0) and (i >= args.limit)): break try: fp = line.strip() guid = email_extract.md5(fp) category = email_extract.categoryList(fp) buff = slurp(fp) row = email_extract.extract(guid, buff, args.out_dir, category, args.target_email) spit(outfile, row + "\n") except Exception as e: print "exception line: {} | {} ".format(i, e.message) if i % 100 == 0: prn("completed line: {}".format(i + args.start))
if __name__ == "__main__": desc = ''' examples: cat input_file.tsv | ./printview.py ''' parser = argparse.ArgumentParser( description="printview", formatter_class=argparse.RawDescriptionHelpFormatter, epilog=desc) parser.add_argument("target", help="target email") parser.add_argument("tmpl", help="path to template file") parser.add_argument("infile", nargs='?', type=argparse.FileType('r'), default=sys.stdin, help="Input File") args = parser.parse_args() T = Template(slurp(args.tmpl)) def split(x, c): a= x.split(c) if x else '' return a if a else [] def formatName(n): a = n.split() if n else [] return ' '.join(a[:5]) def formatScore(s): x = float(s) * 100 return "{:10.2f}%".format(x) def getTopics(_id): with newman_connector() as cnx:
msg = clean_string(msg, [EXPR_OPTS['fix_utf8']]) spit("{}/{}.txt".format(_dir, email_id), msg) row= createRow(email_id, "emails/{}".format(email_id), target_email, mail, categories, attach, msg) return row if __name__ == "__main__": desc = ''' examples: cat email.eml | ./this.py ''' parser = argparse.ArgumentParser( description=" ... ", formatter_class=argparse.RawDescriptionHelpFormatter, epilog=desc) parser.add_argument("target_email", help="target email") parser.add_argument("outdir", help="Out Dir") parser.add_argument("file_path", help="File Path") #parser.add_argument("infile", nargs='?', type=argparse.FileType('r'), default=sys.stdin, help="Input File") args = parser.parse_args() guid = md5(args.file_path) category = categoryList(args.file_path) buff = slurp(args.file_path) row = extract(guid, buff, args.outdir, category, args.target_email) print row
msg = clean_string(msg, [EXPR_OPTS['fix_utf8']]) spit("{}/{}.txt".format(_dir, email_id), msg) row = createRow(email_id, "emails/{}".format(email_id), target_email, mail, categories, attach, msg) return row if __name__ == "__main__": desc = ''' examples: cat email.eml | ./this.py ''' parser = argparse.ArgumentParser( description=" ... ", formatter_class=argparse.RawDescriptionHelpFormatter, epilog=desc) parser.add_argument("target_email", help="target email") parser.add_argument("outdir", help="Out Dir") parser.add_argument("file_path", help="File Path") #parser.add_argument("infile", nargs='?', type=argparse.FileType('r'), default=sys.stdin, help="Input File") args = parser.parse_args() guid = md5(args.file_path) category = categoryList(args.file_path) buff = slurp(args.file_path) row = extract(guid, buff, args.outdir, category, args.target_email) print row
def getIngestLog(*args): job_id = nth(args, 0) logfile = "{}/{}.tee.log".format(work_dir, job_id) sz = slurp(logfile) tangelo.content_type("application/json") return {'log' : sz }
def getState(*args): email_addr = nth(args, 0) logfile = "{}/{}.log".format(work_dir, email_addr) sz = slurp(logfile) tangelo.content_type("application/json") return {'log' : sz }