Johan713 commited on
Commit
2e36191
·
verified ·
1 Parent(s): 5b8f2f1

Update app2.py

Browse files
Files changed (1) hide show
  1. app2.py +45 -34
app2.py CHANGED
@@ -1253,22 +1253,14 @@ def get_trend_description(df):
1253
  return "The number of cases has remained relatively stable over the five-year period."
1254
 
1255
  PRACTICE_AREAS = [
1256
- "Personal Injury", "Medical Malpractice", "Criminal Law", "DUI & DWI", "Family Law",
1257
- "Divorce", "Bankruptcy", "Business Law", "Consumer Law", "Employment Law",
1258
- "Estate Planning", "Foreclosure Defense", "Immigration Law", "Intellectual Property",
1259
- "Nursing Home Abuse", "Probate", "Products Liability", "Real Estate Law", "Tax Law",
1260
- "Traffic Tickets", "Workers' Compensation", "Agricultural Law", "Animal & Dog Law",
1261
- "Antitrust Law", "Appeals & Appellate", "Arbitration & Mediation", "Asbestos & Mesothelioma",
1262
- "Cannabis & Marijuana Law", "Civil Rights", "Collections", "Communications & Internet Law",
1263
- "Construction Law", "Domestic Violence", "Education Law", "Elder Law",
1264
- "Energy, Oil & Gas Law", "Entertainment & Sports Law", "Environmental Law",
1265
- "Gov & Administrative Law", "Health Care Law", "Insurance Claims", "Insurance Defense",
1266
- "International Law", "Juvenile Law", "Landlord Tenant", "Legal Malpractice",
1267
- "Maritime Law", "Military Law", "Municipal Law", "Native American Law", "Patents",
1268
- "Securities Law", "Social Security Disability", "Stockbroker & Investment Fraud",
1269
- "Trademarks", "White Collar Crime"
1270
  ]
