Alpha108 commited on
Commit
7e2ee1c
·
verified ·
1 Parent(s): 9317e1a

Update backend/agents/normalizer.py

Browse files
Files changed (1) hide show
  1. backend/agents/normalizer.py +12 -1
backend/agents/normalizer.py CHANGED
@@ -21,6 +21,16 @@ def normalize_job_data(job_data, source):
21
  dict: A dictionary with the normalized job data.
22
  """
23
  if source == "RemoteOK":
 
 
 
 
 
 
 
 
 
 
24
  return {
25
  'id': job_data.get('id', ''),
26
  'title': job_data.get('position', 'N/A'),
@@ -28,7 +38,7 @@ def normalize_job_data(job_data, source):
28
  'location': job_data.get('location', 'Remote'),
29
  'description': clean_html(job_data.get('description', '')),
30
  'url': job_data.get('url', ''),
31
- 'date_posted': datetime.fromtimestamp(job_data.get('date', 0)).strftime('%Y-%m-%d'),
32
  'source': source
33
  }
34
  elif source == "LinkedIn (Stub)":
@@ -76,3 +86,4 @@ def normalize_job_data(job_data, source):
76
  'date_posted': 'N/A',
77
  'source': source
78
  }
 
 
21
  dict: A dictionary with the normalized job data.
22
  """
23
  if source == "RemoteOK":
24
+ date_posted_str = 'N/A'
25
+ try:
26
+ # FIX: Safely convert timestamp, handling potential strings or errors.
27
+ timestamp = int(job_data.get('date', 0))
28
+ if timestamp > 0:
29
+ date_posted_str = datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d')
30
+ except (ValueError, TypeError, OSError):
31
+ # If the date is not a valid number or causes an error, it will default to 'N/A'.
32
+ pass
33
+
34
  return {
35
  'id': job_data.get('id', ''),
36
  'title': job_data.get('position', 'N/A'),
 
38
  'location': job_data.get('location', 'Remote'),
39
  'description': clean_html(job_data.get('description', '')),
40
  'url': job_data.get('url', ''),
41
+ 'date_posted': date_posted_str, # Use the safely handled string
42
  'source': source
43
  }
44
  elif source == "LinkedIn (Stub)":
 
86
  'date_posted': 'N/A',
87
  'source': source
88
  }
89
+