akhilkammila / leetcode-screenshotter

screenshots leetcode editorials and problems
MIT License
487 stars 179 forks source link

Add Codes for the editorials #2

Open raghavrambo007 opened 1 year ago

raghavrambo007 commented 1 year ago

Some editorials doesn't show the code, since they are hidden inside scrolling. Without editorial code, solutions doesn't help that much. maybe you can hit the copy button using selenium, and copy those codes, and provide along with the screenshot for each problem to refer to.

raghavrambo007 commented 1 year ago

@akhilkammila if you still have the leetcode premium account, can you run this python script ? This I created by reverse engineering the API calls made in the editorial page to get the editorial solution codes, this gets those codes, and puts them in separate files, for all the approaches, and for all the languages.. Let me know if you face any issues, since some file paths and other things might needs to be changed.

akhilkammila commented 1 year ago

@raghavrambo007

Nice script, it seems to work decently well. Appreciate it. For some problems it doesn't work. Problem 3, for example, throws an exception because response1.text is just {"data":{"question":{"solution":{"content":null}}}}.

I'll run the script for now though and push the files. Thx man

raghavrambo007 commented 1 year ago

Hey @akhilkammila , thanks a lot!

Maybe some problems use some other json response structure. if we can write those problems which doesnt work in the except section to some csv, could look into them.

Also, looking forward to integrate this with your project, with all those docker, and proper foldering out the output and stuff. I am not much familiar with docker, let me know how we can go about that.

akhilkammila commented 1 year ago

Hm yeah. The foldering isn't that hard, I just made a quick change to the script and it should put it into folders. The main point of the folders is just because github doesn't display more than 1000 subitems per folder.

I think the main thing to do for integration is create something that formats the files into the ReadMe (like whats under the readme-formatter folder). So people can just go to the ReadMe and click links and it'll open the link to the problem. It'd be great if you could help with that, if not its aight

Also don't worry about Docker. It runs fine locally, Docker is just for containerization (so you can run it on AWS EC2 or something). I don't really use the docker container most of the time.

I'll push the editorial code once the script finishes running. Lmk if u need anything, I'm a bit too busy for like big stuff right now cuz of school and recruiting, but I can help. Thx!

unable8759 commented 1 year ago

@akhilkammila Speaking on this, the editorials sometimes have video solutions. Is it possible to scrap those videos?

Edit: Since I've never seen the videos, I don't know if they cover the same things the editorials do or if they have additional content. If they're the same, it's not worth the effort but if the videos are useful, it might be worth it.

raghavrambo007 commented 1 year ago

@akhilkammila , sure would do the readme formatter thing, thats just simple string concatenation it seems. Once you push the codes data, would create that based on the forder structure. Thanks

akhilkammila commented 1 year ago

@raghavrambo007 Pushed it, thx. Unfortunately it looks like a good amount failed, but it got a lot of the editorial code.

@unable8759 Its probably not feasible. Even if we could get them, would have to store it somewhere. Tbh the videos aren't that useful though, its the same content plus some examples and stuff. I don't watch them I just use the editorials.

raghavrambo007 commented 1 year ago

@akhilkammila , there was a bug in the script. Basically there was no default return statement for the getExt method in the previous one. so if there is some code language which I didnt mentioned, it would fail with exception. I fixed it, can you merge this PR ( #3 )? Also when you get time can you rerun this to check if there is any reduction in number of errors this time? This time it should run faster than last time, since I removed the unnecessary time.sleep also.

unable8759 commented 1 year ago

@raghavrambo007 does this also fix the editorials that didn't work? Or is it too hard to debug why some fail? There's a few that didn't make it in which would be great to see.

akhilkammila commented 1 year ago

@raghavrambo007 Hey! I just ran the new script. It seems to have fixed the issue for a few editorials, but a lot of them still don't work (like #3 for example). I pushed the new changes tho, thx. Appreciate ur help

@unable8759 Nah this is unrelated to the screenshots. To get screenshots for the missing problems I need to rescrape the problems and rerun my screenshotter. I'll do that in a few weeks when I have more time, sry.

unable8759 commented 1 year ago

oh I was referring to the editorial code snippets that @raghavrambo007 created the script for. Doesn't look like it was able to get all of them unfortunately but still got a lot

unable8759 commented 1 year ago

@akhilkammila do you have neetcode by any chance? There are courses in there which have articles similar to this leetcode editorials.

47-Carnage commented 5 months ago

Hi @akhilkammila @raghavrambo007 , please can you add remaining Editorial Codes please. Like i am solving interview 150 questions for those i don't think codes are there..i didn't find many..

like house robber etc..

NDR0216 commented 5 months ago

I think the API in the script is correct, but the login session header is missing However, I don't have a premium account. so it's hard to fix the error.