-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
48 lines (40 loc) · 1.11 KB
/
main.go
File metadata and controls
48 lines (40 loc) · 1.11 KB
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
package main
import (
"fmt"
"funfunviz/database"
"funfunviz/sec"
"log"
)
func main() {
db := database.InitDB("funfunviz.db")
defer db.Close()
fmt.Println("Database initialized.")
// Clear the database to avoid duplicates
if err := database.ClearStatements(db); err != nil {
log.Fatal(err)
}
// Fetch company facts for Apple
facts, err := sec.GetCompanyFacts("320193")
if err != nil {
log.Fatal(err)
}
// Insert the facts into the database
if err := database.InsertFacts(db, facts); err != nil {
log.Fatal(err)
}
fmt.Printf("Successfully fetched and stored data for %s\n", facts.EntityName)
// Query and display the financials
financials, err := database.QueryFinancials(db)
if err != nil {
log.Fatal(err)
}
fmt.Println("\n--- Stored Financials ---")
for _, f := range financials {
fmt.Printf("Company: %s (CIK: %s)\n", f.Company, f.CIK)
fmt.Printf(" Revenue: %.2f\n", f.Revenue)
fmt.Printf(" Net Income: %.2f\n", f.NetIncome)
fmt.Printf(" Operating Expenses: %.2f\n", f.OperatingExpenses)
fmt.Printf(" Cost of Goods Sold: %.2f\n", f.COGS)
}
fmt.Println("-------------------------")
}