Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated combined_files.py #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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)