treksum

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2017 License: BSD-3-Clause Imports: 12 Imported by: 0

README

Treksum

Travis CI Status License BSD3 Downloads Docker Pulls

Treksum provides access to the transcripts for all episodes of the following TV series:

  • Star Trek
  • Star Trek: The Next Generation
  • Star Trek: Deep Space Nine
  • Star Trek: Voyager
  • Star Trek: Enterprise

What's Included

There are currently two utilities contained in this repository:

  • treksum-scraper: scrapes Star Trek transcripts and shoves everything into a PostgreSQL database.
  • treksum-api: a simple API to serve up random quotes from a PostgreSQL database. This utility is useless without first having used treksum-scraper to populate the PostgreSQL database.

Usage

The following environment variables are used to configure both utilities:

  • TREKSUM_DBHOST: IP address for PostgreSQL service. Default: localhost
  • TREKSUM_DBPORT: Port on which PostgreSQL is listening. Default: 5432
  • TREKSUM_DBNAME: Name of PostgreSQL database where transcripts reside. Default: treksum
  • TREKSUM_DBUSER: PostgreSQL username. Default: treksum
  • TREKSUM_DBPASSWORD: PostgreSQL password. No default.

The following environment variable is used only for treksum-api:

  • TREKSUM_APIADDR: interface and port to bind when serving requests. Default: :1323

With the appropriate environment variables set, simply invoke the desired command.

Credits

The transcripts used by treksum were scraped from http://chakoteya.net/StarTrek/

Star Trek and related marks are trademarks of CBS Studios Inc. This project is purely for educational and entertainment purposes only. All other copyrights remain property of their respective owners.

Documentation

Index

Constants

View Source
const (
	CREATE_EPISODE_TABLE = `` /* 269-byte string literal not displayed */

	INSERT_EPISODE = `` /* 153-byte string literal not displayed */

)
View Source
const (
	CREATE_LINE_TABLE = `` /* 233-byte string literal not displayed */

	INSERT_LINE = `
		insert into "line"
			("episode_id", "speaker_id", "line")
		values
			($1, $2, $3)
		returning ("id")
	`
)
View Source
const (
	CREATE_SERIES_TABLE = `
		create table "series" (
			"id" serial primary key,
			"name" citext,
			"url" text,
			unique("name")
		)
	`

	INSERT_SERIES = `
		insert into "series"
			("name", "url")
		values
			($1, $2)
		returning ("id")
	`
)
View Source
const (
	CREATE_SPEAKER_TABLE = `` /* 188-byte string literal not displayed */

	INSERT_SPEAKER = `` /* 186-byte string literal not displayed */

	SELECT_SPEAKER = `
		SELECT "id"
		FROM "speaker"
		WHERE "series_id" = $1
		  AND "name" = $2
	`
)
View Source
const (
	Version = "v0.0.4"

	VersionTag = ""
)

Variables

View Source
var AppInfo appInfo

Functions

func CleanUnicode

func CleanUnicode(in string) string

CleanUnicode replaces problematic characters from the Star Trek transcripts with suitable alternatives.

func FindEpisodesLink(url string) (next string, err error)

FindEpisodesLink searches a web page for a link to a list of episodes in a particular series and returns the URL for that page.

func GetVersionString added in v0.0.4

func GetVersionString() string

func SwitchPage

func SwitchPage(url, page string) string

SwitchPage replaces the final "index.htm" portion of a URL (if present) with a new page.

Types

type Episode

type Episode struct {
	ID      int64      `json:"id"`
	Series  *Series    `json:"series"`
	Season  int        `json:"season"`
	Episode int        `json:"episode"`
	Title   string     `json:"title"`
	Url     string     `json:"url"`
	Airdate *time.Time `json:"airdate"`
	Script  []*Line    `json:"script"`

	Log *zap.Logger
}

func ParseEpisodeList

func ParseEpisodeList(log *zap.Logger, series *Series) (episodes []*Episode, err error)

ParseEpisodeList parses out each episode from a series of tables on a page that lists all episodes for a specific TV series.

func (*Episode) AddLine

func (this *Episode) AddLine(line *Line)

AddLine adds a new line from the episode's script, cleaning up any problematic characters in the process.

func (*Episode) Fetch

func (this *Episode) Fetch() (err error)

Fetch scrapes the episode's transcript.

func (*Episode) GetAbbrev

func (this *Episode) GetAbbrev() string

GetAbbrev returns the season and episode in the form of S00E00.

func (*Episode) Parse

func (this *Episode) Parse(scriptText io.Reader) (err error)

Parse extracts individual lines from the episode's transcript.

func (*Episode) Save

func (this *Episode) Save(tx *pgx.Tx) (err error)

Save persists the episode and its transcript to the database.

func (*Episode) ScriptString

func (this *Episode) ScriptString() string

ScriptString combines all lines into a single string for the entire episode's script.

func (*Episode) String

func (this *Episode) String() string

type Line

type Line struct {
	ID      int64    `json:"id"`
	Episode *Episode `json:"episode,omitempty"`
	Speaker string   `json:"speaker"`
	Line    string   `json:"line"`
	// contains filtered or unexported fields
}

func NewLine

func NewLine(log *zap.Logger, speaker, text string) (l *Line)

func (*Line) AddText

func (this *Line) AddText(text string)

AddText appends text to existing text in a line from the transcript.

func (*Line) Save

func (this *Line) Save(tx *pgx.Tx) (err error)

Save persists the line to the database;

func (*Line) String

func (this *Line) String() string

type Series

type Series struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
	Url  string `json:"url"`
}

func NewSeries

func NewSeries(name, url string) (s *Series)

func (*Series) Save

func (this *Series) Save(tx *pgx.Tx) (err error)

func (*Series) String

func (this *Series) String() string

type Speaker

type Speaker struct {
	ID     int64   `json:"id"`
	Series *Series `json:"series"`
	Name   string  `json:"name"`
}

func NewSpeaker

func NewSpeaker(series *Series, name string) (s *Speaker)

func (*Speaker) Save

func (this *Speaker) Save(tx *pgx.Tx) (err error)

func (*Speaker) String

func (this *Speaker) String() string

type VersionInfo added in v0.0.4

type VersionInfo struct {
	Version       string `json:"version"`
	VersionTag    string `json:"tag"`
	VersionString string `json:"version_string"`
	Revision      string `json:"revision"`
	Branch        string `json:"branch"`
	BuildUser     string `json:"build_user"`
	BuildDate     string `json:"build_date"`
	GoVersion     string `json:"go_version"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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