-
Notifications
You must be signed in to change notification settings - Fork 3
/
stringManipulation.py
49 lines (38 loc) · 1.5 KB
/
stringManipulation.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
'''
Created by Vassilis Antonakakis on 20/10/2022
'''
import weatherReport
def strReconstruct(partsList, index):
tempTerm = ""
while(len(partsList) > index):
if partsList[index] == "-" or partsList[index] == "+":
tempTerm = " " + tempTerm + partsList[index]
else: tempTerm = tempTerm + partsList[index] + " ";
index = index + 1
tempTerm = tempTerm.strip()
return tempTerm
def commandParser(command):
if "exact request" in command:
tokenList = command.split()
tempCommand = tokenList[0] + " " + tokenList[1]
tokenList[0] = tempCommand
tempTerm = strReconstruct(tokenList, 2)
tokenList[1] = tempTerm
elif "request" in command:
tokenList = command.split(" ",1)
if "exclude" in tokenList[1]:
tempTokenList = tokenList[1].split(" ")
for index in range(len(tempTokenList)-1):
if tempTokenList[index] == "exclude":
tempTokenList[index] = "-"
tokenList[1] = strReconstruct(tempTokenList, 0)
if "include" in tokenList[1]:
tempTokenList = tokenList[1].split(" ")
for index in range(len(tempTokenList)-1):
if tempTokenList[index] == "include":
tempTokenList[index] = "+"
tokenList[1] = strReconstruct(tempTokenList, 0)
return tokenList
elif "weather" in command:
weatherReport.getWeather(command)
#commandTokenizer("get weather")