Documentation
¶
Overview ¶
Package dtekkrem looks up power outages and outage schedules for an address served by DTEK Kyiv Regional Electric Networks (https://www.dtek-krem.com.ua/ua/shutdowns).
The site is protected by Imperva Incapsula, which rejects plain HTTP clients, so the package drives a headless Google Chrome (or Chromium) via the DevTools protocol. Chrome must be installed on the host.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnknownCity = errors.New("dtekkrem: city not found") ErrUnknownStreet = errors.New("dtekkrem: street not found") ErrUnknownHouse = errors.New("dtekkrem: house not found") // ErrBlocked is returned when the site's bot protection rejects the request. It happens // when the site is queried too often (dozens of page loads within half an hour); retry later. ErrBlocked = errors.New("dtekkrem: request was blocked by the site's bot protection") )
Functions ¶
This section is empty.
Types ¶
type Address ¶
Address of a house as spelled on the site, e.g. {"м. Бориспіль", "вул. Київський Шлях", "6"}. House may be empty for addresses the site lists without house numbers.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client looks up outages on the DTEK KREM site. The browser is started on the first request and kept running until Close; each request uses its own tab, so a Client is safe for concurrent use.
func (*Client) Close ¶
func (c *Client) Close()
Close stops the browser. The Client can be reused afterwards: the next request starts a new one.
type Group ¶
type Interval ¶
type Interval struct {
Start time.Time
End time.Time
// Maybe marks a possible outage rather than a scheduled one.
Maybe bool
}
Interval is a period without power.
type Option ¶
type Option func(*Client)
func WithAllocatorOptions ¶
func WithAllocatorOptions(opts ...chromedp.ExecAllocatorOption) Option
WithAllocatorOptions appends chromedp allocator options, e.g. chromedp.ExecPath to point at a non-default Chrome binary or chromedp.Flag("headless", false) for debugging.
func WithTimeout ¶
WithTimeout limits the duration of a single request (page load included). Default is one minute.
type Outage ¶
type Outage struct {
// Planned is true for planned repair works; otherwise Reason tells the kind of outage,
// e.g. "Стабілізаційне відключення (Згідно графіку погодинних відключень)".
Planned bool
Reason string
Start time.Time
// End is the expected restoration time.
End time.Time
}
func (*Outage) IsEmergency ¶
IsEmergency reports an emergency outage, during which the group schedules do not apply.
type Result ¶
type Result struct {
Address Address
// Outage is the outage currently reported for the address, nil when there is none.
Outage *Outage
// Groups are the outage schedule groups (черги) the house belongs to. A house fed by
// several lines has several groups, and its apartments may follow different schedules.
Groups []Group
// UpdatedAt is when the site last refreshed the current outage information.
UpdatedAt time.Time
// ScheduleUpdatedAt is when the group schedules were last published.
ScheduleUpdatedAt time.Time
}
type Status ¶
type Status string
const ( StatusOn Status = "yes" StatusOff Status = "no" StatusMaybe Status = "maybe" StatusOffFirstHalf Status = "first" // off for the first 30 minutes of the hour StatusOffSecondHalf Status = "second" // off for the second 30 minutes of the hour StatusMaybeFirstHalf Status = "mfirst" // possibly off for the first 30 minutes StatusMaybeSecondHalf Status = "msecond" // possibly off for the second 30 minutes )