Skip to content

Commit

Permalink
get list of service dates
Browse files Browse the repository at this point in the history
Closes #6
  • Loading branch information
mscarey committed May 24, 2020
1 parent 47a6e6d commit 949981f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
24 changes: 17 additions & 7 deletions hearing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import re

from typing import Dict
from typing import Dict, List

from bs4 import BeautifulSoup

Expand Down Expand Up @@ -126,14 +126,24 @@ def appeared_in_text(text):
return appeared_tag is not None


def was_defendant_served(soup) -> bool:
served_tag = soup.find_all(text="Served")
return served_tag is not None
def was_defendant_served(soup) -> List[str]:
dates_of_service = []
served_tags = soup.find_all(text="Served")
for service_tag in served_tags:
date_tag = service_tag.parent.find_next_sibling("td")
dates_of_service.append(date_tag.text)

return dates_of_service

def was_defendant_alternative_served(soup) -> bool:
served_tag = soup.find(text="Order Granting Alternative Service")
return served_tag is not None

def was_defendant_alternative_served(soup) -> List[str]:
dates_of_service = []
served_tags = soup.find_all(text="Order Granting Alternative Service")
for service_tag in served_tags:
date_tag = service_tag.parent.parent.find_previous_sibling("th")
dates_of_service.append(date_tag.text)

return dates_of_service


def make_parsed_hearing(soup) -> Dict[str, str]:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ def test_defendant_appeared(self, index, expected):
assert expected == appeared

@pytest.mark.parametrize(
"index, expected", [(0, True), (1, True), (2, True)],
"index, expected", [(0, "05/01/2020"), (1, "05/06/2020"), (2, "01/22/2020")],
)
def test_defendant_served(self, index, expected):
soup = hearing.get_test_soup(index)
served = hearing.was_defendant_served(soup)
assert expected == served
assert expected == served[0]

@pytest.mark.parametrize(
"index, expected", [(0, False), (1, True), (2, True)],
"index, expected", [(0, []), (1, ["05/05/2020"]), (2, ["01/22/2020"])],
)
def test_alternative_service(self, index, expected):
soup = hearing.get_test_soup(index)
Expand Down

0 comments on commit 949981f

Please sign in to comment.