scoremsg.py

来自「用python实现的邮件过滤器」· Python 代码 · 共 48 行

PY
48
字号
#! /usr/bin/env python"""Score a message provided on stdin and show the evidence."""import sysimport emailimport localefrom types import UnicodeTypeimport ZODBfrom ZEO.ClientStorage import ClientStorageimport pspam.databasefrom spambayes.Options import optionsfrom spambayes.tokenizer import tokenizetry:    True, Falseexcept NameError:    # Maintain compatibility with Python 2.2    True, False = 1, 0def main(fp):    charset = locale.getdefaultlocale()[1]    if not charset:        charset = 'us-ascii'    db = pspam.database.open()    r = db.open().root()    p = r["profile"]    msg = email.message_from_file(fp)    prob, evidence = p.classifier.spamprob(tokenize(msg), True)    print "Score:", prob    print    print "Clues"    print "-----"    for clue, prob in evidence:        if isinstance(clue, UnicodeType):            clue = clue.encode(charset, 'replace')        print clue, prob##    print##    print msgif __name__ == "__main__":    main(sys.stdin)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?