From 8f26264801b9092d7a63d10929be63447dae6717 Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Mon, 18 May 2020 16:18:39 -0400
Subject: [PATCH] Implement file parsing for part 3

---
 main.py | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)

diff --git a/main.py b/main.py
index 614f1ca..053ecdf 100644
--- a/main.py
+++ b/main.py
@@ -19,8 +19,6 @@ def main():
     """
     Program main.
     """
-    logger.info('Starting main()')
-
     calc_part_1()
     calc_part_2()
     calc_part_3()
@@ -273,6 +271,50 @@ def calc_part_3():
     logger.info('=========================')
     logger.info('')
 
+    lib_array = []
+
+    # Open file.
+    with open('./documents/data.libraries.inventories.txt', 'r') as student_scores_file:
+        # Read in each line and save to our struct.
+        for line in student_scores_file:
+            # Split on tabs.
+            split_line = line.strip().split('\t')
+
+            # Loop through all line values.
+            for line_val in split_line:
+
+                # Handle for each major case.
+                if line_val.strip() == 'library':
+                    data_type = 1
+                    index = 0
+                elif line_val.strip() == 'CML':
+                    data_type = 2
+                    index = 0
+                elif line_val.strip() == 'CBL':
+                    data_type = 3
+                    index = 0
+                else:
+                    # Handle general case.
+                    if data_type == 1:
+                        # Is book id.
+                        lib_array.append({
+                            'id': int(line_val.strip().split('_')[1])
+                        })
+                    elif data_type == 2:
+                        # Is CML library data.
+                        lib_array[index]['CML'] = int(line_val.strip())
+                        index += 1
+                    elif data_type == 3:
+                        # Is CBL library data.
+                        lib_array[index]['CBL'] = int(line_val.strip())
+                        index += 1
+
+        logger.info('')
+        logger.info('Lib Array:')
+        for item in lib_array:
+            logger.info('    {0}'.format(item))
+        logger.info('')
+
 
 def calc_part_4():
     """
-- 
GitLab