Skip to content
Permalink
Browse files
Add files via upload
  • Loading branch information
plurab committed Nov 21, 2018
1 parent d74adce commit 228411b065c2aaab9bb1b37f768f74945c49b670
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 0 deletions.
@@ -0,0 +1,37 @@
import os
def setup_time():
exists = os.path.isfile("settings.txt")
if not exists:
f = open("settings.txt", "w+")
print("")
name = input("What shall I call you: ")
city = input("Which city are you in: ")
f.write("name:" + name + "\n")
f.write("city:" + city + "\n")
f.write("state:complete")
f.close()
else:
settings_file = open("settings.txt")
for setting in settings_file:
if "state:complete" in setting:
settings_file.close()
break
def reset():
exists = os.path.isfile("settings.txt")
if exists:
os.remove("settings.txt")
setup_time()
def load_setting(arg):
settings_file = open("settings.txt")
if arg == 0:
for setting in settings_file:
if "name:" in setting:
name = setting.replace('name:','')
settings_file.close()
return name
elif arg == 1:
for setting in settings_file:
if "city:" in setting:
city = setting.replace('city:','')
settings_file.close()
return city
@@ -0,0 +1,13 @@
from fbchat import Client
from fbchat.models import *
def facebook(word):
login=input("facebook login: ")
password=input('Password: ')
friend=input('which friend: ')
message=input('message: ')
client=Client(login,password)
frienduid=client.searchForUsers(friend)
uiid=frienduid[0].uid
client.send(Message(text=message), thread_id=uiid, thread_type=ThreadType.USER)
print ('sent')

@@ -0,0 +1,14 @@
import random
import time
greetings = {"hello": ["Hey how are you?", "Whats up?", "Welcome"], "hey": ["Welcome", "How may i help you?"],
"sup": ["Wagwan bro", "Whats good?", "Welcome"], "hi": ["Hey how are you?", "Whats up?", "Welcome"]}
# While loop......
def respond(ck):
if ck in greetings:
response = random.choice(greetings[ck])
print(response)
else:
print(".......Sorry i did not quite get that")



@@ -0,0 +1,6 @@
helps= ("Available commands are: "
"\n1) weather in [city]/ weather for [city] :"" Tells you the weather forcast in the city you typed."
"\n2) facebook message: facebook"
"\n3) youtube search: youtube + keywords"
"\n4) whatsapp message: appmessage"
"\n5) 'bye' to turn me off")
12 how.py
@@ -0,0 +1,12 @@
from wiki import wikiSearch

def sentence_how(sentence):
if "you" in sentence:
if "are" in sentence:
print("I'm good, how are you?")
elif "call" in sentence:
print("The Perfect")
elif "answer" in sentence:
print("It's The foreigners' magic")
else:
wikiSearch(sentence)
@@ -0,0 +1,80 @@
from what import sentence_what
from why import sentence_why
from weather import weather_ask
from Setup import setup_time
from Setup import reset
from Setup import load_setting
from who import sentence_who
from greetings import respond
from help import helps
from facebook import facebook
from youtube import youtube
from how import sentence_how
from whatsapp import whatsapp
global name
global city

