-
Notifications
You must be signed in to change notification settings - Fork 1
/
archivegrid.go
364 lines (311 loc) · 11.3 KB
/
archivegrid.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
package main
import (
"crypto/md5"
"fmt"
"io"
"strings"
)
type AGDEBUG int
const (
EMPTY AGDEBUG = iota
INPROGRESS
FOUNDNOTVALIDATEDYET
FOUNDANDNOTVALIDATED
FOUNDANDVALIDATED
//TOOMANYRESULTS
//NORESULTS
//ACCEPTABLERESULTS
)
type AGOrganization struct {
orgId int
name string
contact_information string
}
type AGRecord struct {
Dom string
URL_rec_x string
}
type AGRecordTitle struct {
Dom string
href string
description string
}
type AGRecordAuthor struct {
Dom string
href string
description string
}
type AGRecordArchive struct {
Dom string
href string
description string
}
type AGRecordSummary struct {
Dom string
href string
description string
}
type AGRecordLinksContactInformation struct {
Dom string
href string
description string
}
const ArchiveGridRecordSTRINGNULL = "NODATAFOUND"
//type ArchiveGridRecord struct {
// Id HashSum `json:"id"`
// MusicianId HashSum `json:"musician_id"`
// Query MusicianQuery `json:"musician_query"`
// ResultSize bool `json:"is_found"`
// RecordCollectionDataPath AGRecord `json:"record"`
// Title AGRecordTitle `json:"record_title"`
// Author AGRecordAuthor `json:"record_author"`
// Archive AGRecordArchive `json:"record_archive"`
// Summary AGRecordSummary `json:"record_summary"`
// LinksContactInformation AGRecordLinksContactInformation `json:"record_links_contact_information"`
// DebugNotes AGDEBUG `json:"debug_notes"`
//}
type ArchiveGridRecord struct {
Id HashSum `json:"id"`
MusicianId HashSum `json:"musician_id"`
Query MusicianQuery `json:"musician_query"`
ResultCount int `json:"result_count"`
IsMatch bool `json:"is_match"`
RecordCollectionDataPath string `json:"record_collection_datapath"`
Title string `json:"record_title"`
Author string `json:"record_author"`
Archive string `json:"record_archive"`
Summary string `json:"record_summary"`
LinksContactInformation string `json:"links_contact_information"`
ContactInformation string `json:"contact_information"`
DebugNotes AGDEBUG `json:"debug_notes"`
}
func (agr *ArchiveGridRecord) PrimaryKey() string {
return fmt.Sprintf("PRIMARYKEY=%s%s", agr.MusicianId, agr.Query)
}
//func (agr ArchiveGridRecord) String() string {
// return fmt.Sprintf("{ RECORDID%sMUSICIAN%s__%s_in_%s }", agr.Id, agr.MusicianId, agr.Query, agr.Archive.href)
//}
func (agr *ArchiveGridRecord) String() string {
return fmt.Sprintf("{ RECORDID%sMUSICIAN%s__%s_in_%s }", agr.Id, agr.MusicianId, agr.Query, agr.Archive)
}
func (agr *ArchiveGridRecord) ToJson() string {
return fmt.Sprintf("{\"ag_record_id\": %q, \n\"musician_id\": %q, \n\"query\": %q, \n}",
agr.Id, agr.MusicianId, agr.Query)
}
//func (agr ArchiveGridRecord) ToCsv() string {
// return fmt.Sprintf("%s; %s; %s; %s", agr.Id, agr.MusicianId, agr.Query, agr.Archive.href)
//}
func (agr *ArchiveGridRecord) ToCsv() string {
return fmt.Sprintf("%q; %q; %q; %d; %q; %q; %q; %q; %q; %q; %q; %q\n",
agr.Id,
agr.MusicianId,
agr.Query,
agr.ResultCount,
agr.RecordCollectionDataPath,
agr.Title,
agr.Author,
agr.Archive,
agr.Summary,
agr.LinksContactInformation,
agr.ContactInformation,
agr.DebugNotes)
}
func (agr ArchiveGridRecord) Hash() HashSum {
hashfunc := md5.New()
data := agr.PrimaryKey()
io.WriteString(hashfunc, data)
hashsum := hashfunc.Sum(nil)
return HashSum(fmt.Sprintf("%x", hashsum))
}
func NewArchiveGridRecord(musicianId HashSum, query MusicianQuery) (archiveGridRecord *ArchiveGridRecord) {
archiveGridRecord = new(ArchiveGridRecord)
archiveGridRecord = &ArchiveGridRecord{
MusicianId: musicianId,
Query: query,
ResultCount: -1,
//RecordCollectionDataPath: ArchiveGridRecordSTRINGNULL,
//Title: AGRecordTitle,
//Author: AGRecordAuthor,
//Archive: AGRecordArchive,
//Summary: AGRecordSummary,
//LinksContactInformation: AGRecordLinksContactInformation,
}
archiveGridRecord.Id = archiveGridRecord.Hash()
return archiveGridRecord
}
func (agr *ArchiveGridRecord) Destroy() {
agr.Id = ""
agr.MusicianId = ""
agr.Query = MusicianQuery{}
agr.ResultCount = 0
agr.IsMatch = false
agr.RecordCollectionDataPath = ""
agr.Title = ""
agr.Author = ""
agr.Archive = ""
agr.Summary = ""
agr.LinksContactInformation = ""
agr.ContactInformation = ""
agr.DebugNotes = AGDEBUG(0)
return
}
func (agr *ArchiveGridRecord) Set(record, title, author, archive, summary, link, contact string) {
agr.IsMatch = false
agr.RecordCollectionDataPath = record
agr.Title = title
agr.Author = author
agr.Archive = archive
agr.Summary = summary
agr.LinksContactInformation = link
agr.ContactInformation = contact
agr.DebugNotes = AGDEBUG(FOUNDNOTVALIDATEDYET)
}
func (agr *ArchiveGridRecord) ContainsAnyFolded(phrases []string) (matches int) {
if len(phrases) < 1 {
return -1
}
for _, phrase := range phrases {
p := strings.ToLower(phrase)
//log.Printf("A PHRASE %s", p)
//WaitForKeypress()
if strings.Contains(strings.ToLower(agr.Title), p) {
matches++
//WaitForKeypress()
}
if strings.Contains(strings.ToLower(agr.Author), p) {
matches++
//WaitForKeypress()
}
if strings.Contains(strings.ToLower(agr.Archive), p) {
matches++
//WaitForKeypress()
}
if strings.Contains(strings.ToLower(agr.Summary), p) {
matches++
//WaitForKeypress()
}
if strings.Contains(strings.ToLower(agr.ContactInformation), p) {
matches++
//WaitForKeypress()
}
}
return matches
}
//
type AGDomPaths struct {
Record string
RecordCollectionDataPath string // AGRecord.Dom
Title string // AGRecordTitle.Dom
Author string // AGRecordAuthor.Dom
Archive string // AGRecordArchive.Dom
Summary string // AGRecordSummary.Dom
LinksContactInformation string // AGRecordLinksContactInformation.Dom
ContactInformation string
Results string
ResultsNotEmpty string
ResultsEmpty string
ResultsSize string
ResultsSizeMessage string
ResultsNext string
}
var AGDomPathsDefinition = AGDomPaths{
Record: "div.record",
RecordCollectionDataPath: "input[value]", // container->archivegrid collection data path "div.record > input[value]",
Title: "div.record_title > h3 > a[title]", // h3>a href THEN $inner_text "div.record_title > h3 > a[title]"
Author: "div.record_author span[itemprop]", // span[itemprop="name"] THEN $inner_text "div.record_author span[itemprop]"
Archive: "div.record_archive span[itemprop]", // span[itemprop="name"] THEN $inner_text "div.record_archive span[itemprop]"
Summary: "div.record_summary", // THEN $inner_text
LinksContactInformation: "div.record_links > a[href]", // a href ANDALSO "div.record_links > a[href]"
ContactInformation: "div.record_links > a[title]", // a ANDALSO title "div.record_links > a[title]"
Results: "div.results",
ResultsNotEmpty: "div.results div.searchresult",
ResultsEmpty: "div.results div.alertresult",
ResultsSize: "resultsize", // "main h2 > span[id=resultsize]", // "main > h2", // "main h2 > span#resultsize"
ResultsSizeMessage: "div.navtable > div.navrow > div.navrowright > span",
ResultsNext: ".results .navtable .navrow a[title=\"View the Next page of results\"]", // get the href
}
//type AGResults struct {
// Results string
// ResultsNotEmpty string //div.results > div.searchresults
// ResultsEmpty string // div.results > div.alertresult
// ResultsSize string // span#resultsize
// ResultsSizeMessage string
// ResultsNext string
//}
//var AGResultsDefinition = AGResults{
// Results: "div.results",
// ResultsNotEmpty: "div.results > div.searchresult",
// ResultsEmpty: "div.results > div.alertresult",
// ResultsSize: "main > h2", // "main h2 > span#resultsize"
// ResultsSizeMessage: ".navrow span",
// ResultsNext: ".results .navtable .navrow a[title=\"View the Next page of results\"]", // get the href
//}
// type ArchiveGridRecord struct {
// RecId int
// RecordCollectionDataPath AGRecord
// Title AGRecordTitle
// Author AGRecordAuthor
// Archive AGRecordArchive
// Summary AGRecordSummary
// LinksContactInformation AGRecordLinksContactInformation
// }
//
/*
main
...
span#resultsize
$text
div.results
div.alertresult
div
text " No ArchiveGrid collection descriptions match this search:"
div.results
div.searchresult
div #rec_x .record
input type="hidden" #url_rec_x value="/archivegrid/collection/data/nnnnnnnn"
div itemprop="name" .record_title
h3
a
href="/archivegrid/collection/data/same"
$here text collection data title
/a
div itemprop="author" .record_author
span itemprop="name"
$here text author
div itemprop="contributor" .record_archive
span itemprop="name"
$here text archive name
div .record_summary
$here text summary
div .record_links
a href="/archivegrid/contact-information/nnn" title="$here text about archive org"
a href="/archivegrid/collection/data/samennnnn" <-- ignoring this one for now
*/
//
////
//var AGDomPathsDefinition = AGDomPaths{
// RecordCollectionDataPath: "div.record", // container
// Title: "div.record_title > h3 > a", // h3>a href ANDTHEN $inner_text
// Author: "div.record_author", // span THEN $inner_text
// Archive: "div.record_archive", // span THEN $inner_text
// Summary: "div.record_summary", // THEN $inner_text
// LinksContactInformation: "div.record_links", // a href ANDALSO title
//}
//
////
//
//var ARCHIVE_GRID_BASE_URL = "https://researchworks.oclc.org/archivegrid"
//var AG_BASE_URL, _ = url.Parse(ARCHIVE_GRID_BASE_URL)
//log.Printf("INFO: %v", AG_BASE_URL)
//
//// type ArchiveGridRecord struct {
//// RecId int
//// RecordCollectionDataPath AGRecord
//// Title AGRecordTitle
//// Author AGRecordAuthor
//// Archive AGRecordArchive
//// Summary AGRecordSummary
//// LinksContactInformation AGRecordLinksContactInformation
//// }
//
////