yonginbustimetable

package module
v0.0.0-...-334d3c3 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

README

yongin-bus-timetable

Yongin Bus Timetable Scraper & Viewer using Go

See README_ko.md if you're a Korean.

Why?

  • In Yongin, There are several buses are having a timetable.
  • However, most of the map service (such as, N*V*R, K*K*O, etc) does not supports Specific Bus Timetable.

How?

  1. Scrape Bus Timetable from Yongin Bus Terminal
  2. Extract Links from Button (that usually trigger window.open to show timetables of a bus.)
  3. Go to extracted address from window.open and extract <table>...</table>
  4. Store it to DB (or json formatted code to easily retrieve from Static Site.)
  5. Profit!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BusLink struct {
	// Name Bus name
	//
	// extracted from button's b tag
	Name string `json:"name"`
	// Route Bus Route
	Route string `json:"route,omitempty"`
	// WindowOpenLink a Extracted URL from button's onclick attribute
	WindowOpenLink string `json:"windowOpenLink"`
}

BusLink Link information from `button` element

func (*BusLink) ExtractBusNumber

func (b *BusLink) ExtractBusNumber() string

ExtractBusNumber Extract Bus number using regexp and return exact bus number

type BusLinkExtractor

type BusLinkExtractor struct {
	// Doc Goquery Document
	Doc *goquery.Document
	// URL a Request URL to make full bus timetable url
	URL string
}

BusLinkExtractor Bus List Extractor

func NewBusListExtractor

func NewBusListExtractor(r io.Reader, urls ...string) (*BusLinkExtractor, error)

NewBusListExtractor Create new BusListExtractor from Reader

func (*BusLinkExtractor) Extract

func (b *BusLinkExtractor) Extract(ctx context.Context) ([]*BusLink, error)

Extract the button elements

type BusTimetable

type BusTimetable struct {
	// Stops name of bus stops
	Stops []string `json:"stops"`
	// Timetables List of bus timetables
	Timetables []*Timetable `json:"timetables"`
}

BusTimetable Bus Timetable Information

type BusTimetableExtractor

type BusTimetableExtractor struct{}

TimetableExtractor Bus Timetable Extractor

func NewBusTimetableExtractor

func NewBusTimetableExtractor() *BusTimetableExtractor

NewBusTimetableExtractor Create a new TimetableExtractor

func (*BusTimetableExtractor) Extract

func (bte *BusTimetableExtractor) Extract(ctx context.Context, b *BusLink) (*BusTimetable, error)

type Timetable

type Timetable struct {
	// Stop name of bus stop
	Stop string `json:"stop"`
	// DepartAt time of when bus is depart
	DepartAt string `json:"departAt"`
}

func (*Timetable) ExtractTime

func (t *Timetable) ExtractTime() (s string, commentFound bool, err error)

ExtractTime Extract TIME from DepartAt

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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