|
@ -47,7 +47,7 @@ def insert_linebreaks(string, linelength): |
|
|
count += 1 |
|
|
count += 1 |
|
|
return new |
|
|
return new |
|
|
|
|
|
|
|
|
def printNow(query, results, results_count): |
|
|
def printNow(query, results): |
|
|
if connected == True: |
|
|
if connected == True: |
|
|
printerpath = check_printer_path() |
|
|
printerpath = check_printer_path() |
|
|
try: |
|
|
try: |
|
@ -58,31 +58,25 @@ def printNow(query, results, results_count): |
|
|
print(escpos['justify_center'], file=print_pointer, flush=True) |
|
|
print(escpos['justify_center'], file=print_pointer, flush=True) |
|
|
|
|
|
|
|
|
printed = False |
|
|
printed = False |
|
|
|
|
|
results_count = 0 |
|
|
if results_count == None or results_count == 'None': |
|
|
|
|
|
results_count = 0 |
|
|
|
|
|
results_count_max = results_count + 5 |
|
|
|
|
|
current_count = 0 |
|
|
|
|
|
for x, document in results.items(): |
|
|
for x, document in results.items(): |
|
|
for n, sentence in enumerate(document['matches']): |
|
|
for n, sentence in enumerate(document['matches']): |
|
|
if current_count == results_count: |
|
|
if results_count < 4: |
|
|
printed = True |
|
|
results_count += 1 |
|
|
if results_count < results_count_max: |
|
|
sentence = str(sentence) # Turn Flask Markup object back to normal python string |
|
|
results_count += 1 |
|
|
sentence = char_swap(sentence) |
|
|
sentence = str(sentence) # Turn Flask Markup object back to normal python string |
|
|
query = char_swap(query) |
|
|
sentence = char_swap(sentence) |
|
|
sentence = sentence.replace('\n', ' ').replace(' ', ' ') |
|
|
query = char_swap(query) |
|
|
pattern = r'[\s\W\_]'+query+r'[\s\W\_\n]|^'+query+'|'+query+'$' |
|
|
sentence = sentence.replace('\n', ' ').replace(' ', ' ') |
|
|
match = re.search(pattern, sentence, flags=re.IGNORECASE) |
|
|
pattern = r'[\s\W\_]'+query+r'[\s\W\_\n]|^'+query+'|'+query+'$' |
|
|
if match: |
|
|
match = re.search(pattern, sentence, flags=re.IGNORECASE) |
|
|
match = match.group() |
|
|
if match: |
|
|
sentence_splitted = re.compile(match).split(sentence) # find the query in the sentence, and split the sentence up |
|
|
match = match.group() |
|
|
for i, part in enumerate(sentence_splitted): |
|
|
sentence_splitted = re.compile(match).split(sentence) # find the query in the sentence, and split the sentence up |
|
|
if n == 0: # first sentence of this document |
|
|
for i, part in enumerate(sentence_splitted): |
|
|
if i == 0: # start of a new sentence |
|
|
if n == 0: # first sentence of this document |
|
|
print('', file=print_pointer, flush=True) |
|
|
if i == 0: # start of a new sentence |
|
|
linebreak = ''' ** |
|
|
print('', file=print_pointer, flush=True) |
|
|
|
|
|
linebreak = ''' ** |
|
|
|
|
|
** /** ** |
|
|
** /** ** |
|
|
//** /** ** |
|
|
//** /** ** |
|
|
************** |
|
|
************** |
|
@ -90,23 +84,23 @@ def printNow(query, results, results_count): |
|
|
** /** //** |
|
|
** /** //** |
|
|
// /** // |
|
|
// /** // |
|
|
// ''' |
|
|
// ''' |
|
|
print(linebreak, file=print_pointer, flush=True) # print line break ascii art |
|
|
print(linebreak, file=print_pointer, flush=True) # print line break ascii art |
|
|
print('\n', file=print_pointer, flush=True) |
|
|
print('\n', file=print_pointer, flush=True) |
|
|
title = insert_linebreaks(document['name'], 13) |
|
|
title = insert_linebreaks(document['name'], 13) |
|
|
print(escpos['largefont'], title, escpos['normalfont'], file=print_pointer, flush=True) # print the document name |
|
|
print(escpos['largefont'], title, escpos['normalfont'], file=print_pointer, flush=True) # print the document name |
|
|
print('\n', file=print_pointer, flush=True) |
|
|
print('\n', file=print_pointer, flush=True) |
|
|
|
|
|
|
|
|
# start of sentence |
|
|
# start of sentence |
|
|
part = insert_linebreaks(part, 35) |
|
|
part = insert_linebreaks(part, 35) |
|
|
print(part, file=print_pointer, flush=True) # print current part of sentence |
|
|
print(part, file=print_pointer, flush=True) # print current part of sentence |
|
|
|
|
|
|
|
|
if i + 1 != len(sentence_splitted): # if this part is not the last one |
|
|
if i + 1 != len(sentence_splitted): # if this part is not the last one |
|
|
print(escpos['bold'], match, escpos['reset'], file=print_pointer, flush=True) # print query |
|
|
print(escpos['bold'], match, escpos['reset'], file=print_pointer, flush=True) # print query |
|
|
|
|
|
|
|
|
# line breaker after each sentence |
|
|
# line breaker after each sentence |
|
|
if i + 1 == len(sentence_splitted): |
|
|
if i + 1 == len(sentence_splitted): |
|
|
print('\n | \n', file=print_pointer, flush=True) |
|
|
print('\n | \n', file=print_pointer, flush=True) |
|
|
sleep(3) |
|
|
sleep(3) |
|
|
|
|
|
|
|
|
current_count += 1 |
|
|
current_count += 1 |
|
|
|
|
|
|
|
@ -124,12 +118,9 @@ def printNow(query, results, results_count): |
|
|
results_count = 0 |
|
|
results_count = 0 |
|
|
# printNow(query, results, results_count) |
|
|
# printNow(query, results, results_count) |
|
|
|
|
|
|
|
|
return results_count |
|
|
|
|
|
|
|
|
|
|
|
except: |
|
|
except: |
|
|
e = sys.exc_info()[0] |
|
|
e = sys.exc_info()[0] |
|
|
print("Could not print: {}".format(e)) |
|
|
print("Could not print: {}".format(e)) |
|
|
return 0 |
|
|
|
|
|
|
|
|
|
|
|
# query = 'noise' |
|
|
# query = 'noise' |
|
|
# results, _, _ = readings.request_results(query) |
|
|
# results, _, _ = readings.request_results(query) |
|
|