-
Notifications
You must be signed in to change notification settings - Fork 0
/
getPapers.go
95 lines (89 loc) · 2.29 KB
/
getPapers.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
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"encoding/json"
"io"
"log"
"net/http"
"net/url"
"os"
"strconv"
"strings"
)
func getJournal(apistring string) string {
req, err := url.Parse("https://m2.mtmt.hu/" + apistring)
if err != nil {
log.Fatalln(err)
return ""
}
resp, err := http.Get(req.String())
if err != nil {
log.Fatalln(err)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
journalResponse := JournalResponse{}
err = json.Unmarshal([]byte(body), &journalResponse)
if err != nil {
log.Fatalln(err)
}
return strings.Title(strings.ToLower(journalResponse.Content.Title))
}
func getJournals(papers []Paper) []Paper {
marshalledjson, _ := os.ReadFile("journalmap.json")
journalmap := make(map[string]string)
json.Unmarshal(marshalledjson, &journalmap)
for i, paper := range papers {
if title, ok := journalmap[paper.Journal]; ok {
papers[i].Journal = title
} else {
title := getJournal(paper.Journal)
journalmap[paper.Journal] = title
papers[i].Journal = title
}
}
marshalledjson, _ = json.Marshal(journalmap)
_ = os.WriteFile("journalmap.json", marshalledjson, 0644)
return papers
}
func getPapers(mtmtResponse MtmtResponse, userMtid string) []Paper {
var papers []Paper
for index, content := range mtmtResponse.Content {
var doi string
for _, identifier := range content.Identifiers {
if identifier.Source.Label == "DOI" {
doi = identifier.RealUrl
if doi == "" {
doi = "https://doi.org/" + strings.Split(identifier.Label, " ")[0]
}
}
}
var authors []Author
mtid_asint, _ := strconv.Atoi(userMtid)
for author_i, author := range content.Authorships {
if author.Type.Mtid == 1 {
authors = append(authors, Author{
Index: author_i,
FamilyName: author.FamilyName,
GivenName: author.GivenName,
IsUser: author.Author.Mtid == mtid_asint,
})
}
}
paper := Paper{
Mtid: content.Mtid,
Index: index,
Title: content.Title,
Year: content.Year,
Citation: content.Citation,
IndependentCitation: content.IndependentCitation,
Doi: doi,
Authors: authors,
Journal: content.Journal.Link,
Sjr: content.Sjr,
}
papers = append(papers, paper)
}
return papers
}