def _update_tag(self, book_id): if self._execute: tags=prompt('Please enter TAGs (BLANK separator)') book['tags'] = tags.split() result = self._ePubs.updateField(rec=book, fld_name='tags') if result.matched_count: C.pCyanH(text='tags {0} have been added'.format(book['tags']), tab=4) self._book_indexing(book, fields=['tags']) print() else: C.pCyanH(text='in DRY-RUN mode, tag setting not available', tab=4) prompt()
def delete(): print('delete') prompt()
def update(): print('update') prompt()
def search(): print('search') prompt()
#!/usr/bin/python3 # # updated by ...: Loreto Notarantonio # Version ......: 11-10-2020 17.06.02 # import sys sys.dont_write_bytecode = True import os from pathlib import Path from types import SimpleNamespace import pyaml from lnLib.colorLN import LnColor C = LnColor() from lnLib.promptLN import prompt prompt(gVars={"color": LnColor()}) from lnLib.loggerLN import setLogger import lnLib.monkeyPathLN as PathLN import lnLib.monkeyBenedictLN # per caricare i miei metodi from Source.parseInputLN import parseInput from lnLib.configurationLoader import LoadConfigFile from lnLib.resolveDictVars import ResolveDictVars from Source.eBooksLN import eBooksLN """ inp_list=[ {index { title: title, tags: tags }} {index { title: title, tags: tags }} {index { title: title, tags: tags }}
def _displayResults(self, book, data): # data=' '.join(book['content']) # occurrencies=regEx.FindIter(pattern, data=data, fPRINT=False) # result=self._color_words_in_text(data, occurrencies) ''' Sample { "word1": {"counter": 1 }, "word2": {"counter": 1 }, "data": { "1": ["Lee Child"], "2": ["Child pippo"], } } ''' dis_data = data.pop('data', []) words = data.keys() choice = '' _max = len(dis_data) _min = 0 _step=4 _from=_min # - prepard book info display data dmBook=DotMap(book, _dynamic=False) # di comodo dis_line=[] dis_line.append('') dis_line.append('book: {dmBook.title} - [{dmBook.author}]'.format(**locals())) dis_line.append(' - id: {dmBook._id}'.format(**locals())) dis_line.append(' - tags: {dmBook.tags}'.format(**locals())) for word in words: counter = data[word]['counter'] dis_line.append(' - word: {word} - instances: {counter}'.format(**locals())) while True: if choice=='b': break # return to book_list # - display book metadata for line in dis_line: C.pYellowH(text=line, tab=8) ''' Display data. ruoto all'interno della lista visualizzando [step] results per volta''' # - set range to display menu if _from>=_max: _from=_max-_step if _from<0: _from=0 _to = _from+_step if _to>_max: _to=_max # - display data for index in range(_from, _to): item = dis_data[index+1] print('{0:5} - {1}'.format(index+1, item[0])) for line in item[1:]: print(' '*7, line) print() # - Get keybord input choice=prompt('[n]ext [p]rev [b]ooks_list [t]ag', validKeys='n|p|b|t') if choice in ['b']: break elif choice in ['n']: _from+=_step elif choice in ['p']: _from-=_step elif choice in ['t']: if self._execute: tags=prompt('Please enter TAGs (BLANK separator)') book['tags'] = tags.split() result = self._ePubs.updateField(rec=book, fld_name='tags') if result.matched_count: C.pCyanH(text='tags {0} have been added'.format(book['tags']), tab=4) self._book_indexing(book, fields=['tags']) print() else: C.pCyanH(text='in DRY-RUN mode, tag setting not available', tab=4) prompt()
def _display_occurrencies_DELETE(self, book, occurrencies): ''' Sample { "word1": {"counter": 1 }, "word2": {"counter": 1 }, "data": { "1": ["Lee Child"], "2": ["Child pippo"], } } {'word1': [ (2553, 2561), (2678, 3456) ] } ''' words = occurrencies.keys() choice = '' # scelta menu _max = len(occurrencies) _max = 5 _min = 0 _step=4 inx_from=_min # - prepard book info display data nsBook=SimpleNamespace(**book) # di comodo dis_line=[] dis_line.append('') dis_line.append(f'book: {nsBook.title} - [{nsBook.author}]') dis_line.append(f' - id: {nsBook._id}') dis_line.append(f' - tags: {nsBook.tags}') result=[] for word in words: positions=occurrencies[word] """ numero di occurrencies per ogni word """ counter = len(occurrencies[word]) dis_line.append(f' - item: {word} - instances: {counter}') for pos in positions: # incr counter for specific word # result[word]['counter'] += 1 # counter += 1 # counter totale # - get text around the found word _from=0 if pos-_before<0 else pos-_before _to=pos+word_len+_after text=item[_from:_to].replace('\n', ' ') new_text = ' '.join(text.split()) # remove multiple blanks ''' new_text=text.replace(cur_word, colored_word) # no good perché case-sensitive redata = re.compile(re.escape(cur_word), re.IGNORECASE) new_text = redata.sub(colored_word, text) ''' # replace word(s) with colored_word # ruotiamo sulle word in modo da colorarle # se fossero presenti nello stesso testo for i, w in enumerate(words): colored_word = colors[i](text=w, get=True) new_text = re.sub(w, colored_word, new_text, flags=re.IGNORECASE) # - wrap text to easy displaying tb=textwrap.wrap(new_text, 80, break_long_words=True) # - save it into result list result['data'][counter] = [] result['data'][counter].extend(tb) if fPRINT: for l in tb: print(' ', l) print() while True: if choice=='b': break # return to book_list # - display book metadata for line in dis_line: C.pYellowH(text=line, tab=8) ''' Display data. ruoto all'interno della lista visualizzando [step] results per volta ''' # - set range to display menu if inx_from>=_max: inx_from=_max-_step if inx_from<0: inx_from=0 inx_to = inx_from+_step if inx_to>_max: inx_to=_max # - display data for index in range(inx_from, inx_to): item = items[index+1] print('{0:5} - {1}'.format(index+1, item[0])) for line in item[1:]: print(' '*7, line) print() # - Get keybord input choice=prompt('[n]ext [p]rev [b]ooks_list [t]ag', validKeys='n|p|b|t') if choice in ['b']: break elif choice in ['n']: inx_from+=_step elif choice in ['p']: inx_from-=_step elif choice in ['t']: if self._execute: tags=prompt('Please enter TAGs (BLANK separator)') book['tags'] = tags.split() result = self._ePubs.updateField(rec=book, fld_name='tags') if result.matched_count: C.pCyanH(text='tags {0} have been added'.format(book['tags']), tab=4) self._book_indexing(book, fields=['tags']) print() else: C.pCyanH(text='in DRY-RUN mode, tag setting not available', tab=4) prompt()