Created
February 12, 2014 15:31
-
-
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...
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
#!/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() | |
Author
markberly
commented
Feb 12, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment