Skip to content

Instantly share code, notes, and snippets.

@stevenhair
Created April 29, 2015 20:07
Show Gist options
  • Save stevenhair/a289c389ea854987ae63 to your computer and use it in GitHub Desktop.
Save stevenhair/a289c389ea854987ae63 to your computer and use it in GitHub Desktop.
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