matteospanio / spam-analyzer

A program to detect spam https://pypi.org/project/spam-analyzer/
http://docs.spamanalyzer.tech/
GNU General Public License v3.0
3 stars 0 forks source link

Cant find config.yaml, word_blacklist.txt or classifier.pkl #17

Closed NeaMitika closed 1 year ago

NeaMitika commented 1 year ago

Describe the bug

Traceback (most recent call last):
  File "c:\Users\Luciano M\Desktop\Python\Sys-Admin-Tools\spam_analyzer\prove_spam_analyzer2.py", line 12, in <module>
    if spam_analysis.is_spam():
  File "C:\Users\Luciano M\AppData\Local\Programs\Python\Python310\lib\site-packages\spamanalyzer\analyzer\data_structures.py", line 156, in is_spam
    with open(CONFIG_FILE, 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Luciano M\\.config\\spamanalyzer\\config.yaml'

To Reproduce Run this script:

from spamanalyzer import *
import email

# Crea un'istanza di MailAnalyzer.
mail_analyzer = MailAnalyzer(wordlist="spam_analyzer/word_blacklist.txt")

# Analizza il file EML.
spam_analysis = mail_analyzer.analyze(email_path="spam_analyzer/email2.eml")

# Stampa il risultato dell'analisi.
if spam_analysis.is_spam():
  print("Il file EML è spam.")
else:
  print("Il file EML non è spam.")

Expected behavior

It should print:

Il file EML è spam. OR Il file EML non è spam.

Desktop (please complete the following information): Edizione Windows 10 Enterprise Versione 22H2 Data installazione: ‎08/‎07/‎2023 Build sistema operativo 19045.3208 Esperienza Windows Feature Experience Pack 1000.19041.1000.0

Python Version Python 3.10.6

Additional context

The onlyway to make it work i had to manualy create the directory: C:\Users\Luciano M\.config\spamanalyzer and place inside the files: word_blacklist.txt, classifier.pkl, config.yaml. Then change the content of the config.yaml to:

# constants values used across the app
files:
  # absolute path to the spam words file
  # wordlist source: https://gist.github.com/prasidhda/13c9303be3cbc4228585a7f1a06040a3
  wordlist: 'C:\Users\Luciano M\.config\spamanalyzer\word_blacklist.txt'
  classifier: 'C:\Users\Luciano M\.config\spamanalyzer\classifier.pkl'
matteospanio commented 1 year ago

The library was not able to create correctly config files if imported as a python module, this PR fixes this bug. Please use the updated version to see the correct behavior. Since the bug has been solved I'm closing this issue, feel free to reopen it if the bug persists.

NeaMitika commented 1 year ago

It's fixed, thank you for the ultra fast response.