cleanup python
authorgamesguru <mathmuncher11@gmail.com>
Sat, 22 May 2021 00:03:17 +0000 (20:03 -0400)
committergamesguru <mathmuncher11@gmail.com>
Sat, 22 May 2021 00:03:17 +0000 (20:03 -0400)
build.py
sql/__init__.py

index 1a4c548aca2ae7f57a6204c4c489ab47d3c312e3..07045ae85310307c322c362ce56e08f71273bb6c 100755 (executable)
--- a/build.py
+++ b/build.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python3
-
+"""Executable script for building nt.sqlite"""
 
 if __name__ == "__main__":
     from sql import build_ntsqlite
index 7c6633bb7556648a1bb26d9477f5320f1532adcf..34ccd06b5a206d6880045fa1e9eaec80b3e1e6a2 100644 (file)
@@ -1,14 +1,17 @@
 #!/usr/bin/env python3
+"""Main module for building nt.sqlite"""
+
 import csv
 import os
 import sqlite3
 
 NT_DB_NAME = "nt.sqlite"
+SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
 
 
 def build_ntsqlite(verbose=False):
+    """Builds and inserts stock data into nt.sqlite"""
     # cd into this script's directory
-    SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
     os.chdir(SCRIPT_DIR)
 
     if verbose:
@@ -28,18 +31,18 @@ def build_ntsqlite(verbose=False):
 
     if verbose:
         print("-> Populate data")
-    for p in os.listdir("data"):
-        if not p.endswith(".csv"):
+    for file_path in os.listdir("data"):
+        if not file_path.endswith(".csv"):
             continue
-        t = os.path.splitext(os.path.basename(p))[0]
-        p = os.path.join("data", p)
+        table_name = os.path.splitext(os.path.basename(file_path))[0]
+        file_path_full = os.path.join("data", file_path)
 
         # Loop over CSV files
-        with open(p) as f:
-            reader = csv.DictReader(f)
-            q = ",".join("?" * len(reader.fieldnames))
-            reader = csv.reader(f)
-            cur.executemany(f"INSERT INTO {t} VALUES ({q});", reader)
+        with open(file_path_full) as csv_file:
+            reader = csv.DictReader(csv_file)
+            values = ",".join("?" * len(reader.fieldnames))
+            reader = csv.reader(csv_file)
+            cur.executemany(f"INSERT INTO {table_name} VALUES ({values});", reader)
 
     cur.close()
     con.commit()