setting min and max price from API variable in function

  api, filter, if-statement, python-3.x, python-requests

I have an API web http://www.boredapi.com/api/activity/ which randomly creates an activity to do if you are bored. The common output is the activity with the followings fields: key,link,participants,accessibility,price and type.
I’m only interested in showing the activity, the type and the price.

So far so good.

BUT, I wan to be able to get only the activities that are WITHIN a range of prices.
I created the function "fun" and has two parameters (the minimum price and the maximum we are willing to pay.

I want to check in a range from 0 to 10 which activities are available in a specific range of price.

The only thing I can’t get around is how to tell the API to print only if the activities are in these ranges…
I tried to access the attribute with [‘price’] but it doesn’t seem to make any difference.

How would you address this issue?

Currently the output is something like this, the only issue is the price range
enter image description here

import requests
import json

def fun(minprice,maxprice):
    for i in range(0,10):
        response= requests.get("http://www.boredapi.com/api/activity/")
        content_dict=json.loads(response.content)
        del(content_dict['key'])
        del(content_dict['link'])
        del(content_dict['participants'])
        del(content_dict['accessibility'])
        minprice=content_dict['price']
        maxprice=content_dict['price']
        print(content_dict)
fun(0,0.1)

Source: Python-3x Questions

LEAVE A COMMENT