I am working in jupyter notebook and made a get request,
but the fetching taking long time. It is taking long time not only for multiple id’s but also for a single id
Fetching is taking long time
hey @itzsakshi26gupta,
can you please share your code , so that i can understand your approach and suggest something based on it.
Thank you.
.
thanks
hey @itzsakshi26gupta ,
kindly check above provided link again , it just link to ide , not your code.
Kindly provide the correct one.
Thank You.
#sorry my ide is not working
#issues:
#1. it is slow
#2. it not working for id’s with no content like id:7
from urllib.request import urlopen
import json
with open(“joke.csv”,‘r’) as file:
joke_list = file.read().split()
string = “”
joke_url = “http://api.icndb.com/jokes/”
headings = [“id”,“joke”]
with open(‘allJoke.csv’,‘w’,encoding = “utf-8”) as f:
string = “,” .join(headings) + ‘\n’
f.write(string)
for i in joke_list:
url = joke_url + i
url_result = urlopen(url)
joke_data = url_result.read()
json_data = json.loads(joke_data)
string2 = ""
value = json_data["value"]
idx = value["id"]
joke = value["joke"]
idx = str(idx)
joke_details = []
joke_details = [idx,joke]
string2 = ",".join(joke_details) + "\n"
f.write(string2)
hey @itzsakshi26gupta ,
i am really sorry for such late response,
the slow working can be due to either low network speed or due to large number of calls on the respective url.
So , instead of making a large number of calls,
you just save all records / jokes at once by fetching the json data from “http://api.icndb.com/jokes/” .
once you have stored it , now you can access it locally on your system very fastly , instead of making various calls one after the other.
hey @itzsakshi26gupta ,
kindly visit this link https://drive.google.com/drive/folders/1IyiFbU9SwCTlhGKAUSvSPmvoQ8O4z9PK?usp=sharing.
The error was with qoutes to be included on jokes having commas in between them.
i have updated the code and made it much faster too.
Kindly have a look at it and if there are any questions , you can ask me.
Thank you
.
why have you used (the marked portion)
if(type == 'NoSuchQuoteException'):
value = json_data['value']
id = i
–> if re.search(r"[^a-zA-Z0-9]"):
–> value = ‘"’+value+’"’
data = [id,value]
string = “,”.join(data) + ‘\n’
i am using regular expressions to find if there is any character other than alphabets and numbers in the sentence. If there is any then add qoutes in begining and at end.
ok, got it. Thank You.
but the instruction of adding quotes in such cases was not mentioned in the question.
Anyways, thanks 
yeah it wasn’t. And this was the thing that the students needs to find out for proper submission.
Dont worry , in future we will be taking it in care .
Thank You.
Now i guess your doubt is resolved, so i would request you to kindly mark this doubt as resolved and to provide your valuable feedback for helping us in improving this platform of learning.
Thank You and Happy Coding
.
We are not saving jokes with NoSuchQuoteException, right?
ok got it, thank you so much.