citationSheetParse.js 5.85 KB
Newer Older
Joe TS Dell's avatar
update  
Joe TS Dell committed
1
2
3
4
5
//
// begining of xlsx to json coversion
//

var jsonContent = [];
6
7
8
var bibAuthors = "";
var bit1stAuthorLN ="";

Joe TS Dell's avatar
update  
Joe TS Dell committed
9

10

Joe TS Dell's avatar
update  
Joe TS Dell committed
11
/* set up XMLHttpRequest */
Sini's avatar
Sini committed
12
var url = "./content/CitationSheet3.xlsx";
Joe TS Dell's avatar
update  
Joe TS Dell committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open("GET", url, true);
xmlHttpRequest.responseType = "arraybuffer";
xmlHttpRequest.onload = function (e) {
    var arraybuffer = xmlHttpRequest.response;

    // convert data to binary string //
    var data = new Uint8Array(arraybuffer);
    var arr = new Array();
    for (var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
    var bstr = arr.join("");

    // Call XLSX //
    var workbook = XLSX.read(bstr, {
        type: "binary"
    });

    // DO SOMETHING WITH workbook HERE //
    var first_sheet_name = workbook.SheetNames[0];
    // Get worksheet //
    var worksheet = workbook.Sheets[first_sheet_name];

    var jsonOutput = XLSX.utils.sheet_to_json(worksheet);
Sini's avatar
Sini committed
36
    // console.log(jsonOutput);
Joe TS Dell's avatar
update  
Joe TS Dell committed
37
38

    for (i = 0; i < jsonOutput.length; i++) {
Sini's avatar
Sini committed
39
40
41
42
        var authors;
        if (jsonOutput[i].Authors != undefined){
            authors = jsonOutput[i].Authors.replace("and ", "").trim().split(",");
        }
43
        var bibAuthors;
Joe TS Dell's avatar
update  
Joe TS Dell committed
44
45
46
47
48
49
50
51
52
53
54
        var item = {
            "item": {
                "title": "",
                "project": "",
                "authors": [],
                "imageLink": "",
                "keywords": "",
                "journal": {
                    "name": "journal",
                    "volume": "",
                    "year": "",
Sini's avatar
Sini committed
55
                    "month": "",
Joe TS Dell's avatar
update  
Joe TS Dell committed
56
57
                    "pages": ""
                },
Sini's avatar
Sini committed
58
59
60
61
62
63
64
65
66
67
68
69
                "conference":{
                    "name":"",
                    "place":"",
                    "date":""
                },
                "DOI": "",
                "publisher":"",
                "type":"",
                "project":"",
                "reviewed":"",
                "open":""

Joe TS Dell's avatar
update  
Joe TS Dell committed
70
71
72
73
74
            },
            "links": {
                "pdf": "",
                "url": "",
                "demo": ""
75
76
            },
            "bibtex" : ""
Joe TS Dell's avatar
update  
Joe TS Dell committed
77
78
        }

79
80
81
        
        bibAuthors = "";
        bit1stAuthorLN ="";
Joe TS Dell's avatar
update  
Joe TS Dell committed
82
83
84
85
86
87
88
89
90
        for (j = 0; j < authors.length; j++) {
            var author = {
                "firstName": "",
                "lastName": ""
            }
            if (authors[j].trim().split(" ").length == 1) {
                author["firstName"] = authors[j].trim().split(".")[0];
                author["lastName"] = authors[j].trim().split(".")[1];
                item["item"].authors.push(author);
91
                bibAuthors+=authors[j].trim().split(".")[1] + ", "+ authors[j].trim().split(".")[0]+ " and ";
Joe TS Dell's avatar
update  
Joe TS Dell committed
92
93
94
95
            } else if (authors[j].trim().split(" ").length == 2) {
                author["firstName"] = authors[j].trim().split(" ")[0];
                author["lastName"] = authors[j].trim().split(" ")[1];
                item["item"].authors.push(author);
96
                bibAuthors+=authors[j].trim().split(" ")[1] + ", "+ authors[j].trim().split(" ")[0]+ " and ";
Joe TS Dell's avatar
update  
Joe TS Dell committed
97
98
99
100
            } else if (authors[j].trim().split(" ").length == 3) {
                author["firstName"] = authors[j].trim().split(" ")[0];
                author["lastName"] = authors[j].trim().split(" ")[2];
                item["item"].authors.push(author);
101
                bibAuthors+=authors[j].trim().split(" ")[2] + ", "+ authors[j].trim().split(" ")[0]+ " and ";
Joe TS Dell's avatar
update  
Joe TS Dell committed
102
103
104
            }

        }
105
       
Joe TS Dell's avatar
update  
Joe TS Dell committed
106
107
108
109
110
        if (jsonOutput[i].Keywords != undefined) {
            item["item"].keywords = jsonOutput[i].Keywords.split(",");
        } else {
            item["item"].keywords = jsonOutput[i].Keywords;
        }
111
112
113
114
115
116
117
118
119
120
121
122

        if (authors[0].split(" ").length == 3 ){
            bit1stAuthorLN = authors[0].split(" ")[2];
        } else if (authors[0].split(" ").length == 2 ){
            bit1stAuthorLN = authors[0].split(" ")[1];
        } else if (authors[0].split(" ").length == 1 ){
            bit1stAuthorLN = authors[0].split(" ")[0];
        }

        item["item"].title = jsonOutput[i].Titel;
        item["item"].project = jsonOutput[i].Project;
        item["item"].imageLink = jsonOutput[i]["Path to demo image"]
Joe TS Dell's avatar
update  
Joe TS Dell committed
123
124
125
        item["item"].journal.name = jsonOutput[i].Journal;
        item["item"].journal.volume = jsonOutput[i].Volume;
        item["item"].journal.year = jsonOutput[i].Year;
Sini's avatar
Sini committed
126
127
128
129
130

        if (jsonOutput[i].Date != undefined){
            item["item"].journal.month = jsonOutput[i].Date.split(",")[0].trim();
        }

Joe TS Dell's avatar
update  
Joe TS Dell committed
131
        item["item"].journal.pages = jsonOutput[i].Pages;
Sini's avatar
Sini committed
132
133
134
135
136
137
138
139
        item["item"].conference.name = jsonOutput[i].Conference;
        item["item"].conference.place = jsonOutput[i]["City and Country"]
        item["item"].conference.date = jsonOutput[i].Date;
        item["item"].publisher = jsonOutput[i].Publisher;
        item["item"].type = jsonOutput[i]["Type of Work"];
        item["item"].project = jsonOutput[i].Project;
        item["item"].reviewed = jsonOutput[i]["Peer-Reviewed"];
        item["item"].open = jsonOutput[i]["Open Access"];
Joe TS Dell's avatar
update  
Joe TS Dell committed
140
        item["item"].DOI = jsonOutput[i].DOI;
Sini's avatar
Sini committed
141
        item["links"].pdf = jsonOutput[i].PDF_Link;
Joe TS Dell's avatar
update  
Joe TS Dell committed
142
        item["links"].url = jsonOutput[i].URL;
Sini's avatar
Sini committed
143
        item["links"].demo = jsonOutput[i].Demo;
Joe TS Dell's avatar
update  
Joe TS Dell committed
144

145
146
147
148
149
150
        //// BibTex /////////////////////
        item["bibtex"] = "@article{"+ bit1stAuthorLN + jsonOutput[i].Year +","+
        "title={"+ jsonOutput[i].Titel + 
        "},author={"+ bibAuthors.trim().substring(0, bibAuthors.trim().lastIndexOf(" ")) +
        "},journal={"+ jsonOutput[i].Journal +
        "},volume={"+ jsonOutput[i].Volume +
Sini's avatar
Sini committed
151
        // "},number={"+ jsonOutput[i].Number
152
153
154
155
156
157
        "},pages={"+ jsonOutput[i].Pages +
        "},year={"+ jsonOutput[i].Year +
        "},DOI ={"+ jsonOutput[i].DOI+
        "},url ={"+ jsonOutput[i].URL+
        "}}"

Joe TS Dell's avatar
update  
Joe TS Dell committed
158
159
160
        jsonContent.push(item);

    }
161
    console.log(jsonContent);
Joe TS Dell's avatar
update  
Joe TS Dell committed
162
163
164
165

}
xmlHttpRequest.send();

166
167
168
169

// str = str.substring(0, lastIndex);


Joe TS Dell's avatar
update  
Joe TS Dell committed
170
171
172
//
// ending of xlsx to json coversion
//