Skip to content

Commit 8dd0846

Browse files
committed
Changed the pyramid bot from Chuck Norris to Cat facts
1 parent 077ec28 commit 8dd0846

File tree

1 file changed

+13
-13
lines changed
  • examples/pyramidSparkBot/pyramidSparkBot

1 file changed

+13
-13
lines changed

examples/pyramidSparkBot/pyramidSparkBot/views.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,34 @@
3737

3838

3939
# Module constants
40-
CHUCK_NORRIS_JOKES_URL = 'http://api.icndb.com/jokes/random'
40+
CAT_FACT_URL = 'http://catfacts-api.appspot.com/api/facts?number=1'
4141

4242

4343
# Initialize the environment
4444
spark_api = CiscoSparkAPI() # Create the Cisco Spark API connection object
4545

4646

4747
# Helper functions
48-
def get_chuck_norris_joke():
49-
"""Get a Chuck Norris Joke from api.icndb.com and return it as a string.
48+
def get_catfact():
49+
"""Get a cat fact from catfacts-api.appspot.com and return it as a string.
5050
Functions for Soundhound, Google, IBM Watson, or other APIs can be added
5151
to create the desired functionality into this bot.
5252
"""
53-
response = requests.get(CHUCK_NORRIS_JOKES_URL, verify=False)
53+
response = requests.get(CAT_FACT_URL, verify=False)
5454
response_dict = json.loads(response.text)
55-
return response_dict['value']['joke']
55+
return response_dict['facts'][0]
5656

5757

5858
sparkwebhook = Service(name='sparkwebhook', path='/sparkwebhook', description="Spark Webhook")
5959

6060

6161
@sparkwebhook.get()
6262
def get_sparkwebhook(request):
63-
log.info(get_chuck_norris_joke())
64-
return {"joke": get_chuck_norris_joke()}
63+
log.info(get_catfact())
64+
return {"fact": get_catfact()}
6565

6666
@sparkwebhook.post()
67-
# Your Spark webhook should point to http://<serverip>:5000/sparkwebhook
67+
# Your Spark webhook should point to http://<serverip>:6543/sparkwebhook
6868
def post_sparkwebhook(request):
6969
"""Respond to inbound webhook JSON HTTP POST from Cisco Spark."""
7070

@@ -93,10 +93,10 @@ def post_sparkwebhook(request):
9393

9494
else:
9595
# Message was sent by someone else; parse message and respond.
96-
if "/CHUCKNORRIS" in message.text:
97-
log.info("FOUND '/CHUCKNORRIS'")
98-
chuck_norris_joke = get_chuck_norris_joke() # Get a Chuck Norris Joke
99-
log.info("SENDING CHUCK NORRIS JOKE '{}'".format(chuck_norris_joke))
100-
spark_api.messages.create(room.id, text=chuck_norris_joke) # Post the fact to the room where the request was received
96+
if "/CAT" in message.text:
97+
log.info("FOUND '/CAT'")
98+
catfact = get_catfact() # Get a cat fact
99+
log.info("SENDING CAT FACT'{}'".format(catfact))
100+
spark_api.messages.create(room.id, text=catfact) # Post the fact to the room where the request was received
101101
return {'Message': 'OK'}
102102

0 commit comments

Comments
 (0)