Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
1,265 additions
and
782 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
''' All codes in this file are extracted and editted from https://stackoverflow.com/questions/25798674/python-duplicate-words ''' | ||
def isRepeat(sentence): | ||
words = sentence.split(" ") | ||
words.sort() # ascending sorting | ||
|
||
# keep user original input | ||
words_copied = sentence.split(" ") | ||
words_copied.sort() | ||
|
||
wordL=[] | ||
'''Copied codes to loop through the sentence given.''' | ||
for word in words[0:len(words)-1]: | ||
count = 0 | ||
while True: | ||
try: | ||
index = words_copied.index(word) | ||
count += 1 | ||
del words_copied[index] | ||
except ValueError: | ||
if count > 1: | ||
wordL.append([word,count]) | ||
break | ||
'''Copied code ends''' | ||
if wordL != []: | ||
repeat=True | ||
else: | ||
repeat=False | ||
return repeat | ||
|
||
def CountRepeat(sentence): | ||
words = sentence.split(" ") | ||
words.sort() # ascending sorting | ||
|
||
# keep user original input | ||
words_copied = sentence.split(" ") | ||
words_copied.sort() | ||
|
||
wordL={} | ||
|
||
for word in words[0:len(words)-1]: | ||
count = 0 | ||
while True: | ||
try: | ||
index = words_copied.index(word) | ||
count += 1 | ||
del words_copied[index] | ||
except ValueError: | ||
if count > 1: | ||
wordL.update({word:count}) | ||
break | ||
if wordL != []: | ||
repeat=True | ||
else: | ||
repeat=False | ||
return wordL | ||
|
||
#sentence=input('Enter your sentence : ') | ||
#print(isRepeat(input())) | ||
#print(CountRepeat(sentence)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Sentences for responding the user | ||
MyDictionary={ | ||
"GREETING_KEYWORDS":["hello", "hi", "greetings", "sup", "what's up"], | ||
"GREETING_RESPONSES":["'sup bro", "hey", "*nods*", "hey you get my snap?"], | ||
"REFUSE":["no","nah","not"], | ||
"AGREE":["yes","sure","agreed","why not"], | ||
"EMOTION_POSITIVE":["happy","thrilled","enjoyed","yo","high spirits"], | ||
"EMOTION_NEGATIVE":["sad","blue","dissatisfied","heck","hell no"] | ||
} | ||
|
||
def ref(category): | ||
catName=[] | ||
for j,k in MyDictionary.items(): #listing a whole dictionary | ||
catName.append(j) | ||
for i in catName: | ||
if (category.upper()).strip() == i: | ||
return i | ||
if (category.upper()).strip() not in catName: | ||
return False | ||
|
||
|
||
|
||
'''Function checks if a value is in a specified dictionary''' | ||
def isRef(word): | ||
try: | ||
for j,k in MyDictionary.items(): #listing a whole dictionary | ||
for i in k: #looping through the dictionary | ||
for p in word.split(): | ||
if (p.lower()).strip()==i: | ||
return True | ||
else: | ||
continue | ||
continue | ||
continue | ||
except: | ||
print("Invalid input!") | ||
print("Type of i: ",type(i),";type of p: ",type(p)) | ||
else: | ||
return False | ||
|
||
#print(isRef(input("Test a word: "))) | ||
#print(ref(input("Test a word: "))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from MyDictionary import * | ||
def social(chat): | ||
import random | ||
try: | ||
user=input("Can you share your life with me? ") | ||
except: | ||
print("Invalid input!") | ||
else: | ||
for i in user.split(): | ||
if i.lower() in MyDictionary["REFUSE"] or i.lower() in MyDictionary["Emotion_negative"]: | ||
try: | ||
user=input("I'm so sorry affecting your bad mood. So do you want to leave, or stay with my other services?(leave/service) ") | ||
except: | ||
print("Invalid input!") | ||
else: | ||
for j in user.split(): | ||
if (str(j.lower())).strip() in ["leave"]: | ||
exit() | ||
elif (str(j.lower())).strip() in ["service"]: | ||
from main2 import main2 | ||
main2() | ||
else: | ||
print("I don't know what the hell are yo saying dude!!!") | ||
try: | ||
chat=input("Say again please: ") | ||
except: | ||
print("Invalid input!") | ||
else: | ||
social(chat) | ||
else: | ||
for j in user.split(): | ||
if str(j.lower()) in Emotion_positive: | ||
em=True | ||
break | ||
else: | ||
em=False | ||
continue | ||
print(em) | ||
res="I'm quite " | ||
from parrot import find_longest_word | ||
if em==True: | ||
print(res,"glad to hear that you are",find_longest_word(user.split()),".") | ||
else: | ||
try: | ||
user=input("Sorry what do you mean by ",find_longest_word(user.split()),"?") | ||
except: | ||
print("Invalid input!") | ||
finally: | ||
print(res,"disappointed to hear that you said",find_longest_word(user.split()),".") | ||
|
||
|
||
'''Greet each other''' | ||
def greet(): | ||
import random | ||
while True: | ||
res="" | ||
found=False | ||
try: | ||
user=input("Hello, what's up bro? ") | ||
for i in user.split(): | ||
if i.lower() in GREETING_KEYWORDS: | ||
print(GREETING_RESPONSES[random.randint(1,len(GREETING_RESPONSES))-1] ) # random generate a response based on user input | ||
found=True | ||
else: | ||
if i.index(user.split())<len(user.split())-1: | ||
continue | ||
else: | ||
found=False # return error | ||
while found==False: | ||
for j in user.split(): | ||
if j.lower() in (GREETING_KEYWORDS.lower()).strip(): # check if greeting words are in the user input | ||
res=GREETING_RESPONSES[random.randint(0,len(GREETING_RESPONSES-1))] # returns a greeting statement if yes | ||
found==True | ||
else: | ||
from Checkings import isRepeat,CountRepeat | ||
if isRepeat(user)==True: | ||
for k in range(0,len(CountRepeat(user))): | ||
print("Word '",CountRepeat(user)[k][0],"' has been repeated:",CountRepeat(user)[k][1]," times.") | ||
print("Response '",str(i),"' in '",str(user),"' not found sorry!") | ||
else: | ||
print("",end="") | ||
if found==True: | ||
break | ||
else: | ||
print("Error not found for: "+str(user)) | ||
user=input("Hello, what's up bro? ") | ||
except: # error exception | ||
print("Invalid input!") | ||
else: | ||
user=input("Are you feeling great with me today? ") # prompt to ask if user wants to start chatting | ||
status=True | ||
for i in user.split(): | ||
if i.lower() in REFUSE: # return to main menu | ||
from main2 import main2 | ||
main2() | ||
else: # start chatting | ||
print("Great! \n") | ||
social(user) | ||
'''Greeting part ends''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
""" | ||
Libraries: | ||
- requests (http://docs.python-requests.org/en/master/) by Kenneth Reitz for web requests | ||
""" | ||
import requests | ||
import xml.etree.ElementTree as ET | ||
|
||
""" Returns a dictionary of currencies and rates. Coded with help from https://docs.python.org/2/library/xml.etree.elementtree.html """ | ||
async def getCurrencyDictionary(): | ||
response = requests.get("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml").text | ||
root = ET.fromstring(response) | ||
curr={} | ||
for child in root[2][0]: | ||
curr[child.attrib["currency"]] = float(child.attrib["rate"]) | ||
curr["EUR"] = 1 | ||
curr["XDR"] = 1/(0.423 + 12.1*(1/curr["JPY"]) + 0.111*(1/curr["GBP"]) + 0.66*(1/curr["USD"])) | ||
return curr | ||
|
||
|
||
async def convertCurrency(to, base, amount): | ||
|
||
if amount <= 0: | ||
return amount | ||
|
||
currencies = await getCurrencyDictionary() | ||
return amount*currencies[to]/currencies[base] | ||
'''Code is written by Ben.''' | ||
|
||
|
||
""" | ||
Libraries: | ||
- requests (http://docs.python-requests.org/en/master/) by Kenneth Reitz for web requests | ||
""" | ||
import requests | ||
import xml.etree.ElementTree as ET | ||
|
||
""" Returns a dictionary of currencies and rates. Coded with help from https://docs.python.org/2/library/xml.etree.elementtree.html """ | ||
async def getCurrencyDictionary(): | ||
response = requests.get("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml").text | ||
root = ET.fromstring(response) | ||
curr={} | ||
for child in root[2][0]: | ||
curr[child.attrib["currency"]] = float(child.attrib["rate"]) | ||
curr["EUR"] = 1 | ||
curr["XDR"] = 1/(0.423 + 12.1*(1/curr["JPY"]) + 0.111*(1/curr["GBP"]) + 0.66*(1/curr["USD"])) | ||
return curr | ||
|
||
|
||
async def convertCurrency(to, base, amount): | ||
|
||
if amount <= 0: | ||
return amount | ||
|
||
currencies = await getCurrencyDictionary() | ||
return amount*currencies[to]/currencies[base] |
Oops, something went wrong.