forked from Scriptkiddi/anknotes
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanknotes_start_note_validation.py
More file actions
114 lines (97 loc) · 4.54 KB
/
anknotes_start_note_validation.py
File metadata and controls
114 lines (97 loc) · 4.54 KB
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
import os
from anknotes import stopwatch
from anknotes.imports import import_etree
import time
if import_etree():
try:
from pysqlite2 import dbapi2 as sqlite
except ImportError:
from sqlite3 import dbapi2 as sqlite
from anknotes.imports import lxml, etree
### Anknotes Module Imports for Stand Alone Scripts
from anknotes import evernote as evernote
### Anknotes Shared Imports
from anknotes.shared import *
from anknotes.error import *
from anknotes.toc import TOCHierarchyClass
### Anknotes Class Imports
from anknotes.AnkiNotePrototype import AnkiNotePrototype
from anknotes.EvernoteNoteTitle import generateTOCTitle
### Anknotes Main Imports
from anknotes.Anki import Anki
from anknotes.ankEvernote import Evernote
# from anknotes.EvernoteNoteFetcher import EvernoteNoteFetcher
# from anknotes.EvernoteNotes import EvernoteNotes
# from anknotes.EvernoteNotePrototype import EvernoteNotePrototype
# from anknotes.EvernoteImporter import EvernoteImporter
#
# ### Evernote Imports
# from anknotes.evernote.edam.notestore.ttypes import NoteFilter, NotesMetadataResultSpec
# from anknotes.evernote.edam.type.ttypes import NoteSortOrder, Note as EvernoteNote
from anknotes.evernote.edam.error.ttypes import EDAMSystemException, EDAMUserException, EDAMNotFoundException
# from anknotes.evernote.api.client import EvernoteClient
def mk_banner(fn, display_initial_info=False):
l.default_filename = fn
my_info_str = info_str % l.default_filename.upper()
myTmr = stopwatch.Timer(len(queued_items[fn]), 10, infoStr=my_info_str, do_print=True, label=l.base_path,
display_initial_info=display_initial_info)
l.go("------------------------------------------------", clear=True)
l.go(my_info_str)
l.go("------------------------------------------------")
return myTmr
ankDBSetLocal()
db = ankDB(TABLES.NOTE_VALIDATION_QUEUE)
db.Init()
queued_items = {'Failed': db.all("validation_status = -1"),
'Pending': db.all("validation_status = 0"),
'Successful': db.all("validation_status = 1")}
info_str = 'CHECKING {num} %s MAKE NOTE QUEUE ITEMS'
l = Logger('Validation\\validate_notes\\', rm_path=True, do_print=True, timestamp=False)
tmr = mk_banner('Successful')
for result in queued_items[l.default_filename]:
line = (" [%-30s] " % ((result['guid']) + ':')) if result['guid'] else "NEW [%-30s] " % ''
line += result['title']
l.go(line)
tmr = mk_banner('Failed')
for result in queued_items[l.default_filename]:
line = '%-60s ' % (result['title'] + ':')
line += (" [%-30s] " % ((result['guid']) + ':')) if result['guid'] else "NEW"
line += '\n' + result['validation_result']
l.go(line)
l.go("------------------------------------------------\n")
l.go(result['contents'])
l.go("------------------------------------------------\n")
EN = Evernote()
tmr = mk_banner('Pending', display_initial_info=True)
timerFull = stopwatch.Timer()
for result in queued_items[l.default_filename]:
guid = result['guid']
noteContents = result['contents']
noteTitle = result['title']
line = (" [%-30s] " % ((result['guid']) + ':')) if result['guid'] else "NEW [%-30s] " % ''
errors = tmr.autoStep(EN.validateNoteContent(noteContents, noteTitle), noteTitle)
validation_status = 1 if tmr.status.IsSuccess else -1
line = " SUCCESS! " if tmr.status.IsSuccess else " FAILURE: "
line += ' ' if result['guid'] else ' NEW '
# line += ' %-60s ' % (result['title'] + ':')
l.dump(errors, 'LXML ERRORS', 'lxml_errors', wrap_filename=False, crosspost_to_default=False)
if not tmr.status.IsSuccess:
if not is_str_type(errors):
errors = '\n * ' + '\n * '.join(errors)
l.go(line + errors)
else:
if not is_str_type(errors):
errors = '\n'.join(errors)
sql = "UPDATE {t} SET validation_status = ?, validation_result = ? WHERE "
data = [validation_status, errors]
if guid:
sql += "guid = ?"
data += [guid]
else:
sql += "title = ? AND contents = ?"
data += [noteTitle, noteContents]
db.execute(sql, data)
timerFull.stop()
l.go("Validation of %d results completed in %s" % (tmr.max, str(timerFull)))
db.commit()
db.close()