Skip to content

Commit

Permalink
tidy python
Browse files Browse the repository at this point in the history
  • Loading branch information
gamesguru committed Jan 14, 2024
1 parent a999741 commit d63f00b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def build_db(verbose: bool = False) -> bool:
os.remove(OUTPUT_DB_NAME)

if verbose:
# pylint: disable=consider-using-f-string
print("\nPack %s" % OUTPUT_DB_NAME)
print(f"\nPack {OUTPUT_DB_NAME}")
con = sqlite3.connect(OUTPUT_DB_NAME)
cur = con.cursor()

Expand All @@ -38,23 +37,21 @@ def build_db(verbose: bool = False) -> bool:
continue
table_name = os.path.splitext(os.path.basename(file_path))[0]
file_path_full = os.path.join("data", file_path)
# print(table_name)

# Loop over CSV files
with open(file_path_full, encoding="utf-8") as csv_file:
dict_reader = csv.DictReader(csv_file)
# Skip empty CSV files
if not dict_reader.fieldnames:
print(f" WARN: empty CSV? {file_path_full}")
print(f"WARN: empty CSV? {file_path_full}")
continue
# Build values string (not best practice, use parametrized queries instead)
values = ",".join("?" * len(dict_reader.fieldnames or []))
reader = csv.reader(csv_file)
# pylint: disable=consider-using-f-string
query = "INSERT INTO {0} VALUES ({1});".format( # nosec: B608
table_name, values
)
# print(query)
# exit()
query = f"INSERT INTO {table_name} VALUES ({values});" # nosec: B608
if verbose:
print(f" {query}")

cur.executemany(query, reader)

cur.close()
Expand Down
2 changes: 1 addition & 1 deletion sql/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self):
def get(self, endpoint: str, params: dict = None) -> dict:
"""GET request to NHL API"""
response = requests.get(
f"{self.url}/{endpoint}", headers=self.headers, params=params
f"{self.url}/{endpoint}", headers=self.headers, params=params, timeout=10,
)
return dict(json.loads(response.text))

Expand Down

0 comments on commit d63f00b

Please sign in to comment.