Nassiraaa commited on
Commit
ddcadec
·
verified ·
1 Parent(s): b46cf47

Update personal_information.py

Browse files
Files changed (1) hide show
  1. personal_information.py +9 -11
personal_information.py CHANGED
@@ -29,15 +29,15 @@ def extract_location(text):
29
  if response:
30
  try:
31
  location_data = json.loads(response)
32
- city = list(location_data.get('city', {}).keys())[0] if location_data.get('city') else None
33
- country = any(location_data.get('country', {}).values())
34
  except json.JSONDecodeError:
35
  print("Failed to parse JSON from response")
36
- city, country = None, False
37
  else:
38
- city, country = None, False
39
 
40
- return city, country
41
 
42
  def calculate_score(email_exists, phone_exists, city_exists, country_exists):
43
  score = 0
@@ -56,20 +56,18 @@ def analyze_personal_info(file_path):
56
 
57
  email = extract_email(text)
58
  phone = extract_phone(text)
59
- city, country = extract_location(text)
60
 
61
  email_exists = email is not None
62
  phone_exists = phone is not None
63
- city_exists = city is not None
64
- country_exists = country
65
 
66
- score = calculate_score(email_exists, phone_exists, city_exists, country_exists)
67
 
68
  result = {
69
  "email": email_exists,
70
  "phone": phone_exists,
71
- "city": city if city_exists else None,
72
- "country": country_exists,
73
  "personal_info_score": score
74
  }
75
 
 
29
  if response:
30
  try:
31
  location_data = json.loads(response)
32
+ city_present = any(location_data.get('city', {}).values())
33
+ country_present = any(location_data.get('country', {}).values())
34
  except json.JSONDecodeError:
35
  print("Failed to parse JSON from response")
36
+ city_present, country_present = False, False
37
  else:
38
+ city_present, country_present = False, False
39
 
40
+ return city_present, country_present
41
 
42
  def calculate_score(email_exists, phone_exists, city_exists, country_exists):
43
  score = 0
 
56
 
57
  email = extract_email(text)
58
  phone = extract_phone(text)
59
+ city_present, country_present = extract_location(text)
60
 
61
  email_exists = email is not None
62
  phone_exists = phone is not None
 
 
63
 
64
+ score = calculate_score(email_exists, phone_exists, city_present, country_present)
65
 
66
  result = {
67
  "email": email_exists,
68
  "phone": phone_exists,
69
+ "city": city_present,
70
+ "country": country_present,
71
  "personal_info_score": score
72
  }
73