-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_new.py
43 lines (31 loc) · 1.1 KB
/
validate_new.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import csv
from datetime import datetime
count = 0
# Function to extract year from a date string
def extract_year(date_str):
try:
date_obj = datetime.strptime(date_str, '%b %d, %Y')
print(date_obj)
return date_obj.year
except ValueError:
return None
# Function to check if release year matches date year
def check_year_mismatch(csv_file_path):
global count
mismatches = []
with open(csv_file_path, mode='r', newline='') as file:
reader = csv.DictReader(file)
for row in reader:
date_str = row.get('Date')
release_year_str = row.get('Released')
date_year = extract_year(date_str) if date_str else None
release_year = int(release_year_str) if release_year_str else None
if release_year is None or date_year != release_year:
mismatches.append(row)
count += 1
return mismatches
csv_file_path = 'input.csv'
mismatches = check_year_mismatch(csv_file_path)
for mismatch in mismatches:
print(mismatch)
print(count)