Skip to content

Commit

Permalink
Ability to interpret Spanish
Browse files Browse the repository at this point in the history
  • Loading branch information
hmangukia committed Jul 16, 2018
1 parent 5581bdf commit 06310d7
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions windows/benji.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import tweepy
from tweepy import OAuthHandler
import twitterCredentials
from googletrans import Translator

requests.packages.urllib3.disable_warnings()
try:
Expand All @@ -58,7 +59,7 @@
speak = pyttsx3.init()

def events(frame,put):
identity_keywords = ["who are you", "who r u", "what is your name"]
identity_keywords = ["who are you", "who r u", "what is your name", "who you are"]
youtube_keywords = ("play ", "stream ", "queue ")
launch_keywords = ["open ", "launch "]
search_keywords = ["search "]
Expand All @@ -72,7 +73,14 @@ def events(frame,put):
pc_locations = ("desktop", "documents", "downloads")

put = put.lower()
link = put.split()
translator = Translator()
if put.startswith("spanish"):
word, space, rest = put.partition(' ')
translated = translator.translate(rest, src='es', dest='en')
put = translated.text
link = put.split()
else:
link = put.split()

#Add user for face detection
if link[0] == "face" or link[0] == "phase":
Expand All @@ -83,30 +91,8 @@ def events(frame,put):
cv2.imwrite(path + "/" + str(name) + ".jpg", img)
cam.release()
cv2.destroyAllWindows()

#Get top 10 tweets
elif link[0] == "get" and link[-1] == "tweets":
auth = OAuthHandler(twitterCredentials.consumer_key, twitterCredentials.consumer_secret)
auth.set_access_token(twitterCredentials.access_token, twitterCredentials.access_secret)
api = tweepy.API(auth)
if link[-2] == "my":
for tweet in tweepy.Cursor(api.user_timeline).items(10):
print("\n", json.dumps(tweet.text))
print("on ", tweet.created_at)
elif link[1] == "tweets":
for status in tweepy.Cursor(api.home_timeline).items(10):
print("\n", status.text)
print("By ", status.user.screen_name, " at ", status.user.created_at)

#Get friends from twitter
elif link[-3] == "follow" and link[-1] == "twitter":
auth = OAuthHandler(twitterCredentials.consumer_key, twitterCredentials.consumer_secret)
auth.set_access_token(twitterCredentials.access_token, twitterCredentials.access_secret)
api = tweepy.API(auth)
for friend in tweepy.Cursor(api.friends).items():
print("\nName: ", json.dumps(friend.name), " Username: ", json.dumps(friend.screen_name))

#Screenshot

#Screenshot
elif put.startswith('take screenshot') or put.startswith("screenshot"):
try:
pic = pyautogui.screenshot()
Expand Down Expand Up @@ -728,6 +714,28 @@ def main():
#Exit/Quit
elif put.startswith('exit') or put.startswith('quit'):
sys.exit()

#Get top 10 tweets
elif link[0] == "get" and link[-1] == "tweets":
auth = OAuthHandler(twitterCredentials.consumer_key, twitterCredentials.consumer_secret)
auth.set_access_token(twitterCredentials.access_token, twitterCredentials.access_secret)
api = tweepy.API(auth)
if link[-2] == "my":
for tweet in tweepy.Cursor(api.user_timeline).items(10):
print("\n", json.dumps(tweet.text))
print("on ", tweet.created_at)
elif link[1] == "tweets":
for status in tweepy.Cursor(api.home_timeline).items(10):
print("\n", status.text)
print("By ", status.user.screen_name, " at ", status.user.created_at)

#Get friends from twitter
elif link[-3] == "follow" and link[-1] == "twitter":
auth = OAuthHandler(twitterCredentials.consumer_key, twitterCredentials.consumer_secret)
auth.set_access_token(twitterCredentials.access_token, twitterCredentials.access_secret)
api = tweepy.API(auth)
for friend in tweepy.Cursor(api.friends).items():
print("\nName: ", json.dumps(friend.name), " Username: ", json.dumps(friend.screen_name))

#A stdout class to redirect output to tkinter window
class StdRedirector(object):
Expand Down

0 comments on commit 06310d7

Please sign in to comment.