Created
April 29, 2015 20:07
-
-
Save stevenhair/a289c389ea854987ae63 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 csv | |
import re | |
from glob import glob | |
class alarm_list: | |
def __init__(self): | |
self.alarms = {} | |
self.count = 0 | |
def add_processor(self, proc): | |
self.alarms[proc] = {} | |
def add_alarm(self, proc, tag, msg): | |
self.alarms[proc][tag] = msg | |
self.count += 1 | |
if __name__ == "__main__": | |
alm_list = alarm_list() | |
outfilename = "alarms.xml" | |
# get a list of the csv files | |
file_list = glob("*.csv") | |
for file_name in file_list: | |
# set processor name (assuming filename format <Processor Name>-Tags.CSV) | |
proc = file_name.replace("-Tags.CSV","") | |
alm_list.add_processor(proc) | |
with open(file_name, 'r') as csvfile: | |
reader = csv.reader(csvfile) | |
for row in reader: | |
if row[0] == "TAG" and re.match("^AB_", row[2]): | |
alm_list.add_alarm(proc, row[2], row[3]) | |
for proc, alm in self.alarms.items(): | |
for tag, msg in alm.items(): | |
print("[{}]{}, {}".format(proc, tag, msg)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment