Created
May 3, 2016 02:01
-
-
Save cjwinchester/0ec9354dd7eeae026abdbb57c557dcfe to your computer and use it in GitHub Desktop.
Command-Line Kid Jokes As A Service
This file contains hidden or 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
[ | |
{ | |
"joke": "orange", | |
"punchline": "Orange you glad I'm telling you all these knock-knock jokes?", | |
"knockknock": true | |
}, | |
{ | |
"joke": "boo", | |
"punchline": "Don't cry about it. It's just a joke.", | |
"knockknock": true | |
}, | |
{ | |
"joke": "How do dinosaurs pay their bills?", | |
"punchline": "With Tyrannosaurus checks!" | |
}, | |
{ | |
"joke": "interrupting cow", | |
"punchline": "MOOOOOOOOOOOOOOO", | |
"knockknock": true, | |
"interrupting": true | |
} | |
] |
This file contains hidden or 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
import random | |
import json | |
import time | |
jokes_file = "jokes.json" | |
with open(jokes_file, "rb") as jokes: | |
f = jokes.read() | |
ls = json.loads(f) | |
random_number = random.randint(0, len(ls)-1) | |
def tell_joke(d): | |
if 'knockknock' in d: | |
x = raw_input("Knock, knock.\n") | |
print(d['joke']) | |
if 'interrupting' in d: | |
time.sleep(1) | |
print(d['punchline'] + "\n") | |
else: | |
y = raw_input("") | |
print(d['punchline'] + "\n") | |
else: | |
x = raw_input(d['joke'] + "\n") | |
print(d['punchline'] + "\n") | |
tell_joke(ls[random_number]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment