-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
386 lines (358 loc) · 10.4 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
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
// GopherPEDS main file with GUI (USPTO)
// Copyright (C) 2021 Vinz Frauchiger
//
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of the License, or any later version.
// v0.13.0 List Processor!
package main
import (
"fmt"
"log"
"os"
"strconv"
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
canvas2 "fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
)
// Versioning!
var ReleaseVersion string = "0.13.0 Process!"
func modifyText(rawText string) string {
// Function removes Country Code and Kind Code from Patent Number
if strings.ToUpper(rawText[:2]) == "US" {
rawText = rawText[2:]
}
l := len(rawText)
if strings.ToUpper(string(rawText[l-2])) == "A" || strings.ToUpper(string(rawText[l-2])) == "B" {
rawText = rawText[:l-2]
} else if strings.ToUpper(string(rawText[l-1])) == "A" {
rawText = rawText[:l-1]
}
return rawText
}
func removeChars(rawText string) string {
// Function removes unwanted chars from a string
rawText = strings.ReplaceAll(rawText, "/", "")
rawText = strings.ReplaceAll(rawText, "-", "")
rawText = strings.ReplaceAll(rawText, " ", "")
return rawText
}
func treatEarlAppNumb(pubnum string) string {
// this function checks for the correct length and
// the correct kind code
l := len(pubnum)
if l == 14 {
pubnum = pubnum[:6] + "0" + pubnum[6:]
}
if pubnum[l-2:] == "AA" {
pubnum = pubnum[:l-2] + "A1"
} else if pubnum[l-2:] == "AB" {
pubnum = pubnum[:l-2] + "A2"
}
return pubnum
}
func chooseDirectory(w fyne.Window, h *widget.Label) {
dialog.ShowFolderOpen(func(dir fyne.ListableURI, err error) {
save_dir = "$HOME"
if err != nil {
dialog.ShowError(err, w)
return
}
if dir != nil {
fmt.Println(dir.Path())
save_dir = dir.Path() // here value of save_dir shall be updated!
}
fmt.Println(save_dir)
h.SetText(save_dir)
}, w)
}
func chooseFile(w fyne.Window, fname *widget.Label) {
dialog.ShowFileOpen(func(file fyne.URIReadCloser, err error) {
if file == nil {
return
}
fileP := file.URI().Path()
if err != nil {
fmt.Println(err)
}
fmt.Println(fileP)
fname.SetText(fileP)
file.Close()
}, w)
}
//Variables
var save_dir string = "$HOME"
var theApplId2 string = ""
//
// MAIN
//
func main() {
a := app.New()
w := a.NewWindow("USPTO PEDS Tool Go!")
hello := widget.NewLabel("Hello Dude!")
hello.TextStyle = fyne.TextStyle{Bold: true}
progress := widget.NewProgressBar()
progress.SetValue(0)
labApplId := widget.NewLabel("Application ID")
inpApplId := widget.NewEntry()
inpApplId.SetPlaceHolder("12321123")
labPatentNum := widget.NewLabel("Patent Number")
inpPatentNum := widget.NewEntry()
inpPatentNum.SetPlaceHolder("7123456 or 11321123")
labEarlPubNum := widget.NewLabel("Early Publication Number")
inpEarlPubNum := widget.NewEntry()
inpEarlPubNum.SetPlaceHolder("Us20080123456A1")
// Check "Turbo Mode"
checkTurbo := widget.NewCheck("Turbo", func(value bool) {
fmt.Println(value)
})
// images
//image := canvas2.NewImageFromFile("gopherli.png")
image := canvas2.NewImageFromResource(resourceGopherliPng)
image.FillMode = canvas2.ImageFillOriginal
//imageYps := canvas2.NewImageFromFile("Ypsomed_big.png")
imageYps := canvas2.NewImageFromResource(resourceYpsomedbigPng)
imageYps.FillMode = canvas2.ImageFillOriginal
labTitle := widget.NewLabelWithStyle(
"GopherPEDS",
fyne.TextAlignCenter,
fyne.TextStyle{Bold: true},
)
labCopyRight := widget.NewLabelWithStyle(
"© Vinz Frauchiger, 2021",
fyne.TextAlignCenter,
fyne.TextStyle{Bold: true},
)
labExclPatents := widget.NewLabelWithStyle(
" Proudly for Ypsomed Patents!",
fyne.TextAlignCenter,
fyne.TextStyle{Italic: true},
)
// Button Application ID
butTermApplID := widget.NewButton("Get Term Ext.", func() {
modifiedText := modifyText(inpApplId.Text)
modifiedText = removeChars(modifiedText)
termdays, discl, _, err := GetTermDisc("applId", modifiedText)
if err != nil {
log.Fatal(err)
}
if discl == "" {
discl = "No terminal disclaimer found!"
}
if termdays == "" {
termdays = "0"
}
hello.SetText(termdays + " days and " + discl)
})
butWrapApplId := widget.NewButton("Get FileWrapper", func() {
modifiedText := modifyText(inpApplId.Text)
modifiedText = removeChars(modifiedText)
hello.SetText(modifiedText)
fmt.Println(checkTurbo.Checked)
_, _, theApplId, err := GetTermDisc("applId", modifiedText)
if err != nil {
hello.SetText("wrong number format!")
} else if theApplId == "number!" {
hello.SetText("wrong number!(kind code?)")
} else {
theApplId2 = theApplId
hello.SetText("Getting FileWrapper for " + theApplId2)
err = GetFileWrapperMulti(theApplId2, save_dir, progress, checkTurbo.Checked)
if err != nil {
fmt.Println(err)
}
}
})
butApplLatClaims := widget.NewButton("Get Latest Claims", func() {
modifiedText := modifyText(inpApplId.Text)
modifiedText = removeChars(modifiedText)
hello.SetText(modifiedText)
discNumber(modifiedText, "applId", save_dir, progress)
})
// Buttons Patents
butPatNumTerm := widget.NewButton("Get Term Ext.", func() {
var termMonths float64
modifiedText := modifyText(inpPatentNum.Text)
modifiedText = removeChars(modifiedText)
hello.SetText(modifiedText)
termdays, discl, theApplId, err := GetTermDisc("patentNumber", modifiedText)
if err != nil {
log.Fatal(err)
}
theApplId2 = theApplId
if discl == "" {
discl = "No terminal disclaimer found!"
}
if termdays == "" {
termdays = "0"
}
// convert term extension from days to months.
termMonths, err = strconv.ParseFloat(termdays, 64)
termMonths = termMonths / 365.25 * 12.0
if err != nil {
log.Fatal(err)
}
hello.SetText(termdays + " days (" + fmt.Sprintf("%.1f", termMonths) + "months) and " + discl + " / ApplID " + theApplId)
})
butPatNumWrap := widget.NewButton("Get FileWrapper for Patent", func() {
modifiedText := modifyText(inpPatentNum.Text)
modifiedText = removeChars(modifiedText)
hello.SetText(modifiedText)
_, _, theApplId, err := GetTermDisc("patentNumber", modifiedText)
if err != nil {
hello.SetText("wrong number format!")
} else if theApplId == "number!" {
hello.SetText("wrong number!(kind code?)")
} else {
theApplId2 = theApplId
hello.SetText("Getting FileWrapper for " + theApplId2)
err = GetFileWrapperMulti(theApplId2, save_dir, progress, checkTurbo.Checked)
if err != nil {
fmt.Println(err)
}
}
})
butPatLatClaims := widget.NewButton("Get Latest Claims", func() {
modifiedText := modifyText(inpPatentNum.Text)
modifiedText = removeChars(modifiedText)
hello.SetText(modifiedText)
discNumber(modifiedText, "patentNumber", save_dir, progress)
})
// Buttons Early Publication
butEarlPubNumTerm := widget.NewButton("Get Term Ext.", func() {
modifiedText := removeChars(inpEarlPubNum.Text)
modifiedText = strings.ToUpper(modifiedText)
modifiedText = treatEarlAppNumb(modifiedText)
hello.SetText(modifiedText)
termdays, discl, theApplId, err := GetTermDisc("appEarlyPubNumber", modifiedText)
if err != nil {
fmt.Println(termdays, discl, theApplId, err)
}
if discl == "" {
discl = "No terminal disclaimer found!"
}
if termdays == "" {
termdays = "not granted yet!"
}
hello.SetText(termdays + " days and " + discl + " / " + theApplId)
})
butEarlPubNumWrap := widget.NewButton("Get FileWrapper Publ", func() {
modifiedText := removeChars(inpEarlPubNum.Text)
modifiedText = strings.ToUpper(modifiedText)
modifiedText = treatEarlAppNumb(modifiedText)
hello.SetText(modifiedText)
_, _, theApplId, err := GetTermDisc("appEarlyPubNumber", modifiedText)
if err != nil {
hello.SetText("wrong number format!")
} else if theApplId == "number!" {
hello.SetText("wrong number!(kind code?)")
} else {
theApplId2 = theApplId
hello.SetText("Getting FileWrapper for " + theApplId2)
err = GetFileWrapperMulti(theApplId2, save_dir, progress, checkTurbo.Checked)
if err != nil {
hello.SetText(err.Error())
}
}
})
butEarlPubLatClaims := widget.NewButton("Get Latest Claims", func() {
modifiedText := removeChars(inpEarlPubNum.Text)
modifiedText = strings.ToUpper(modifiedText)
modifiedText = treatEarlAppNumb(modifiedText)
hello.SetText(modifiedText)
discNumber(modifiedText, "appEarlyPubNumber", save_dir, progress)
})
fmt.Println(checkTurbo.Checked)
//button for directory to save to
labSavDir := widget.NewLabel("$HOME")
butSaveDir := widget.NewButton("Get Save Directory!", func() {
chooseDirectory(w, labSavDir) // Text of hello updated by return value
})
//
// List processor
labListProc := widget.NewLabel("no file chosen")
butListProc := widget.NewButton("Get File", func() {
chooseFile(w, labListProc)
})
butGoList := widget.NewButton("Go List Proc.", func() {
publicationList := LoadExcel(labListProc.Text)
fmt.Println(publicationList)
text := labListProc.Text
response := ManageList(w, labListProc, publicationList, text)
fmt.Println(response)
})
// CONTENT
content := container.NewVBox(
container.NewHBox(
image,
container.NewVBox(
labTitle,
labCopyRight,
labExclPatents,
imageYps,
widget.NewLabelWithStyle(
"Version: "+ReleaseVersion,
fyne.TextAlignCenter,
fyne.TextStyle{Italic: true},
),
),
),
widget.NewSeparator(),
widget.NewLabel("Find Output below:"),
widget.NewSeparator(),
hello,
widget.NewSeparator(),
labApplId,
inpApplId,
container.NewHBox(
butTermApplID,
butWrapApplId,
butApplLatClaims,
),
labPatentNum,
inpPatentNum,
container.NewHBox(
butPatNumTerm,
butPatNumWrap,
butPatLatClaims,
),
labEarlPubNum,
inpEarlPubNum,
container.NewHBox(
butEarlPubNumTerm,
butEarlPubNumWrap,
butEarlPubLatClaims,
),
widget.NewSeparator(),
widget.NewLabel("Please not that the list processor takes (early & patent) publication numbers only!"),
container.NewHBox(
widget.NewLabel("File List Proc."),
labListProc,
widget.NewSeparator(),
butListProc,
butGoList,
),
widget.NewSeparator(),
container.NewHBox(
widget.NewLabel("Directory to which the files are saved: "),
widget.NewSeparator(),
layout.NewSpacer(),
widget.NewSeparator(),
checkTurbo,
),
labSavDir,
butSaveDir,
progress,
widget.NewSeparator(),
widget.NewButton("Quit", w.Close))
w.SetContent(content)
w.Resize(fyne.NewSize(800, 800))
w.ShowAndRun()
w.SetOnClosed(func() {
os.Exit(1)
})
}