Documentation
¶
Overview ¶
A web scraper for the Social Security Administration's life expectancy calculation.
Given a gender code ("m" or "f") and a date of birth in YYYY-MM-DD format, it will do a POST request to the Social Security Administrations website using the format defined by its [Life Expectancy Calculator], parse the response, and return the result.
Index ¶
Constants ¶
const ( ISO_FORMAT = "2006-01-02" Float64EqualityThreshold = 1e-9 )
const ( SSA_URL = "https://www.ssa.gov/cgi-bin/longevity.cgi" TIMEOUT = 15 )
Variables ¶
This section is empty.
Functions ¶
func DoRequest ¶ added in v1.5.0
DoRequest accepts the two required parameters (sex and date of birth) and issues a POST request to the SSA website. It then parses the HTML returned and creates a Response object with what it parses.
func ParseCurrentAge ¶
ParseCurrentAge finds an age value in a string. This can be a simple integer: "68" or a combination of years and month(s): ("68 and 3 months")
func ParseFloat ¶
ParseFloat converts a string to a float, ignoring any errors
Types ¶
type Response ¶
type Response struct {
CurrentAge float64
AdditionalYears float64
TotalYears float64
DeathDate time.Time
}
Response is a structure that contains the results of parsing a response.
func ParseResponse ¶
ParseResponse parses the response HTML to get the desired output. The section of interest is this:
Inside <table ... summary="life expectancy table" after the first <tr>...</tr> ...
<tr><td style="text-align:left">68 and 6 months<sup>a</sup></td> <td>16.5</td> <td>85.0</td></tr>