From e51294bca2acf71927f5b282f156970ab512cad7 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sun, 1 Sep 2019 15:19:23 +0200 Subject: [PATCH] Add option --verbose --- judge_message | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/judge_message b/judge_message index 35d6eb3..bf76950 100755 --- a/judge_message +++ b/judge_message @@ -32,7 +32,7 @@ def add_message(msg): msg.get_payload(decode=True) .decode(charset, errors='replace')) -def extract_features(msgid): +def extract_features(msgid, verbose): db = psycopg2.connect("dbname=bayes") csr = db.cursor(cursor_factory=ppe.DictCursor) csr.execute( @@ -89,7 +89,8 @@ def extract_features(msgid): p1 = 1 p2 = 1 for i in interesting_evidence: - print("#", i["spam_prob"], i["type"], i["length"], i["feature"], sep="\t") + if verbose: + print("#", i["spam_prob"], i["type"], i["length"], i["feature"], sep="\t") csr.execute( "insert into used_evidence(message, spam_prob, type, length, feature) values(%s, %s, %s, %s, %s)", (msg_pk, i["spam_prob"], i["type"], i["length"], i["feature"])) @@ -102,6 +103,7 @@ def extract_features(msgid): def main(): ap = argparse.ArgumentParser() + ap.add_argument('--verbose', action='store_true') ap.add_argument('file', nargs='?') args = ap.parse_args() if args.file: @@ -111,7 +113,7 @@ def main(): parser = email.parser.BytesParser(policy=email.policy.default) msg = parser.parse(fh) add_message(msg) - p = extract_features(msg["Message-Id"]) + p = extract_features(msg["Message-Id"], args.verbose) print(p, "spam" if p > 0.5 else "ham") main()