-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpage.go
73 lines (64 loc) · 1.77 KB
/
page.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package edgar
import (
"fmt"
"io"
"log"
"net/http"
)
var (
baseURL = "https://www.sec.gov/"
cikURL = "https://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&output=xml&CIK=%s"
queryURL = "cgi-bin/browse-edgar?action=getcompany&CIK=%s&type=%s&dateb=&owner=exclude&count=10"
searchURL = baseURL + queryURL
)
func createQueryURL(symbol string, docType FilingType) string {
return fmt.Sprintf(searchURL, symbol, docType)
}
func getPage(url string) io.ReadCloser {
resp, err := http.Get(url)
if err != nil {
log.Fatal("Query to SEC page ", url, "failed: ", err)
return nil
}
return resp.Body
}
func getCompanyCIK(ticker string) string {
url := fmt.Sprintf(cikURL, ticker)
r := getPage(url)
if r != nil {
if cik, err := cikPageParser(r); err == nil {
return cik
}
}
return ""
}
// getFilingLinks gets the links for filings of a given type of filing 10K/10Q..
func getFilingLinks(ticker string, fileType FilingType) map[string]string {
url := createQueryURL(ticker, fileType)
resp := getPage(url)
if resp == nil {
log.Println("No response on the query for docs")
return nil
}
defer resp.Close()
return queryPageParser(resp, fileType)
}
//Get all the docs pages based on the filing type
//Returns a map:
// key=Document type ex.Cash flow statement
// Value = link to that that sheet
func getFilingDocs(url string, fileType FilingType) map[filingDocType]string {
url = baseURL + url
resp := getPage(url)
if resp == nil {
return nil
}
defer resp.Close()
return filingPageParser(resp, fileType)
}
// getFinancialData gets the data from all the filing docs and places it in
// a financial report
func getFinancialData(url string, fileType FilingType) (*financialReport, error) {
docs := getFilingDocs(url, fileType)
return parseMappedReports(docs, fileType)
}