<commit_before>"""
Scraper for New Hampshire Supreme Court
CourtID: nh
Court Short Name: NH
Court Contact: <EMAIL>
Author: <NAME>
Reviewer: mlr
History:
    - 2014-06-27: Created
    - 2014-10-17: Updated by mlr to fix regex error.
    - 2015-06-04: Updated by bwc so regex catches comma, period, or
    whitespaces as separator. Simplified by mlr to make regexes more semantic.
    - 2016-02-20: Updated by arderyp to handle strange format where multiple
    case names and docket numbers appear in anchor text for a single case pdf
    link. Multiple case names are concatenated, and docket numbers are
    concatenated with ',' delimiter
    - 2021-12-22: Updated for new web site, by satsuki-chan
"""

from datetime import date

from juriscraper.OpinionSiteLinear import OpinionSiteLinear


class Site(OpinionSiteLinear):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.court_id = self.__module__
        self.url = f"https://www.courts.nh.gov/our-courts/supreme-court/orders-and-opinions/opinions/{date.today().year}"
        self.cases = []

    def _process_html(self) -> None:
        path = "//div[@class='tabulator-cell']/div[@class='document__detail']/div[@class='document__detail__container']"
        for item in self.html.xpath(path):
            title = item.xpath(
                "./div[@class='document__detail__title']/h3//text()"
            )[0]
            url = item.xpath(
                "./div[@class='document__detail__title']/h3/a/@href"
            )[0]
            date = item.xpath(
                "./div[@class='document__detail__information'][2]/div/text()"
            )[0]
            docket_name = title.split(", ", 1)
            if not docket_name:
                continue
            docket = docket_name[0].strip()
            name = docket_name[1].strip()

            self.cases.append(
                {
                    "name": name,
                    "url": url,
                    "date": date,
                    "status": "Published",
                    "docket": docket,
                }
            )<commit_msg>Changed URL to web site API<commit_after>"""
Scraper for New Hampshire Supreme Court
CourtID: nh
Court Short Name: NH
Court Contact: <EMAIL>
Author: <NAME>
Reviewer: mlr
History:
    - 2014-06-27: Created
    - 2014-10-17: Updated by mlr to fix regex error.
    - 2015-06-04: Updated by bwc so regex catches comma, period, or
    whitespaces as separator. Simplified by mlr to make regexes more semantic.
    - 2016-02-20: Updated by arderyp to handle strange format where multiple
    case names and docket numbers appear in anchor text for a single case pdf
    link. Multiple case names are concatenated, and docket numbers are
    concatenated with ',' delimiter
    - 2021-12-22: Updated for new web site, by satsuki-chan
"""

import re

from juriscraper.OpinionSiteLinear import OpinionSiteLinear


class Site(OpinionSiteLinear):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.court_id = self.__module__
        self.url = "https://www.courts.nh.gov/content/api/documents"
        self.method = "GET"
        self.parameters = {
            "sort": "field_date_posted|desc",
            "page": "1",
            "size": "25",
            "purpose": "1331+undefined",
            "tag": "1206+",
        }

    def _download(self, request_dict={}):
        resp = self.request["session"].get(self.url, params=self.parameters)
        return resp.json()

    def _process_html(self) -> None:
        for op in self.html["data"]:
            docket, name = op["documentName"].split(",", 1)
            date = op["documentPosted"]
            url = re.findall(r"(http.*docu.*\.pdf)", op["documentContent"])[0]
            self.cases.append(
                {
                    "name": name,
                    "docket": docket,
                    "date": date,
                    "status": "Published",
                    "url": url,
                }
            )
{'fraction_non_alphanumeric': 0.11921840217660154, 'fraction_numerical': 0.0252287905021024, 'mean_word_length': 2.0870229007633587, 'pattern_counts': {'":': 15, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7580990', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1149, 'n_words': 329}