-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scrape anime and play episodes on browser without ads from terminal #5975
Scrape anime and play episodes on browser without ads from terminal #5975
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from urllib.error import HTTPError | |
from requests.exceptions import HTTPError, RequestException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
except (requests.exceptions.RequestException, HTTPError, TypeError) as e: | |
except (HTTPError, RequestException, TypeError) as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to RequestException
[list]: [List of animes] | ||
""" | ||
|
||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the long try catches with critical ones
KeyError, | ||
NotFoundErr, | ||
TypeError, | ||
requests.exceptions.RequestException, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed multiple exceptions
@cclauss . I have made the changes |
except RequestException as e: | ||
raise e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function will take an url and | |
Take an url and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed them
except (ValueError, IndexError, TypeError) as e: | ||
raise e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can lose the try / except if we are not going to handle the errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the block.
response = requests.get( | ||
search_url, headers={"UserAgent": UserAgent().chrome} | ||
) # request the url. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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}
.