pyytdata icon indicating copy to clipboard operation
pyytdata copied to clipboard

Implement an API cache for development.

Open Agent-Hellboy opened this issue 3 years ago • 19 comments

Implementation of local API cache will help in avoiding rate limits of youtube data v3 API.

Agent-Hellboy avatar Feb 11 '21 07:02 Agent-Hellboy

I would like to work on this. this is a great opportunity for me to study APIs

tusharkulkarni008 avatar Oct 03 '22 03:10 tusharkulkarni008

Sure

Agent-Hellboy avatar Oct 03 '22 04:10 Agent-Hellboy

what route do you suggest

tusharkulkarni008 avatar Oct 03 '22 04:10 tusharkulkarni008

I am a beginner to this field

tusharkulkarni008 avatar Oct 03 '22 05:10 tusharkulkarni008

Can we use the cache argument from build function??

tusharkulkarni008 avatar Oct 03 '22 09:10 tusharkulkarni008

Can we use the cache argument from the build function??

didn't understand, which build function.

when I created this ticket I had an approach in mind i.e to save the JSON response returned by YouTube Data V3 API in a JSON file, we can track the input(input of public APIs like PyYtData class or vid_info function ) in the JSON file itself and if the input is present in JSON we simply return the response from JSON file instead of querying to YouTube API.

This will be useful in local testing only, you need to make changes in VideoInfo and ChannelInfo classes to avoid querying to Youtube API if the result is there for the particular request in the JSON file.

I hope you got my point

Agent-Hellboy avatar Oct 03 '22 12:10 Agent-Hellboy

Yes I got your point. I will commit the code in couple of days

tusharkulkarni008 avatar Oct 03 '22 12:10 tusharkulkarni008

Shall we use redis for this ???

tusharkulkarni008 avatar Oct 07 '22 05:10 tusharkulkarni008

No, we should stick with the json file. We are using this to avoid API rate limit while doing development locally.

Agent-Hellboy avatar Oct 07 '22 06:10 Agent-Hellboy

No, we should stick with the json file. We are using this to avoid API rate limits while doing development locally.

Agent-Hellboy avatar Oct 07 '22 06:10 Agent-Hellboy

Ok

tusharkulkarni008 avatar Oct 07 '22 06:10 tusharkulkarni008

I am working on it . Just need to study it a bit more since I have not done before

tusharkulkarni008 avatar Oct 07 '22 06:10 tusharkulkarni008

No probs, take your time

Agent-Hellboy avatar Oct 07 '22 06:10 Agent-Hellboy

I am not able to get the data from previous query into a JSON how should I do it

tusharkulkarni008 avatar Oct 10 '22 05:10 tusharkulkarni008

Save the json response returned by YouTube Data API V3 into a json file and next time if you are querying the same thing query to json file instead of YouTube Data API V3

Agent-Hellboy avatar Oct 10 '22 06:10 Agent-Hellboy

for i in range(self.maxlen): vid = VidInfo(self.type, self.keyword, self.maxlen, i) rslt.append(vid) return rslt do you mean this

tusharkulkarni008 avatar Oct 10 '22 06:10 tusharkulkarni008

No, I am talking about this point, https://github.com/Agent-Hellboy/pyytdata/blob/master/pyytdata/util/querier.py#L35

here you should do all the operations of saving the whole response https://github.com/Agent-Hellboy/pyytdata/blob/master/pyytdata/util/querier.py#L46 in a JSON file if the result is not present else return the result from JSON file instead of querying to the YouTube API

Agent-Hellboy avatar Oct 10 '22 07:10 Agent-Hellboy

we will get a response after req.execute() in fetch method runs right??. if I store req in JSON then it will be just that request not the response??

tusharkulkarni008 avatar Oct 12 '22 05:10 tusharkulkarni008

if I store req in JSON then it will be just that request not the response??

No, you will store both request and response, request as a key in JSON object and response and a value.

we will get a response after req.execute() in fetch method runs right

Yes, inside this you should check if the keyboard is inside your cache if yes you should return it as it is without querying to youtube API. https://github.com/Agent-Hellboy/pyytdata/blob/3ce31fc200ddec2b42c88b9edca038240e96b3f9/pyytdata/util/querier.py#L28

Agent-Hellboy avatar Oct 21 '22 13:10 Agent-Hellboy