Skip to content

Instantly share code, notes, and snippets.

@markberly
Created February 12, 2014 15:31
Show Gist options
  • Save markberly/8957657 to your computer and use it in GitHub Desktop.
Save markberly/8957657 to your computer and use it in GitHub Desktop.
Let Yoda 'speak' a short python script that uses a API on Mashape API, found at: https://www.mashape.com/ismaelc/yoda-speak. You need to register and insert a Mashape-Authorization key in order to use the API. Have fun...
#!/usr/bin/python
import urllib2, urllib, argparse
# goto: https://www.mashape.com
# you need to create a Mashape account insert your key
# if you do not do this the script will fail
mashapeAuthorization = "MASHAPE_KEY"
def drawYoda () :
print ( """
::\`--._,'.::.`._.--'/::
::::. ` __::__ ' .::::
::::::-:.`'..`'.:-::::::
::::::::\ `--' /::::::::
""")
def main() :
# Create the command line parser / arguments
parser = argparse.ArgumentParser(description='What do you want Yoda to say?')
parser.add_argument( 'yodasLine', help='What do you want Yoda to say?' )
args = parser.parse_args()
str = urllib.quote(args.yodasLine)
opener = urllib2.build_opener()
opener.addheaders = [("X-Mashape-Authorization", mashapeAuthorization)]
socket = opener.open('https://yoda.p.mashape.com/yoda?sentence=' +
str)
content = socket.read()
socket.close()
drawYoda()
print "Yoda says: " + content + "\n\n\n"
if __name__ == '__main__':
main()
@markberly
Copy link
Author

bash$ ./yodaSpeak.py 'Fear is the path to the dark side. Fear leads to anger. Anger leads to hate. Hate leads to suffering.' 
  
   
    
::\`--._,'.::.`._.--'/::        
::::.  ` __::__ '  .::::
::::::-:.`'..`'.:-::::::                                     
::::::::\ `--' /::::::::      
       
Yoda says: The path to the dark side, fear is.  To anger fear leads.  To hate anger leads.  To suffering hate leads.  Hmmmmmm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment