-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
73 lines (52 loc) · 2.29 KB
/
main.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 main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"opencoredata.org/csdcoMendeley/structs"
// "time"
)
func main() {
// url := "https://api.mendeley.com/documents?group_id=4cdf9c25-5a17-3644-8087-301999b5ba63&limit=50"
url := "https://api.mendeley.com/documents?group_id=4cdf9c25-5a17-3644-8087-301999b5ba63&limit=500"
req, _ := http.NewRequest("GET", url, nil)
// When getting a new token (every hour for some dumb reason) both the authorization and postman-token will change
req.Header.Add("authorization", "Bearer MSwxNDY0ODExNDU5MTM0LDE5NjQyMDEsMzE2MSxhbGwsLCxjOWQ0OTBjNWMzZDA1NTExY2I2ZDE2NmYyOTZjZjg1YjQwZTcxYWUtaCw5MzgyMDgxNi1lNTU3LTMzMmUtYjJkOS04ZDBhOGQ0MGQ1MGQsRXU3dFBSUlBCeEFnT3NBd0dKZElTbEIzSGlZ")
req.Header.Add("cache-control", "no-cache")
req.Header.Add("postman-token", "2c9cded0-a9a5-4032-7028-32d94e1972bb")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
docsStruct := structs.Mdocs{}
if err := json.Unmarshal(body, &docsStruct); err != nil {
panic(err)
}
for _, elem := range docsStruct {
doi := elem.Identifiers.Doi // pass along to dataset func to print out along with the file.
fmt.Println(doi)
dataset(elem.ID)
}
}
func dataset(id string) {
url := fmt.Sprintf("https://api.mendeley.com/documents/%s", id)
// fmt.Println(url)
req, _ := http.NewRequest("GET", url, nil)
// When getting a new token (every hour for some dumb reason) both the authorization and postman-token will change
req.Header.Add("authorization", "Bearer MSwxNDY0ODExNDU5MTM0LDE5NjQyMDEsMzE2MSxhbGwsLCxjOWQ0OTBjNWMzZDA1NTExY2I2ZDE2NmYyOTZjZjg1YjQwZTcxYWUtaCw5MzgyMDgxNi1lNTU3LTMzMmUtYjJkOS04ZDBhOGQ0MGQ1MGQsRXU3dFBSUlBCeEFnT3NBd0dKZElTbEIzSGlZ")
req.Header.Add("cache-control", "no-cache")
req.Header.Add("postman-token", "2c9cded0-a9a5-4032-7028-32d94e1972bb")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
docStruct := structs.Mdoc{}
if err := json.Unmarshal(body, &docStruct); err != nil {
log.Println(err)
}
// Now that is unmarshalled we can add in the DOI and then
// re-marshall to JSON .. prety it and send it out to a file.
fmt.Printf("ID: %s\n", docStruct.ID)
fmt.Printf("Tag: %s\n", docStruct.Tags)
fmt.Printf("Abstract: %s\n\n", docStruct.Abstract)
}