<commit_before>#!/usr/bin/env python3

import sched
import time
import configparser
import logging
from email.mime.text import MIMEText
from random import randint
from smtplib import SMTP


def read_subjects(filename):
    file = open(filename)
    result = [line.rstrip() for line in file]
    file.close()
    return result


def random_subject(subjects):
    return subjects[randint(0, len(subjects) - 1)]


def send_mail():
    msg = MIMEText("-kT-", 'plain')
    msg['Subject'] = random_subject(subjects)
    msg['From'] = config['mail']['user']
    msg['To'] = config['mail']['to']

    try:
        conn = SMTP(config['mail']['addr'] + ':' + config['mail']['port'])
        conn.starttls()
        conn.login(config['mail']['user'], config['mail']['pass'])
        try:
            conn.send_message(msg)
        finally:
            conn.quit()
            logging.info("Mail with message '" + msg['Subject'] + "' sent!")
    except Exception as exc:
        logging.error(exc)

    rand_minute = randint(0,30)*60
    logging.info("Next mail in " + str(1800 + rand_minute) + " seconds.")
    s.enter(1800+rand_minute)


subjects = read_subjects('sprueche.txt')
config = configparser.ConfigParser()
config.read("mail.conf")
logging.basicConfig(format='%(levelname)s: %(message)s', level=getattr(logging, config['log']['level'].upper(), None))
logging.debug("Read subjects.")
logging.debug("Read config")


s = sched.scheduler()
s.enter(2, 0, send_mail)
s.run()
logging.debug("Started scheduler.")
<commit_msg>bugfix<commit_after>#!/usr/bin/env python3

import sched
import time
import configparser
import logging
from email.mime.text import MIMEText
from random import randint
from smtplib import SMTP


def read_subjects(filename):
    file = open(filename)
    result = [line.rstrip() for line in file]
    file.close()
    return result


def random_subject(subjects):
    return subjects[randint(0, len(subjects) - 1)]


def send_mail():
    msg = MIMEText("-kT-", 'plain')
    msg['Subject'] = random_subject(subjects)
    msg['From'] = config['mail']['user']
    msg['To'] = config['mail']['to']

    try:
        conn = SMTP(config['mail']['addr'] + ':' + config['mail']['port'])
        conn.starttls()
        conn.login(config['mail']['user'], config['mail']['pass'])
        try:
            conn.send_message(msg)
        finally:
            conn.quit()
            logging.info("Mail with message '" + msg['Subject'] + "' sent!")
    except Exception as exc:
        logging.error(exc)

    rand_minute = randint(0,30)*60
    logging.info("Next mail in " + str(1800 + rand_minute) + " seconds.")
    s.enter(1800+rand_minute, 0, send_mail)


subjects = read_subjects('sprueche.txt')
config = configparser.ConfigParser()
config.read("mail.conf")
logging.basicConfig(format='%(levelname)s: %(message)s', level=getattr(logging, config['log']['level'].upper(), None))
logging.debug("Read subjects.")
logging.debug("Read config")


s = sched.scheduler()
s.enter(2, 0, send_mail)
s.run()
logging.debug("Started scheduler.")

{'fraction_non_alphanumeric': 0.16847647252385653, 'fraction_numerical': 0.01217505758473182, 'mean_word_length': 3.8177496038034864, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2830138', 'n_tokens_mistral': 999, 'n_tokens_neox': 965, 'n_words': 210}