读取csv文件并根据配置文件检查其内容

时间:2014-12-17 21:11:31

标签: python csv config

我正在上传一个csv文件,其中包含我需要检查正确拼写/或缺少项目的操作和对象。我创建了一个配置文件,其中包含应该在csv文件中的对象和操作。我在我的代码中创建了一个指向配置文件的配置解析器。如何获取配置文件以检查csv然后记录错误。以下是我到目前为止的情况:

#!usr/bin/python


from subprocess import *
import sys
import ConfigParser
import os
import csv
import getopt
import time
import datetime
from datetime import date
from time import gmtime, strftime
import logging
from sys import argv
script, solution_id, input_file = argv

#creating time stamp and returning as a string to add to solution id log name
def timeIzNow():  
    full = time.strftime(" %Y-%m-%d %H:%M:%S")

    return full

#set up logging to file
LOG_FILENAME = solution_id  + timeIzNow() 
logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s %(process)d',
                    datefmt='%d %b %Y %H:%M:%S', 
                    filename=LOG_FILENAME,
              filemode='w')   
# defining a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(logging.INFO)
# setting a format which is simpler for console use
formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
# telling the handler to use this format
console.setFormatter(formatter)
# adding the handler to the root logger
logging.getLogger('').addHandler(console)

#set up configuration Parser
config = ConfigParser.RawConfigParser()
config.read('/etc/nagios/ingestion/objectItems.cfg')
config.read('/etc/nagios/ingestion/action.cfg')

#set up configuration Parser to get objects and check the csv file for matches
objects = config.get('Objects', 'objects')

#get actions
actions = config.get('Actions', 'actions')

0 个答案:

没有答案