3 Achegas 421efc759b ... b51b2a53ac

Autor SHA1 Mensaxe Data
  Joshua b51b2a53ac Merge branch 'develop' of https://git.tk.informatik.tu-darmstadt.de/leon.boeck/ID2T-toolkit-BotnetTraffic into develop %!s(int64=6) %!d(string=hai) anos
  Joshua 4668eeacd1 CSV parser commented %!s(int64=6) %!d(string=hai) anos
  Joshua c8c3c9bc90 test %!s(int64=6) %!d(string=hai) anos
Modificáronse 1 ficheiros con 27 adicións e 0 borrados
  1. 27 0
      code/Iteration1/CSVParser.py

+ 27 - 0
code/Iteration1/CSVParser.py

@@ -0,0 +1,27 @@
+import xml.etree.ElementTree as ET
+import csv
+
+# def parseCSV:
+
+def parse_csv(file: str):
+	# build a tree structure
+	root = ET.Element("mmcommunication")
+
+	# parse the csvFile into reader
+	with open(file) as csvFile:
+	    reader = csv.reader(csvFile, delimiter=",")
+		# loop through the parsed file, creating packet-elements with the structure of the csvFile as attributes
+	    for line in reader:
+	        packet = ET.SubElement(root, "packet")
+	        for element in line:
+	        	element = element.replace(" ", "")
+	        	splitel = element.split(":")
+	        	key, value = splitel[0], splitel[1]
+		        packet.attrib[key] = value
+
+	# writing the ElementTree into the .xml file
+	tree = ET.ElementTree(root)
+	tree.write("ExampleCSVBotnetCommunication.xml")
+
+
+parse_csv("ExampleCSVBotnetCommunication.txt")