Created
December 8, 2016 16:16
-
-
Save wolendranh/bb42fd2ad858bff7c230283d535bebd8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ConfigParser | |
import ast | |
import os | |
import logging | |
from django.core.management import BaseCommand | |
from models import BannedMails | |
class Config(object): | |
def get_value_confing(self, section, key): | |
configParser = ConfigParser.RawConfigParser() | |
configFilePath = r'/root/repmailspam/mail_log_analyzer/mail.conf' | |
configParser.read(configFilePath) | |
value = configParser.get(section, key) | |
return value | |
def get_dict_config(self, section, key): | |
return ast.literal_eval(self.get_value_confing(section, key)) | |
def get_list_config(self, section, key): | |
return [val.strip() for val in self.get_value_confing(section, key).split(',')] | |
class ParceSyslogFile(Config): | |
def __init__(self): | |
self.path_mail_log = self.get_value_confing('general', 'path_mail_log') | |
def test(self): | |
with open(self.path_mail_log, 'r')as f: | |
data = f.read() | |
for line in data.split('\n'): | |
print repr(line) | |
class Command(BaseCommand): | |
help = 'Some script' | |
def get_logger(self): | |
return logging.getLogger(__name__) | |
def run(self, *args, **options): | |
p = ParceSyslogFile() | |
p.test() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment