-
Notifications
You must be signed in to change notification settings - Fork 1
/
input_parser.py
55 lines (43 loc) · 1.45 KB
/
input_parser.py
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
"""
Author: Marko Njegomir sw-38-2018
"""
def parse_input():
unos = input("Search googolplex($ at the end for autocomplete): ")
if not unos:
print("You have to type in something. Please try again.")
any_input_to_continue()
return
unos = unos.strip()
if not unos:
print("You have to type in something. Please try again.")
any_input_to_continue()
return
if unos == ":q" or unos == ":wq" or unos == ":q!" or unos == ":x" or unos == ":qa":
return ("exit", unos)
if unos[0] == "\"":
unos = unos.replace("\"", "")
unos = unos.strip()
print("You entered a phrase {}".format(unos))
return ("phrase", unos)
lista_reci = unos.lower().split(" ")
if "and" in lista_reci or "or" in lista_reci or "not" in lista_reci:
for i in range(len(lista_reci)):
lista_reci[i] = lista_reci[i].strip()
return ("logical", unos)
if lista_reci[-1]:
if lista_reci[-1][-1] == "$":
return ("autocomplete", unos)
return ("regular", unos)
def next_page_input():
unos = input("Press n for next, and b for back <pdf to export><x to search again>")
if not unos.strip():
return 1
if unos.lower().strip() == "x":
return 0
if unos.lower().strip() == "b":
return -1
if unos.lower().strip() == "pdf":
return 2
return 1
def any_input_to_continue():
input("Press any key to continue.")