Skip to content

Commit

Permalink
Merge pull request #1186 from lucas-watkins/master
Browse files Browse the repository at this point in the history
Fix bored plugin
  • Loading branch information
pnhofmann committed Jul 8, 2024
2 parents 4945fa0 + e1637ff commit 8edd545
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions jarviscli/plugins/boredAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from plugin import plugin, require

"""
Gives you ideas to do when you are bored from https://www.boredapi.com/
Gives you ideas to do when you are bored from https://bored.api.lewagon.com/
"""


Expand All @@ -12,21 +12,32 @@ class bored_api:
"""
Tells an activity and its details when you type 'bored'
"""

def __call__(self, jarvis, s):
api_url = 'https://www.boredapi.com/api/activity/'
api_url = 'https://bored.api.lewagon.com/api/activity'
header = {'Accept': 'application/json'}
r = requests.get(api_url, headers=header)

query = r.json()
try:
r = requests.get(api_url, headers=header)

query = r.json()

activity = query['activity']
typ = query['type']
partic = query['participants']
price = query['price']
access = query['accessibility']
link = query['link']

jarvis.say(f'Activity: {activity}')
jarvis.say(f'Type: {typ}')
jarvis.say(f'Number of Participants: {partic}')
jarvis.say(f'Price: {"free" if price == 0 else price}')
jarvis.say(f'Link: {link if link is None else "none"}')

jarvis.say(f'Accessibility: {access}')

activity = query['activity']
typ = query['type']
partic = query['participants']
price = query['price']
access = query['accessibility']
except requests.exceptions.RequestException:

jarvis.say(f'Activity: {activity}')
jarvis.say(f'Type: {typ}')
jarvis.say(f'Number of Participants: {partic}')
jarvis.say(f'Price: {"free" if price==0 else price}')
jarvis.say(f'Accessibility: {access}')
# Is said in case of a connection or parse error
jarvis.say('Request Exception Occurred')

0 comments on commit 8edd545

Please sign in to comment.