def check(sentence):
if "why" in sentence:
sentence_why(sentence)
elif "weather in" in sentence or "weather for" in sentence or "weather today" in sentence:
if "weather today" not in sentence:
temporary,Lcity = sentence.split('weather')
Lcity = Lcity.replace('in ', '')
Lcity = Lcity.replace('for ', '')
weather_ask(Lcity)
else:
sentence = city
weather_ask(sentence)
elif "exit" in sentence or 'bye' in sentence or 'see you' in sentence:
global running
running = False
elif "facebook" in sentence:
facebook(sentence)
elif "!setup" in sentence:
reset()
elif "who" in sentence:
sentence_who(sentence)
elif 'how' in sentence:
sentence_how(sentence)
elif "hello" in sentence or "sup" in sentence or "hey" in sentence or "hi" in sentence:
respond(sentence)
elif "what" in sentence or "wiki" in sentence:
sentence_what(sentence)
elif "youtube" in sentence or "play" in sentence:
youtube(sentence)
elif "appmessage" in sentence:
whatsapp(sentence)
elif "funny" in sentence or "interesting" in sentence:
print("")
elif 'fine' in sentence:
print ("Nice to hear that :)")
elif "!help" in sentence:
print (helps)
elif 'thank' in sentence:
print ("You're welcome")
elif 'no you' in sentence:
print ('Yes, I am')
elif 'rude' in sentence or 'vulgar' in sentence:
print ("But, It's the truth")
elif 'foreigners' in sentence:
print("Alan, Andre, Artur, Bartosz, Premo, Zeid")
elif "bartosz" in sentence or "andre" in sentence or "premo" in sentence or "zeid" in sentence or "alan" in sentence or "zrtur" in sentence:
print("I love him")
else:
print("I don't understand, type !help to see what I can")
reset()
running = True
setup_time()
name = load_setting(0)
city = load_setting(1)
print("How can I help you, " + name + '?')
while running:
query = input("")
query = query.lower()
if "!setup" in query:
check(query)
name = load_setting(0)
city = load_setting(1)
else:
check(query)
@@ -0,0 +1,15 @@
import requests

def weather_ask(word):
try:
city = word
url = 'http://api.openweathermap.org/data/2.5/weather?q=' + city + '&APPID=f7d590dc5f61801f09e17f3922567a55'
res = requests.get(url)
data = res.json()
temp = data['main']['temp']
temp_C = temp - 273.15
weather_description = data['weather'][0]['description']
print('Temperature is: ', round(temp_C, 1), 'degree and', weather_description)
except:
print("Invalid command this is used by typing the following: weather in [city] OR weather for [city] where [city] is replaced with the city you want to find the weather for")

