Challenge - Chuk Norris Jokes (API)

please give me some hint for this problem.

1 Like

Hey @Abhishek-Vishwakarma-653004358467067,

For this specific challenge, you will be extracting jokes from the Chuck Norris Database API.
You will be given specific joke ‘ID’ and you have to get the joke for the corresponding joke ID.

For Example:
For a Joke with ID ‘1’, you will make a GET request at following URL- http://api.icndb.com/jokes/1

Steps :

  1. Import the necessary libraries.

    from urllib.request import urlopen
    import json

  2. Scrap data from the given URL

    url_result = urlopen('http://api.icndb.com/jokes/1')
    data = url_result.read()
    print(data)

    Output: = b’{ “type”: “success”, “value”: { “id”: 1, “joke”: “Chuck Norris uses ribbed
    condoms inside out, so he gets the pleasure.”, “categories”: [“explicit”] } }’

    This is raw data, we need to convert this into JSON data.

  3. Converting raw data to JSON formatted data.

    json_data=json.loads(data)

    Output:

    {‘type’: ‘success’,
    ‘value’: {‘id’: 1,
    ‘joke’: ‘Chuck Norris uses ribbed condoms inside out, so he gets the pleasure.’,
    ‘categories’: [‘explicit’]}}
    json[‘value’][‘joke’]

    Thus we can extract jokes from json_data by,

    print(json_data['value']['id'])
    print(json_data['value']['joke'])

Output:

1
Chuck Norris uses ribbed condoms inside out, so he gets the pleasure

Submission Guidelines:

You are given a CSV for Testcases that contains ID’s of the jokes. You need to scrap the data corresponding to those ID’s and write that data to another CSV as shown in the Reference CSV.

I hope this post makes everything clear.

it is taking too long for the given test case, my code is running for huge time, is there any way to optimise it

like gnewsclient is for getting news, what if I want to access articles about mental issues likes depression , their symptoms and their treatment and about other things related to them.