Skip to content

Commit b5bfab9

Browse files
committed
Try for memento_all
1 parent a96c47c commit b5bfab9

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

memento_all.py

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import os
2+
import sys
3+
from subprocess import call
4+
5+
from image_make import image_make_main
6+
from tess_ocr.ocr_orientation import ocr_orientation_main
7+
from tess_ocr.ocr_rename import ocr_rename_main
8+
from tess_ocr.ocr_save import ocr_save_main
9+
10+
VALIDITY = [".jpg",".gif",".png",".tga",".tif",".bmp"]
11+
12+
class ArgumentMissingException(Exception):
13+
def __init__(self):
14+
print("usage: {} <dirname>".format(sys.argv[0]))
15+
sys.exit(1)
16+
17+
def check_path(path):
18+
return bool(os.path.exists(path)) #Checkif path exists
19+
20+
def main(path):
21+
call(['clear'])
22+
j = 1
23+
i = 0
24+
if call(['which', 'tesseract']): #Run the command described by args
25+
print("tesseract-ocr missing") #No tesseract installed
26+
while(True):
27+
sys.stdout.write("\t\t\t Memento: Meme Organizer \t \n\n")
28+
sys.stdout.write("Files in Directory: \t \n\n")
29+
30+
if check_path(path):
31+
arr = os.listdir(path)
32+
for f in arr:
33+
ext = os.path.splitext(f)[1]
34+
if ext.lower() in VALIDITY:
35+
print('[' + str(j) + ']' + ' ' + f )
36+
j +=1
37+
38+
else :
39+
print("No directory : " + format(path))
40+
41+
print('\nChoose one or all: ')
42+
file = input()
43+
if file == 'all':
44+
prompt = " [1/2/3/4/5]: "
45+
sys.stdout.write("\n")
46+
sys.stdout.write(' 1) Orientation Check \n 2) Rename file \n 3) Save OCR \n 4) Edit text \n 5) Exit \n (Can you multiple inputs)' + prompt)
47+
choice = input()
48+
while (i != len(choice)):
49+
print ('\n\t\t\t Current Choice: ' + choice[i] + '\n')
50+
if choice[i] == '1':
51+
ocr_orientation_main(path)
52+
print(" Orientation Check DONE!! \n")
53+
elif choice[i] == '2':
54+
ocr_rename_main(path)
55+
print("Rename to identified text DONE!! \n")
56+
elif choice[i] == '3':
57+
ocr_save_main(path)
58+
print("Save the OCR to /OCR-text/ DONE!! \n")
59+
elif choice[i] == '4':
60+
image_make_main(path)
61+
print("Edit the text in image DONE!! \n")
62+
elif choice[i] == '5':
63+
print("\t\t\t Thank you for using Memento!")
64+
sys.exit(1)
65+
elif choice[i] == ' ':
66+
print("Chosing Next! \n")
67+
else:
68+
sys.stdout.write("Invalid Choice \n")
69+
i += 1
70+
71+
if __name__ == '__main__': #Execute all code before reading source file, ie. execute import, evaluate def to equal name to main
72+
if len(sys.argv) != 2: # Count number of arguments which contains the command-line arguments passed to the script if it is not equal to 2 ie for (py main.py 1_arg 2_arg)
73+
raise ArgumentMissingException
74+
path = sys.argv[1] #python main.py "path_to/img_dir" ie the argv[1] value
75+
path = os.path.abspath(path) #Accesing filesystem for Return a normalized absolutized version of the pathname path
76+
main(path)
77+
#s = memento(path)
78+
#s.main(path) # Def main to path

0 commit comments

Comments
 (0)