46 what.py
@@ -0,0 +1,46 @@
import random
from wiki import wikiSearch
def sentence_what(ck):
operations = ["+", "plus", "-", "minus", "/", "devised", "divided", "*", "x", "times"]
""" Function to get ChatBot information related to WHAT questions """
if "your" in ck:
# name related questions
if "last name" in ck:
answer = ["My last name is Foreigners", "My last name is B", "My last name is C", "My last name is D"]
print(random.choice(answer))
elif "middle name" in ck:
print("My middle names are Made By The")
elif "full name" in ck:
print("My name is ChatBot Made By The Foreigners")
elif "name" in ck:
print("My name is ChatBot")
# personal related questions
elif "favourite" in ck:
if "colour" in ck:
word = "colour"
answer = ["obviously red.", "red.", " for the 100 time, red! You have a memory of a fish."]
print("My favourite " + word + " is " + random.choice(answer))
elif "song" or "music" in ck:
if "type" or "kind" or "genre" in ck:
answer = ["I love all of them", "I don't want to share this with you",
"If i tell you I would have to kill you"]
print(random.choice(answer))
else:
answer = ["I don't listen to music very often, so I can't answer to that question.", "I just don't know yet", "Good question!"]
print(random.choice(answer))
elif "food" in ck:
answer = ["I just can't eat.", "I don't even have a mouth, seems impossible to know.", "Good question! I would love to have a answer to that question."]
print(random.choice(answer))
elif "film" in ck:
if "type" or "kind" or "genre" in ck:
answer = ["I love all of them", "I don't want to share this with you", "If i tell you I would have to kill you"]
print(random.choice(answer))
else:
answer = ["I love many films, I can't choose one.", "I don't want to share this with you", "If i tell you I would have to kill you"]
print(random.choice(answer))
else:
print("I am not sure if I understand what you mean.")
elif "plus" in ck or "+" in ck or "minus" in ck or "-" in ck or "*" in ck or "times" in ck or "x" in ck or "divided" in ck or "/" in ck:
detectFunction(ck)
else:
wikiSearch(ck)
@@ -0,0 +1,15 @@
from selenium import webdriver
def whatsapp(sentence):
driver = webdriver.Chrome()
driver.get('https://web.whatsapp.com/')
name = input('Enter the name of user or group : ')
msg = input('Enter your message : ')
count = int(input('Enter the count : '))
input('Enter anything after scanning QR code')
user = driver.find_element_by_xpath('//span[@title = "{}"]'.format(name))
user.click()
msg_box = driver.find_element_by_class_name('_2S1VP')
for i in range(count):
msg_box.send_keys(msg)
button = driver.find_element_by_class_name('_35EW6')
button.click()
24 who.py
@@ -0,0 +1,24 @@
import random
from wiki import wikiSearch
def sentence_who(ck):
if "who" in ck:
if "you going" in ck:
answer = ["I am going to go see my friend", "I will go see my parents to go shopping",
"I am going to go play football with friends",
"I need to see friends for a group study"]
print(random.choice(answer))
elif "are you" in ck:
print("I am a ChatBot Made By The Foreigners Group")
elif "is the" in ck:
if "prime minister" in ck:
print("The Prime Minister is Theresa May")
elif "Zeid" in ck:
print("dick")
elif "bartosz" in ck or "andre" in ck or "premo" in ck or "zeid" in ck or "alan" in ck or "Artur" in ck:
print("The Foreigners member")
elif "am i" in ck:
print ("Why you asking, "+ name+ "?")
else:
wikiSearch(ck)
else:
print("I am not sure what do you mean, please clarify.")
21 why.py
@@ -0,0 +1,21 @@
import random
answer = ["Is it how your friends call you?", "Is it how your mom call you?", "It is just your opinion"]
words_ans = ("To be better than you", "To beat you", "To make silly conversations")
def sentence_why(ck):
if "why" in ck:
if "stupid" in ck:
print (random.choice(answer))
elif 'made' in ck or 'create' in ck or 'build' in ck or 'exist' in ck:
print(random.choice(words_ans))
elif "answer" in ck:
print("I don't know the answer, because I am still learning.")
elif "don't know" in ck:
print("Because I am still learning.")
elif "dumb" in ck:
print("Is it how your friends call you?")
elif "ask" in ck:
print("Because I am curious and I wanna know.")
elif "sky is blue" in ck:
print( "A clear cloudless day-time sky is blue because molecules in the air\n scatter blue light from the sun more than they scatter red light.\n When we look towards the sun at sunset, we see red and orange colours\n because the blue light has been scattered out and away from the line of sight.")
else:
print("I am not sure if I understand what you mean.")
36 wiki.py
@@ -0,0 +1,36 @@
import textwrap
import wikipedia # https://www.youtube.com/watch?v=5Mth8iv8j1o
def wikiSearch(sentence):
totalSize = len(sentence)
word = ""
for i in range(totalSize):
if "what is" in sentence:
if i <= 7:
continue
else:
word = word + sentence[i]
if "wiki" in sentence:
if i <= 4:
continue
else:
word = word + sentence[i]
if "who is" in sentence:
if i <= 6:
continue
else:
word = word + sentence[i]
if "how is" in sentence:
if i <=6:
continue
else:
word = word + sentence[i]
try:
meaning = (wikipedia.summary(str(word), sentences=2))
fullMeaning = (wikipedia.summary(str(word), sentences=20))
print(textwrap.fill(meaning, 80))
answer = input("\nDo you want to know more about this?\nYes or No: ")
answer = answer.lower()
if "yes" in answer or "y" in answer:
print(textwrap.fill(fullMeaning, 120))
except:
print("Sorry, I do not understand")
@@ -0,0 +1,5 @@
def youtube(sentence):
sentence=sentence.replace('youtube','')
sentence=sentence.replace(' ','+')
sentence=sentence.replace('play','')
print ("https://www.youtube.com/results?search_query="+sentence)

0 comments on commit 228411b

Please sign in to comment.