1271
 
 
1272
  STATES = [
1273
  "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut",
1274
  "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa",
@@ -1277,9 +1269,8 @@ STATES = [
1277
  "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio",
1278
  "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota",
1279
  "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia",
1280
- "Wisconsin", "Wyoming", "Washington, DC"
1281
  ]
1282
-
1283
  CITIES_BY_STATE = {
1284
  "Alabama": ["Birmingham", "Montgomery", "Mobile", "Huntsville", "Tuscaloosa", "Hoover", "Dothan", "Auburn", "Decatur", "Madison", "Florence", "Gadsden", "Vestavia Hills", "Prattville", "Phenix City", "Alabaster", "Bessemer", "Prichard", "Opelika", "Enterprise"],
1285
  "Alaska": ["Anchorage", "Fairbanks", "Juneau", "Sitka", "Ketchikan", "Wasilla", "Kenai", "Kodiak", "Bethel", "Palmer", "Homer", "Unalaska", "Barrow", "Soldotna", "Valdez", "Nome", "Kotzebue", "Seward", "Wrangell", "Dillingham"],
@@ -1334,13 +1325,16 @@ CITIES_BY_STATE = {
1334
  "Washington, DC": ["Washington"]
1335
  }
1336
 
 
 
 
1337
  def find_lawyers(practice_area, state, city=None):
1338
  base_url = "https://lawyers.findlaw.com"
1339
  formatted_practice_area = format_url_component(practice_area)
1340
- formatted_state = state.lower().replace(' ', '-')
1341
 
1342
  if city:
1343
- formatted_city = city.lower().replace(' ', '-')
1344
  search_url = f"{base_url}/{formatted_state}/{formatted_city}/{formatted_practice_area}-lawyer.html"
1345
  else:
1346
  search_url = f"{base_url}/{formatted_state}/{formatted_practice_area}-lawyer.html"
@@ -1375,15 +1369,20 @@ def find_lawyers(practice_area, state, city=None):
1375
  phone_elem = card.find('p', class_='phone')
1376
  phone = phone_elem.text.strip() if phone_elem else "N/A"
1377
 
1378
- # FindLaw doesn't provide ratings, so we'll generate a random one for demonstration
1379
- rating = f"{random.uniform(3.0, 5.0):.1f}/5.0"
 
 
 
 
 
1380
 
1381
  lawyers.append({
1382
  'name': name,
1383
  'location': location,
1384
  'practice_areas': practice_areas,
1385
  'phone': phone,
1386
- 'rating': rating,
1387
  'profile_url': profile_url
1388
  })
1389
  except AttributeError as e:
@@ -1395,40 +1394,52 @@ def find_lawyers(practice_area, state, city=None):
1395
 
1396
  return lawyers
1397
 
1398
- def format_url_component(s):
1399
- return s.lower().replace(' ', '-').replace(',', '').replace('&', 'and')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1400
 
1401
  def lawyer_finder_ui():
1402
- st.subheader("Find the Best Lawyer for Your Case")
1403
 
1404
  practice_area = st.selectbox("Select a Practice Area:", PRACTICE_AREAS)
1405
  state = st.selectbox("Select a State:", STATES)
1406
 
1407
- cities = CITIES_BY_STATE.get(state, [])
1408
- if cities:
1409
- city = st.selectbox("Select a City (optional):", [""] + cities)
1410
- else:
1411
- city = None
1412
- st.info("No major cities available for the selected state. The search will be performed statewide.")
1413
 
1414
  if st.button("Find Lawyers", type="primary"):
1415
- with st.spinner("Searching for the best lawyers..."):
1416
- lawyers = find_lawyers(practice_area, state, city)
1417
 
1418
  if lawyers:
1419
- st.success(f"Found {len(lawyers)} potential lawyers for your case.")
1420
  for lawyer in lawyers:
1421
  with st.expander(f"{lawyer['name']} - {lawyer['location']}"):
1422
  col1, col2 = st.columns([2, 1])
1423
  with col1:
1424
  st.markdown(f"**Practice Areas:** {lawyer['practice_areas']}")
1425
  st.markdown(f"**Phone:** {lawyer['phone']}")
1426
- st.markdown(f"**Rating:** {lawyer['rating']} (Estimated)")
1427
  with col2:
1428
  st.markdown(f"[![View Profile](https://img.shields.io/badge/View_Profile-FindLaw-blue?style=for-the-badge)]({lawyer['profile_url']})")
1429
  else:
1430
  st.warning("No lawyers found matching your criteria. Try broadening your search.")
1431
 
 
1432
  class LegalDataRetriever:
1433
  def __init__(self):
1434
  self.session = requests.Session()
 
1253
  return "The number of cases has remained relatively stable over the five-year period."
1254
 
1255
  PRACTICE_AREAS = [
1256
+ "Bankruptcy", "Business", "Civil Rights", "Consumer", "Criminal Defense", "DUI",
1257
+ "Employment", "Estate Planning", "Family", "Government", "Immigration", "Injury",
1258
+ "Insurance", "Intellectual Property", "International", "Juvenile", "Landlord Tenant",
1259
+ "Military", "Products Liability", "Real Estate", "Social Security Disability", "Tax",
1260
+ "Traffic Tickets", "Workers' Compensation"
 
 
 
 
 
 
 
 
 
1261
  ]
1262
 
1263
+ # All US states and territories
1264
  STATES = [
1265
  "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut",
1266
  "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa",
 
1269
  "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio",
1270
  "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota",
1271
  "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia",
1272
+ "Wisconsin", "Wyoming", "District of Columbia", "Puerto Rico"
1273
  ]
 
1274
  CITIES_BY_STATE = {
1275
  "Alabama": ["Birmingham", "Montgomery", "Mobile", "Huntsville", "Tuscaloosa", "Hoover", "Dothan", "Auburn", "Decatur", "Madison", "Florence", "Gadsden", "Vestavia Hills", "Prattville", "Phenix City", "Alabaster", "Bessemer", "Prichard", "Opelika", "Enterprise"],
1276
  "Alaska": ["Anchorage", "Fairbanks", "Juneau", "Sitka", "Ketchikan", "Wasilla", "Kenai", "Kodiak", "Bethel", "Palmer", "Homer", "Unalaska", "Barrow", "Soldotna", "Valdez", "Nome", "Kotzebue", "Seward", "Wrangell", "Dillingham"],
 
1325
  "Washington, DC": ["Washington"]
1326
  }
1327
 
1328
+ def format_url_component(s):
1329
+ return s.lower().replace(' ', '-').replace(',', '').replace('&', 'and')
1330
+
1331
  def find_lawyers(practice_area, state, city=None):
1332
  base_url = "https://lawyers.findlaw.com"
1333
  formatted_practice_area = format_url_component(practice_area)
1334
+ formatted_state = format_url_component(state)
1335
 
1336
  if city:
1337
+ formatted_city = format_url_component(city)
1338
  search_url = f"{base_url}/{formatted_state}/{formatted_city}/{formatted_practice_area}-lawyer.html"
1339
  else:
1340
  search_url = f"{base_url}/{formatted_state}/{formatted_practice_area}-lawyer.html"
 
1369
  phone_elem = card.find('p', class_='phone')
1370
  phone = phone_elem.text.strip() if phone_elem else "N/A"
1371
 
1372
+ # Extract years of experience if available
1373
+ experience = "N/A"
1374
+ exp_elem = card.find('p', class_='experience')
1375
+ if exp_elem:
1376
+ exp_match = re.search(r'(\d+)\s+years', exp_elem.text)
1377
+ if exp_match:
1378
+ experience = f"{exp_match.group(1)} years"
1379
 
1380
  lawyers.append({
1381
  'name': name,
1382
  'location': location,
1383
  'practice_areas': practice_areas,
1384
  'phone': phone,
1385
+ 'experience': experience,
1386
  'profile_url': profile_url
1387
  })
1388
  except AttributeError as e:
 
1394
 
1395
  return lawyers
1396
 
1397
+ def get_cities(state):
1398
+ formatted_state = format_url_component(state)
1399
+ url = f"https://lawyers.findlaw.com/{formatted_state}/"
1400
+
1401
+ headers = {
1402
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
1403
+ }
1404
+
1405
+ try:
1406
+ response = requests.get(url, headers=headers, timeout=10)
1407
+ response.raise_for_status()
1408
+ soup = BeautifulSoup(response.content, 'html.parser')
1409
+ city_links = soup.find_all('a', class_='city-link')
1410
+ return [city.text.strip() for city in city_links]
1411
+ except requests.RequestException as e:
1412
+ print(f"Error fetching cities: {e}")
1413
+ return []
1414
 
1415
  def lawyer_finder_ui():
1416
+ st.title("FindLaw Lawyer Search")
1417
 
1418
  practice_area = st.selectbox("Select a Practice Area:", PRACTICE_AREAS)
1419
  state = st.selectbox("Select a State:", STATES)
1420
 
1421
+ cities = get_cities(state)
1422
+ city = st.selectbox("Select a City (optional):", [""] + cities)
 
 
 
 
1423
 
1424
  if st.button("Find Lawyers", type="primary"):
1425
+ with st.spinner("Searching for lawyers..."):
1426
+ lawyers = find_lawyers(practice_area, state, city if city else None)
1427
 
1428
  if lawyers:
1429
+ st.success(f"Found {len(lawyers)} lawyers matching your criteria.")
1430
  for lawyer in lawyers:
1431
  with st.expander(f"{lawyer['name']} - {lawyer['location']}"):
1432
  col1, col2 = st.columns([2, 1])
1433
  with col1:
1434
  st.markdown(f"**Practice Areas:** {lawyer['practice_areas']}")
1435
  st.markdown(f"**Phone:** {lawyer['phone']}")
1436
+ st.markdown(f"**Experience:** {lawyer['experience']}")
1437
  with col2:
1438
  st.markdown(f"[![View Profile](https://img.shields.io/badge/View_Profile-FindLaw-blue?style=for-the-badge)]({lawyer['profile_url']})")
1439
  else:
1440
  st.warning("No lawyers found matching your criteria. Try broadening your search.")
1441
 
1442
+
1443
  class LegalDataRetriever:
1444
  def __init__(self):
1445
  self.session = requests.Session()