parser

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const KindleClippingLimitMessage = "<You have reached the clipping limit for this item>"
View Source
const KindleClippingsSeparator = "=========="

Variables

View Source
var KindleClippingsSeparatorMatcher *regexp.Regexp = regexp.MustCompile(`={10}`)
View Source
var KindleDescriptionLineVariations []KindleDescriptionLineVariation = []KindleDescriptionLineVariation{

	{
		Matcher:               regexp.MustCompile(`^- Your (.+?) on page ([ivx0-9]+) \| location (\d+)-?(\d+)? \| Added on (.+)$`),
		RequiredMatchCount:    12,
		Type:                  [2]int{2, 3},
		Page:                  [2]int{4, 5},
		LocationInSourceStart: [2]int{6, 7},
		LocationInSourceEnd:   [2]int{8, 9},
		CreateTime:            [2]int{10, 11},
		CreateTimeFormat:      "Monday, 2 January 2006 15:04:05",
	},

	{
		Matcher:               regexp.MustCompile(`^- Your (.+?) at location (\d+)-?(\d+)? \| Added on (.+)$`),
		RequiredMatchCount:    10,
		Type:                  [2]int{2, 3},
		Page:                  [2]int{-1, -1},
		LocationInSourceStart: [2]int{4, 5},
		LocationInSourceEnd:   [2]int{6, 7},
		CreateTime:            [2]int{8, 9},
		CreateTimeFormat:      "Monday, 2 January 2006 15:04:05",
	},

	{
		Matcher:               regexp.MustCompile(`- (\d+)ページ\|位置No. (\d+)-?(\d+)?の(.+) \|作成日: (.+)`),
		RequiredMatchCount:    12,
		Type:                  [2]int{8, 9},
		Page:                  [2]int{2, 3},
		LocationInSourceStart: [2]int{4, 5},
		LocationInSourceEnd:   [2]int{6, 7},
		CreateTime:            [2]int{10, 11},
		CreateTimeFormat:      "2006年1月2日",
	},

	{
		Matcher:               regexp.MustCompile(`^- Your (.+?) on page ([ivx0-9]+) \| Location (\d+)-?(\d+)? \| Added on (.+)$`),
		RequiredMatchCount:    12,
		Type:                  [2]int{2, 3},
		Page:                  [2]int{4, 5},
		LocationInSourceStart: [2]int{6, 7},
		LocationInSourceEnd:   [2]int{8, 9},
		CreateTime:            [2]int{10, 11},
		CreateTimeFormat:      "Monday, January 2, 2006 3:04:05 PM",
	},

	{
		Matcher:               regexp.MustCompile(`^- Your (.+?) on Location (\d+)-?(\d+)? \| Added on (.+)$`),
		RequiredMatchCount:    10,
		Type:                  [2]int{2, 3},
		Page:                  [2]int{-1, -1},
		LocationInSourceStart: [2]int{4, 5},
		LocationInSourceEnd:   [2]int{6, 7},
		CreateTime:            [2]int{8, 9},
		CreateTimeFormat:      "Monday, January 2, 2006 3:04:05 PM",
	},
}

Functions

This section is empty.

Types

type BookcisionClippingSet

type BookcisionClippingSet struct {
	Title      string `json:"title"`
	Authors    string `json:"authors"`
	Highlights []BookcisionHighlight
}

type BookcisionClippings

type BookcisionClippings struct {
	FilePath string
	Logger   *zap.Logger
}

func (*BookcisionClippings) Parse

func (b *BookcisionClippings) Parse() (Clippings, error)

Parse ...

type BookcisionHighlight

type BookcisionHighlight struct {
	Text       string
	IsNoteOnly bool
	Location   BookcisionHighlightLocation
	Note       string
}

type BookcisionHighlightLocation

type BookcisionHighlightLocation struct {
	URL   string
	Value int
}

type Clipping

type Clipping struct {
	Source string       `yaml:"source"`
	Type   ClippingType `yaml:"type"`

	// Page is not always a number. Sometimes it is a lowercase Roman numeral "ix"
	Page string `yaml:"page"`

	LocationInSource Location  `yaml:"location_in_source"`
	CreateTime       time.Time `yaml:"create_time"`
	Text             string    `yaml:"text"`
}

type ClippingType

type ClippingType int
const (
	ClippingType_None ClippingType = iota
	ClippingType_Highlight
	ClippingType_Note
)

type Clippings

type Clippings []Clipping

func (Clippings) Len

func (c Clippings) Len() int

Len ...

func (Clippings) Less

func (c Clippings) Less(i, j int) bool

Less ...

func (Clippings) Swap

func (c Clippings) Swap(i, j int)

Swap ...

type KindleClippings

type KindleClippings struct {
	FilePath                     string
	RemoveClippingLimitClippings bool
	// contains filtered or unexported fields
}

func (*KindleClippings) Parse

func (k *KindleClippings) Parse() (Clippings, error)

A sample clipping:

--- Sample START ---

Alias Grace (Atwood, Margaret) - Your Highlight on page 22 | location 281-283 | Added on Sunday, 5 May 2019 10:23:20

They were bell-shaped and ruffled, gracefully waving and lovely under the sea; but if they washed up on the beach and dried out in the sun there was nothing left of them. And that is what the ladies are like: mostly water. ==========

--- Sample END ---

An alternate form of the second line is:

--- Sample START ---

- Your Highlight on page ix | location 341-344 | Added on Saturday, 25 January 2020 10:47:54

--- Sample END ---

type KindleDescriptionLineVariation

type KindleDescriptionLineVariation struct {
	Matcher               *regexp.Regexp
	RequiredMatchCount    int
	Type                  [2]int
	Page                  [2]int
	LocationInSourceStart [2]int
	LocationInSourceEnd   [2]int
	CreateTime            [2]int
	CreateTimeFormat      string
}

type LineType

type LineType int
const (
	LineType_Invalid LineType = iota
	LineType_Source
	LineType_Description
	LineType_Empty
	LineType_Clipping
)

type Location

type Location struct {
	Start int `yaml:",omitempty"`
	End   int `yaml:",omitempty"`
}

type Parser

type Parser interface {
	Parse() (Clippings, error)
}

func NewParser

func NewParser(inputFilePath string) Parser

func NewParserWithLogger

func NewParserWithLogger(inputFilePath string, removeClippingLimitMessages bool, logger *zap.Logger) Parser

type Variant

type Variant int
const (
	Variant_English_BooksWithPageNum Variant = iota
	Variant_English_BooksWithoutPageNum
	Variant_Japanese
)

Jump to

Keyboard shortcuts

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