Repository navigation
Scrape anime and play episodes on browser without ads from terminal - #5975
Conversation
ghost
left a comment
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| ) | ||
| chosen_anime = anime_list[anime_choice - 1] | ||
| print( | ||
| "You chose {}. Searching for episodes...".format(chosen_anime["title"]) |
There was a problem hiding this comment.
As mentioned in the Contributing Guidelines, please do not use printf style formatting or str.format(). Use f-string instead to be more readable and efficient.
| else: | ||
| print(f"Found {len(episode_list)} results: ") | ||
| for (i, episode) in enumerate(episode_list): | ||
| print(("{}. {}").format(i + 1, episode["title"])) |
There was a problem hiding this comment.
As mentioned in the Contributing Guidelines, please do not use printf style formatting or str.format(). Use f-string instead to be more readable and efficient.
| input("\nChoose an episode by serial no: ").strip() | ||
| ) | ||
| chosen_episode = episode_list[episode_choice - 1] | ||
| print("You chose {}. Searching...".format(chosen_episode["title"])) |
There was a problem hiding this comment.
As mentioned in the Contributing Guidelines, please do not use printf style formatting or str.format(). Use f-string instead to be more readable and efficient.
| @@ -0,0 +1,203 @@ | |||
| from urllib.error import HTTPError | |||
There was a problem hiding this comment.
| from urllib.error import HTTPError | |
| from requests.exceptions import HTTPError, RequestException |
There was a problem hiding this comment.
changed with from requests.exceptions import RequestException
|
|
||
| return anime_list | ||
|
|
||
| except (requests.exceptions.RequestException, HTTPError, TypeError) as e: |
There was a problem hiding this comment.
| except (requests.exceptions.RequestException, HTTPError, TypeError) as e: | |
| except (HTTPError, RequestException, TypeError) as e: |
There was a problem hiding this comment.
changed to RequestException
| [list]: [List of animes] | ||
| """ | ||
|
|
||
| try: |
There was a problem hiding this comment.
try / except block should be just around critical areas of code. They should not be 30 lines long!!
There was a problem hiding this comment.
removed the long try catches with critical ones
| KeyError, | ||
| NotFoundErr, | ||
| TypeError, | ||
| requests.exceptions.RequestException, |
There was a problem hiding this comment.
Long try / except blocks lead to many different exceptions which confuses the reader of the code. It also slows down debugging when one of them is raised.
There was a problem hiding this comment.
removed multiple exceptions
|
@cclauss . I have made the changes |
| except RequestException as e: | ||
| raise e |
There was a problem hiding this comment.
There is no need to catch an Exception if you are only going to raise the same Exception unmodified.
There was a problem hiding this comment.
ok. i've used response.raise_for_status() instead.
| for children in episode_page_li: | ||
| try: | ||
| if not isinstance(children, NavigableString): | ||
| episode_list.append( | ||
| { | ||
| "title": children.find("div", {"class": "name"}).text.replace( | ||
| " ", "" | ||
| ), | ||
| "url": children.find("a")["href"], |
There was a problem hiding this comment.
It confuses the reader that children is plural yet these items are singular. It is easier to understand when each item is an episode...
| for children in episode_page_li: | |
| try: | |
| if not isinstance(children, NavigableString): | |
| episode_list.append( | |
| { | |
| "title": children.find("div", {"class": "name"}).text.replace( | |
| " ", "" | |
| ), | |
| "url": children.find("a")["href"], | |
| for episode in episode_page_li: | |
| try: | |
| if not isinstance(episode, NavigableString): | |
| episode_list.append( | |
| { | |
| "title": episode.find("div", {"class": "name"}).text.replace( | |
| " ", "" | |
| ), | |
| "url": episode.find("a")["href"], |
There was a problem hiding this comment.
for episode in episode_page_li:
for anime in anime_li:
Like this now
|
|
||
| """[summary] | ||
|
|
||
| This function will take an url and |
There was a problem hiding this comment.
| This function will take an url and | |
| Take an url and |
|
|
||
| """[summary] | ||
|
|
||
| This function will take an url and |
There was a problem hiding this comment.
| This function will take an url and | |
| Take an url and |
| except (ValueError, IndexError, TypeError) as e: | ||
| raise e |
There was a problem hiding this comment.
We can lose the try / except if we are not going to handle the errors.
There was a problem hiding this comment.
removed the block.
| response = requests.get( | ||
| search_url, headers={"UserAgent": UserAgent().chrome} | ||
| ) # request the url. |
There was a problem hiding this comment.
Don't wrap a line just for a comment.
| response = requests.get( | |
| search_url, headers={"UserAgent": UserAgent().chrome} | |
| ) # request the url. | |
| # request the url. | |
| response = requests.get(search_url, headers={"UserAgent": UserAgent().chrome}) |
|
Thank you @cclauss |
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}.