-
Notifications
You must be signed in to change notification settings - Fork 11
/
load_pages.py
61 lines (41 loc) · 1.95 KB
/
load_pages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
from bs4 import BeautifulSoup
def get_test_html_path(index: int, page_type: str, county: str = "example") -> str:
this_directory = os.path.dirname(os.path.realpath(__file__))
test_filepath = os.path.join(this_directory, page_type, f"{county}_{index}.html")
return test_filepath
def get_test_calendar_path() -> str:
this_directory = os.path.dirname(os.path.realpath(__file__))
test_filepath = os.path.join(this_directory, "test_search_pages", "calendar.html")
return test_filepath
def get_test_filing_search_path() -> str:
"""Used for testing the separate module "parse_filings.py"."""
this_directory = os.path.dirname(os.path.realpath(__file__))
test_filepath = os.path.join(
this_directory, "test_search_pages", f"example_case_query_result.html"
)
return test_filepath
def load_soup_from_filepath(filepath: str) -> BeautifulSoup:
with open(filepath) as fp:
soup = BeautifulSoup(fp, "html.parser")
return soup
def get_test_calendar() -> BeautifulSoup:
filepath = get_test_calendar_path()
return load_soup_from_filepath(filepath)
def get_test_soup(index: int, county: str = "example") -> BeautifulSoup:
filepath = get_test_html_path(index, page_type="test_pages", county=county)
return load_soup_from_filepath(filepath)
def get_test_search_page(index: int) -> BeautifulSoup:
filepath = get_test_html_path(index, page_type="test_search_pages")
return load_soup_from_filepath(filepath)
def get_test_filings_search_page() -> BeautifulSoup:
"""
Used for testing the separate module "parse_filings.py".
This may or may not need to be distinct from get_test_search_page above.
Possibly the functions being tested can be consolidated.
"""
filepath = get_test_filing_search_path()
return load_soup_from_filepath(filepath)
def get_test_calendar_page() -> BeautifulSoup:
filepath = get_test_calendar_path()
return load_soup_from_filepath(filepath)