Skip to content

Instantly share code, notes, and snippets.

@Tokugero
Created January 7, 2023 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tokugero/0d7bec06d813c05e191eb430dfae59e0 to your computer and use it in GitHub Desktop.
Save Tokugero/0d7bec06d813c05e191eb430dfae59e0 to your computer and use it in GitHub Desktop.
import csv
import re
def main():
moduleData = {}
table = {}
rows = []
title = ""
with open("NFIRS_Spec_Tables_2013.csv", 'r') as spec:
reader = csv.reader(spec)
for row in reader:
if (row[0] == "" and row[1] == "") or ("please note" in row[1].lower()): # Empty line
continue
if row[0] != "" and row[1] != "": # Has useful data
rows.append(row)
if "please note" in row[0].lower(): # Has a reference to another module
continue
if "module; begin" in row[1].lower(): # Has module demarcation
moduleMatch = re.match("[eE]nd(?:\sof\s|\s)(.*) [mM]odule; [bB]egin (.*) [mM]odule", row[1])
moduleData[moduleMatch.group(1).lower()] = table
table = {}
if (row[0] == "" or row[0] == " ") and row[1] != "": # Has title or note
table[title] = rows
title = row[1].lower()
rows = []
print(moduleData["fire"])
for module in moduleData:
for table in moduleData[module]:
print(module, table)
# With data model built, need to replace some references
for module in moduleData:
for table in moduleData[module]:
for row in moduleData[module][table]:
if row[0].lower() == "please note:" and "please see the codes listed" in row[1].lower():
print(row[1])
codeMatch = re.match(".*used for ([\w\s]*)(?:[\s-]).* in the (.*) [mM]odule", row[1])
print(codeMatch.groups())
moduleData[module][table] = moduleData[codeMatch.group(2).lower()][codeMatch.group(1).lower()]
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment