ncd

package module
v0.0.0-...-c98c310 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 9 Imported by: 0

README

NL Court Docs

A tool to parse the NL Court Docs with a supplied date and office ID.

You can use the builtin command for default outputs, or write your own with the package API.

Building

make build.

Running
Usage:
  -date string
        date in YYYY-MM-DD format, no past values (default "2023-09-11")
  -format string
        format: json, text, or csv (default "json")
  -office string
        office ID

Example: build/docket -office 7 -format text will output in text format, for office #7, for the current date.

Package

import (
  ncd "github.com/gnikyt/nl-court-docs"
)

// ...

// Grab today's docket for office #7.
d := ncd.NewDocket(time.Now().Format("2006-01-02"), "7", &http.client{})
res, err := d.Fetch()
if err != nil {
  log.Fatal(err)
}
if err := d.Parse(res); err != nil {
  log.Fatal(err)
}

// Output as JSON.
var out string
out, err = d.Output(ncd.NewPrettyJsonOutput(d.Data)) // or ncd.NewJsonOutput for non-pretty.
if err != nil {
  log.Fatal(err)
}
fmt.Print(out)

// Output as text.
out, _ = d.Output(ncd.NewTextOutput(d.Data))
fmt.Print(out)

// Output as CSV.
out, err = d.Output(ncd.NewCsvOutput(d.Data))
if err != nil {
  log.Fatal(err)
}
fmt.Print(out)
Example (JSON)
{
  "09:30 AM": {
    "DOE, JOHN FOO": [
      {
        "Description": "Assault",
        "Count": "1"
      }
    ],
    "DOE, JANE MARIA": [
      {
        "Description": "Operation of a conveyance while impaired",
        "Count": "1"
      },
      {
        "Description": "Failure or refusal to comply with demand",
        "Count": "1"
      },
      {
        "Description": "Dangerous operation of a conveyance",
        "Count": "1"
      },
      {
        "Description": "Resisting or obstructing a Peace Officer",
        "Count": "1"
      },
      {
        "Description": "Assaulting a peace officer/resisting arrest",
        "Count": "2"
      }
    ],
    ["// ..."]
  },
  {"// ..."}
}
Example (text)
>> 09:30AM
DOE, JOHN FOO
-------------
* Assult

DOE, JANE MARIA
---------------
* Operation of a conveyance while impaired
* Failure or refusal to comply with demand
* Dangerous operation of a conveyance
* Resisting or obstructing a Peace Officer
* Assaulting a peace officer/resisting arrest (2 counts)
Example (CSV)
09:30AM,"DOE, JOHN FOO",Assult,1
09:30AM,"DOE, JANE MARIA",Operation of a conveyance while impaired,1
09:30AM,"DOE, JANE MARIA",Failure or refusal to comply with demand,1
09:30AM,"DOE, JANE MARIA",Dangerous operation of a conveyance,1
09:30AM,"DOE, JANE MARIA",Resisting or obstructing a Peace Officer,1
09:30AM,"DOE, JANE MARIA",Assaulting a peace officer/resisting arrest,2

You can use the package API to create your own output implementations, such as saving to a database.

API

Running make docs:

package ncd // import "github.com/gnikyt/nl-court-docs"

type Charge struct{ ... }
type CsvOutput struct{ ... }
    func NewCsvOutput(dm DocketMapping) CsvOutput
type Docket struct{ ... }
    func NewDocket(date string, office string, client *http.Client) *Docket
type DocketMapping = map[string]map[string][]Charge
type JsonOutput struct{ ... }
    func NewJsonOutput(dm DocketMapping) JsonOutput
    func NewPrettyJsonOutput(dm DocketMapping) JsonOutput
type Outputter interface{ ... }
type TextOutput struct{ ... }
    func NewTextOutput(dm DocketMapping) TextOutput

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Charge

type Charge struct {
	Description string // description of the charge.
	Count       int    // number of counts for the charge.
}

Charge represents a charge for a case.

func (Charge) HasMultiple

func (c Charge) HasMultiple() bool

HasMultiple checks if there are multiple counts for the charge.

func (*Charge) Increase

func (c *Charge) Increase()

Increase will increase the count by 1.

type CsvOutput

type CsvOutput struct {
	DocketMapping // docket data.
}

CsvOutput will format the docket data as CSV in the format of: time,[case],[charge],[count].

func NewCsvOutput

func NewCsvOutput(dm DocketMapping) CsvOutput

NewCsvOutput returns a CsvOutput.

func (CsvOutput) Format

func (cv CsvOutput) Format() (*bytes.Buffer, error)

Implements Format for Outputter.

type Docket

type Docket struct {
	Data   DocketMapping // format of... { [time]: [{ [name]: [{ Description: [charge], Count: [count] }] } }.
	Office string        // which office for the docket.
	Date   string        // which date for the docket.
	Client *http.Client  // HTTP client handler.
	// contains filtered or unexported fields
}

Docket represents the data parsed from the Court Docket.

func NewDocket

func NewDocket(date string, office string, client *http.Client) *Docket

NewDocket inits a Docket struct.

func (*Docket) AddCase

func (d *Docket) AddCase(cas string)

AddCase parses the case title and append it to the current time. Should a case contain multiple people via "; ", then each will be appended to the current time.

func (*Docket) AddCharge

func (d *Docket) AddCharge(cas string, charge string)

AddCharge will either append a charge to the case or if the charge already exists for the case, it will increase it's count.

func (*Docket) AddTime

func (d *Docket) AddTime(time string)

AddTime creates a new map for the time supplied, if not existing.

func (*Docket) Fetch

func (d *Docket) Fetch() (*http.Response, error)

Fetch runs an HTTP call to the court docket page for the current date and supplied office. Returning an HTTP response.

func (*Docket) Output

func (d *Docket) Output(out Outputter) (string, error)

Output accepts an Outputter and returns a string.

func (*Docket) Parse

func (d *Docket) Parse(res *http.Response) error

Parse takes the HTTP response and parses it, saving into the data field.

type DocketMapping

type DocketMapping = map[string]map[string][]Charge

Alias type for the docket data container.

type JsonOutput

type JsonOutput struct {
	DocketMapping      // docket data.
	Pretty        bool // print pretty Json or not.
}

JsonOutput will format the docket data as Json.

func NewJsonOutput

func NewJsonOutput(dm DocketMapping) JsonOutput

NewJsonOutut returns a JsonOutput with non-pretty formatting.

func NewPrettyJsonOutput

func NewPrettyJsonOutput(dm DocketMapping) JsonOutput

NewPrettyJsonOutut returns a JsonOutputter with pretty formatting.

func (JsonOutput) Format

func (jo JsonOutput) Format() (*bytes.Buffer, error)

Implements Format for Outputter.

type Outputter

type Outputter interface {
	Format() (*bytes.Buffer, error)
}

Outputter describes and output handler.

type TextOutput

type TextOutput struct {
	DocketMapping // docket data.
}

TextOutput will format the docket data as plain text.

func NewTextOutput

func NewTextOutput(dm DocketMapping) TextOutput

NewTextOutput returns a TextOutputter.

func (TextOutput) Format

func (to TextOutput) Format() (*bytes.Buffer, error)

Implements Format for Outputter.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL