-
Notifications
You must be signed in to change notification settings - Fork 0
/
samhsa.go
83 lines (67 loc) · 2.06 KB
/
samhsa.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
74
75
76
77
78
79
80
81
82
83
package main
import (
"fmt"
"log"
"github.com/PuerkitoBio/goquery"
)
func main() {
doc, err := goquery.NewDocument("http://www.samhsa.gov/medication-assisted-treatment/physician-program-data/certified-physicians?field_bup_us_state_code_value=All&page=1")
if err != nil {
log.Fatal(err)
}
linkmk()
// Find the review items
doc.Find("views-field views-field-field-bup-year-certified .field-content").Each(func(i int, s *goquery.Selection) {
// For each item found, get the year
fmt.Println(i)
state := s.Find("State:").Text()
docnum := s.Find("i").()
fmt.Printf("State %d: %v\n", state, i)
fmt.Println(state)
})
func linkmk() {
//creates URLS and writes different URLs as slices to 'urls'
for i := 0; i <= inRuns; i {
fmt.Println("making URL slices")
urlss := fmt.Sprintf("https://www.samhsa.gov/medication-assisted-treatment/physician-program-data/certified-physicians?field_bup_us_state_code_value=All&page=1
lurl := fmt.Sprintf("https://www.samhsa.gov/medication-assisted-treatment/physician-program-data/certified-physicians?field_bup_us_state_code_value=All&page=%s",
inPage)
urls = append(urls, lurl)
}
fmt.Println(urls[0])
//carries out execution of decoder and reader/writer
dataset := make([]Stat, 0, len(urls)*1)
fmt.Println("dataset made okay")
for _, lurl := range urls {
Currentdat := reader(inRuns, lurl)
dataset = append(dataset, Currentdat.Data...)
fmt.Println("appending...")
}
fmt.Println("trying write...")
writes(dataset, Filecsv)
fmt.Println("write done!")
}
//decodes retrieved JSON data for each URL
func reader(inRuns int, urls ...string) (Currentdat AutoGenerated) {
i := 0
response, err := http.Get(urls[i])
if err != nil {
log.Fatalf("failed to get JSON data: %v", err)
}
// defer response.Body.Close()
dec := json.NewDecoder(response.Body)
dec.UseNumber()
Currentdat = AutoGenerated{}
err = dec.Decode(&Currentdat)
if err != nil {
log.Fatalf("Failed to decode the JSON body: %v", err)
}
noter := string("looks good")
fmt.Println(noter, i)
i = 1
return Currentdat
}
*/
}
# DATA2000
# DATA2000