Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions combine_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@ def cleanRow(row):
for listing in raw_files:
print(listing)
if os.path.isfile(listing):
file_date = re.match('.*([0-9]{8}).*csv$', listing).group(1)
with open(listing) as csvfile:
spamreader = csv.reader(csvfile)
data = []
for row in spamreader:
row = cleanRow(row)
data.append(dict(zip(header, row)))

full_data[file_date] = data
# Updated regex to match 'M.YYYY' format in the filename
match = re.match(r'.*([0-9]{1,2}\.[0-9]{4}).*\.csv$', listing)

# Check if match exists before accessing group(1) to avoid AttributeError
if match: # Updated conditional check to prevent errors
file_date = match.group(1)
with open(listing) as csvfile:
spamreader = csv.reader(csvfile)
data = []
for row in spamreader:
row = cleanRow(row)
data.append(dict(zip(header, row)))

full_data[file_date] = data
else:
print(f"Warning: No valid date found in filename '{listing}'") # Added warning message

with open(combined_file, 'w') as jsonFile:
json.dump(full_data, jsonFile, indent=4)