Update app2.py
Browse files
app2.py
CHANGED
@@ -1252,25 +1252,6 @@ def get_trend_description(df):
|
|
1252 |
else:
|
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",
|
1267 |
-
"Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan",
|
1268 |
-
"Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire",
|
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"],
|
@@ -1328,72 +1309,48 @@ CITIES_BY_STATE = {
|
|
1328 |
def format_url_component(s):
|
1329 |
return s.lower().replace(' ', '-').replace(',', '').replace('&', 'and')
|
1330 |
|
1331 |
-
def
|
1332 |
-
base_url = "https://
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
search_url = f"{base_url}/{formatted_state}/{formatted_practice_area}-lawyer.html"
|
1341 |
|
1342 |
headers = {
|
1343 |
'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'
|
1344 |
}
|
1345 |
|
1346 |
try:
|
1347 |
-
response = requests.get(
|
1348 |
response.raise_for_status()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1349 |
except requests.RequestException as e:
|
1350 |
-
|
1351 |
-
return []
|
1352 |
-
|
1353 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
1354 |
-
|
1355 |
-
lawyers = []
|
1356 |
-
lawyer_cards = soup.find_all('div', class_='lawyer-card')
|
1357 |
-
|
1358 |
-
if not lawyer_cards:
|
1359 |
-
print(f"No lawyer cards found on the page. URL: {search_url}")
|
1360 |
return []
|
1361 |
|
1362 |
-
for card in lawyer_cards[:5]: # Limit to top 5 results
|
1363 |
-
try:
|
1364 |
-
name = card.find('h3', class_='lawyer-name').text.strip()
|
1365 |
-
location = card.find('p', class_='location').text.strip()
|
1366 |
-
practice_areas = card.find('p', class_='practice-areas').text.strip()
|
1367 |
-
profile_url = base_url + card.find('a', class_='lawyer-name')['href']
|
1368 |
-
|
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:
|
1389 |
-
print(f"Error parsing lawyer card: {e}")
|
1390 |
-
continue
|
1391 |
-
|
1392 |
-
if not lawyers:
|
1393 |
-
print(f"No lawyers found on the page. URL: {search_url}")
|
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}/"
|
@@ -1413,32 +1370,43 @@ def get_cities(state):
|
|
1413 |
return []
|
1414 |
|
1415 |
def lawyer_finder_ui():
|
1416 |
-
st.title("
|
1417 |
-
|
1418 |
-
|
1419 |
-
|
1420 |
-
|
1421 |
-
|
1422 |
-
|
1423 |
|
1424 |
-
|
1425 |
-
|
1426 |
-
|
1427 |
-
|
1428 |
-
|
1429 |
-
|
1430 |
-
|
1431 |
-
|
1432 |
-
|
1433 |
-
|
1434 |
-
|
1435 |
-
|
1436 |
-
st.markdown(f"**Experience:** {lawyer['experience']}")
|
1437 |
-
with col2:
|
1438 |
-
st.markdown(f"[]({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):
|
|
|
1252 |
else:
|
1253 |
return "The number of cases has remained relatively stable over the five-year period."
|
1254 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1255 |
CITIES_BY_STATE = {
|
1256 |
"Alabama": ["Birmingham", "Montgomery", "Mobile", "Huntsville", "Tuscaloosa", "Hoover", "Dothan", "Auburn", "Decatur", "Madison", "Florence", "Gadsden", "Vestavia Hills", "Prattville", "Phenix City", "Alabaster", "Bessemer", "Prichard", "Opelika", "Enterprise"],
|
1257 |
"Alaska": ["Anchorage", "Fairbanks", "Juneau", "Sitka", "Ketchikan", "Wasilla", "Kenai", "Kodiak", "Bethel", "Palmer", "Homer", "Unalaska", "Barrow", "Soldotna", "Valdez", "Nome", "Kotzebue", "Seward", "Wrangell", "Dillingham"],
|
|
|
1309 |
def format_url_component(s):
|
1310 |
return s.lower().replace(' ', '-').replace(',', '').replace('&', 'and')
|
1311 |
|
1312 |
+
def search_lawyers(practice_area, state, city=None):
|
1313 |
+
base_url = "https://www.martindale.com/search/attorneys/"
|
1314 |
+
params = {
|
1315 |
+
'term': practice_area,
|
1316 |
+
'country': 'USA',
|
1317 |
+
'state': state,
|
1318 |
+
'city': city or '',
|
1319 |
+
'page': 1
|
1320 |
+
}
|
|
|
1321 |
|
1322 |
headers = {
|
1323 |
'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'
|
1324 |
}
|
1325 |
|
1326 |
try:
|
1327 |
+
response = requests.get(base_url, params=params, headers=headers)
|
1328 |
response.raise_for_status()
|
1329 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
1330 |
+
|
1331 |
+
lawyer_cards = soup.find_all('div', class_='card-body')
|
1332 |
+
|
1333 |
+
lawyers = []
|
1334 |
+
for card in lawyer_cards[:5]: # Limit to top 5 results
|
1335 |
+
name_elem = card.find('h3', class_='name')
|
1336 |
+
if name_elem:
|
1337 |
+
name = name_elem.text.strip()
|
1338 |
+
location = card.find('p', class_='location').text.strip()
|
1339 |
+
practice_areas = card.find('p', class_='practice-areas').text.strip()
|
1340 |
+
profile_url = "https://www.martindale.com" + name_elem.find('a')['href']
|
1341 |
+
|
1342 |
+
lawyers.append({
|
1343 |
+
'name': name,
|
1344 |
+
'location': location,
|
1345 |
+
'practice_areas': practice_areas,
|
1346 |
+
'profile_url': profile_url
|
1347 |
+
})
|
1348 |
+
|
1349 |
+
return lawyers
|
1350 |
except requests.RequestException as e:
|
1351 |
+
st.error(f"Error fetching lawyer data: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1352 |
return []
|
1353 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1354 |
def get_cities(state):
|
1355 |
formatted_state = format_url_component(state)
|
1356 |
url = f"https://lawyers.findlaw.com/{formatted_state}/"
|
|
|
1370 |
return []
|
1371 |
|
1372 |
def lawyer_finder_ui():
|
1373 |
+
st.title("Lawyer Search System")
|
1374 |
+
|
1375 |
+
practice_areas = [
|
1376 |
+
"Bankruptcy", "Business Law", "Civil Rights", "Criminal Defense",
|
1377 |
+
"Employment Law", "Estate Planning", "Family Law", "Immigration",
|
1378 |
+
"Intellectual Property", "Personal Injury", "Real Estate Law", "Tax Law"
|
1379 |
+
]
|
1380 |
|
1381 |
+
states = [
|
1382 |
+
"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado",
|
1383 |
+
"Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho",
|
1384 |
+
"Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana",
|
1385 |
+
"Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota",
|
1386 |
+
"Mississippi", "Missouri", "Montana", "Nebraska", "Nevada",
|
1387 |
+
"New Hampshire", "New Jersey", "New Mexico", "New York",
|
1388 |
+
"North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon",
|
1389 |
+
"Pennsylvania", "Rhode Island", "South Carolina", "South Dakota",
|
1390 |
+
"Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington",
|
1391 |
+
"West Virginia", "Wisconsin", "Wyoming"
|
1392 |
+
]
|
|
|
|
|
|
|
|
|
|
|
1393 |
|
1394 |
+
selected_practice_area = st.selectbox("Select a Practice Area:", practice_areas)
|
1395 |
+
selected_state = st.selectbox("Select a State:", states)
|
1396 |
+
city = st.text_input("Enter a City (optional):")
|
1397 |
+
|
1398 |
+
if st.button("Search Lawyers"):
|
1399 |
+
with st.spinner("Searching for lawyers..."):
|
1400 |
+
results = search_lawyers(selected_practice_area, selected_state, city)
|
1401 |
+
|
1402 |
+
if results:
|
1403 |
+
st.success(f"Found {len(results)} lawyers matching your criteria.")
|
1404 |
+
for lawyer in results:
|
1405 |
+
with st.expander(f"{lawyer['name']} - {lawyer['location']}"):
|
1406 |
+
st.write(f"**Practice Areas:** {lawyer['practice_areas']}")
|
1407 |
+
st.markdown(f"[View Profile]({lawyer['profile_url']})")
|
1408 |
+
else:
|
1409 |
+
st.warning("No lawyers found matching your criteria. Try broadening your search.")
|
1410 |
|
1411 |
class LegalDataRetriever:
|
1412 |
def __init__(self):
|