Documentation ¶
Overview ¶
Package tdbank provides methods for online banking with TD Bank. It uses agouti's Chrome web driver to access the bank's web site. For now it only supports scraping account histories.
Index ¶
- Constants
- Variables
- type Auth
- type Client
- func (client *Client) GetHtml() (string, error)
- func (client *Client) Login(auth Auth)
- func (client *Client) ParseAccountBalance() (int64, error)
- func (client *Client) ParseAccountHistory() ([]HistoryRecord, error)
- func (client *Client) PrintHtml()
- func (client *Client) Start()
- func (client *Client) Stop()
- func (client *Client) ViewAccountHistory(account string, start time.Time, end time.Time) error
- func (client *Client) ViewAccounts() error
- type HistoryRecord
- func (record *HistoryRecord) BalanceFromString(value string) error
- func (record *HistoryRecord) CreditFromString(value string) error
- func (record *HistoryRecord) DateFromString(value string) error
- func (record *HistoryRecord) DebitFromString(value string) error
- func (record *HistoryRecord) DescriptionFromString(value string) error
- func (record *HistoryRecord) TypeFromString(value string) error
Constants ¶
const ( DefaultLoginUrl = "https://onlinebanking.tdbank.com/" AccountBalanceSelector = "table[id=Table2] span, table[id=AccountBalanceSection] span" AccountHistorySelector = "table.td-table.td-table-stripe-row.td-table-hover-row.td-table-border-column tbody" )
Variables ¶
var ( DefaultHandlers = map[string]func(*HistoryRecord, string) error{ "Date": (*HistoryRecord).DateFromString, "Type": (*HistoryRecord).TypeFromString, "Description": (*HistoryRecord).DescriptionFromString, "Debit": (*HistoryRecord).DebitFromString, "Credit": (*HistoryRecord).CreditFromString, "Account Balance": (*HistoryRecord).BalanceFromString, } )
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth struct { LoginUrl string Username string Password string SecurityQuestions map[string]string }
An Auth holds the URL of the login page, a username and password, and answers to the security questions. The Login() method needs this information.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Client represents a virtual web browser. It holds pointers to the Chrome web driver and the current page. Most functions in this package are implemented as methods of client, because they always need a web browser.
func (*Client) GetHtml ¶
GetHtml returns the HTML for the current web page as a string. This is useful in a pinch for debugging.
func (*Client) Login ¶
Login connects to the TD Bank login page and logs in with the supplied username and password. If it notices any of the security questions it was given, then it supplies the answer. When this method returns, the browser should be at the main accounts page.
func (*Client) ParseAccountBalance ¶
ParseAccountBalance assumes that the browser is on the account history page for the desired account, and looks within the current page for an account balance. It parses the balance as a 64-bit integer giving the amount in pennies.
func (*Client) ParseAccountHistory ¶
func (client *Client) ParseAccountHistory() ([]HistoryRecord, error)
ParseAccountHistory assumes the browser is on the account history page, and looks within the page for a table of transactions. It reads each one off the page into a HistoryRecord struct. If some struct fields aren't found in the table (such as a running account balance), then it makes a reasonable effort to calculate them and fill them in anyway.
func (*Client) PrintHtml ¶
func (client *Client) PrintHtml()
PrintHtml prints the HTML for the current web page. This is handy if something breaks, and you want to inspect the page where something went wrong.
func (*Client) Start ¶
func (client *Client) Start()
Start launches a virtual browser -- i.e., it initializes a Chrome web driver and launches Chrome with a blank page. The work is done by agouti, which in turn runs chromedriver, so you may want to set up chromedriver to your liking. For example you might want to put a wrapper (named chromedriver) on your path that launches Chrome in headless mode.
func (*Client) Stop ¶
func (client *Client) Stop()
Stop shuts down the web driver and the Chrome process. You want to make sure you call Stop every time you call Start, or else Chrome processes will continue running after your Go program exits. The usual way to do this is:
var client tdbank.Client; client.Start() defer client.Stop()
func (*Client) ViewAccountHistory ¶
ViewAccountHistory clicks on the provided account name, and then enters the provided start and end dates to view all transactions between those two dates (inclusive). This method assumes that the browser is on the main accounts page already, so if in doubt you should call ViewAccounts first.
func (*Client) ViewAccounts ¶
ViewAccounts takes the browser back to the main accounts page.
type HistoryRecord ¶
type HistoryRecord struct { Index int Date time.Time Type string Description string Debit int64 Credit int64 Balance int64 }
A HistoryRecord contains one line from an account history. TD Bank includes different fields for credit accounts (i.e., credit cards) and debit accounts (e.g., checking accounts). Other methods in this package make reasonable efforts to fill in missing fields -- for example, by computing a running balance if the account history doesn't show one.
func (*HistoryRecord) BalanceFromString ¶
func (record *HistoryRecord) BalanceFromString(value string) error
BalanceFromString attempts to parse the string as a monetary value and, if successful, stores it in the HistoryRecord's Balance field. The value is parsed as an integer number of pennies.
func (*HistoryRecord) CreditFromString ¶
func (record *HistoryRecord) CreditFromString(value string) error
CreditFromString attempts to parse the string as a monetary value and, if successful, stores it in the HistoryRecord's Credit field. The value is parsed as an integer number of pennies.
func (*HistoryRecord) DateFromString ¶
func (record *HistoryRecord) DateFromString(value string) error
DateFromString attempts to parse the string as a date and, if successful, stores it in the HistoryRecord's Date field.
func (*HistoryRecord) DebitFromString ¶
func (record *HistoryRecord) DebitFromString(value string) error
DebitFromString attempts to parse the string as a monetary value and, if successful, stores it in the HistoryRecord's Debit field. The value is parsed as an integer number of pennies.
func (*HistoryRecord) DescriptionFromString ¶
func (record *HistoryRecord) DescriptionFromString(value string) error
DescriptionFromString stores the string in the HistoryRecord's Description field. The string first has any leading or trailing whitepace removed.
func (*HistoryRecord) TypeFromString ¶
func (record *HistoryRecord) TypeFromString(value string) error
TypeFromString stores the string in the HistoryRecord's Type field. The string first has any leading or trailing whitepace removed.