Skip to content

Commit

Permalink
Merge pull request #14 from ruchernchong/13-set-number-instanceof-str…
Browse files Browse the repository at this point in the history
…ing-to-int-before-adding-to-db

Set number instanceof string to number
  • Loading branch information
ruchernchong authored Jun 15, 2024
2 parents adc4b37 + e4b4e7c commit f062571
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions updater.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import csv
import datetime
import os
import re
import tempfile
import time
from typing import List, Dict, Any
Expand Down Expand Up @@ -36,6 +37,15 @@ async def updater(
for row in csv_reader:
if "make" in row:
row["make"] = row["make"].replace(".", "")
# Convert string values to numbers if possible
for key, value in row.items():
if re.match(r"\b\d+(?:,\d+)?\b", value):
row[key] = 0 if value == "" else value
try:
value = str(int(value.replace(",", "")))
row[key] = float(value) if "." in value else int(value)
except ValueError:
pass
csv_data.append(row)

existing_data_map = {
Expand Down

0 comments on commit f062571

Please sign in to comment.