-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Create instagram_pic #3945
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
Create instagram_pic #3945
Conversation
Pull Request Report@Epic-R-R Hello! I'm a bot made to check all the pull request Python files. First of all, I want to say thank you for your time and interest in this project and for opening a pull request. I have detected errors in some of the Python files submitted in this pull request. Please read through the report and make the necessary changes. You can take a look at the relevant links provided after the report. What are node paths?The report contain headings and a checklist where the items are paths to the class/function/parameter where the error is present. Node paths are double colon
Following functions require tests [
|
web_programming/instagram_pic.py
Outdated
import requests | ||
from bs4 import BeautifulSoup | ||
import datetime |
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.
import requests | |
from bs4 import BeautifulSoup | |
import datetime | |
import requests | |
from bs4 import BeautifulSoup | |
from datetime import datetime |
Please run isort
on the imports.
web_programming/instagram_pic.py
Outdated
|
||
if __name__ == "__main__": | ||
url = input("Enter image url: ") | ||
print("Downloading image...") |
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.
print("Downloading image...") | |
print(f"Downloading image from {url} ...") |
Use f-strings as discussed in CONTRIBUTING.md
web_programming/instagram_pic.py
Outdated
req = requests.get(url) | ||
soup = BeautifulSoup(req.content, "html.parser") |
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.
req = requests.get(url) | |
soup = BeautifulSoup(req.content, "html.parser") | |
soup = BeautifulSoup(requests.get(url).content, "html.parser") |
Avoid creating variables that are only used on the next line unless:
- The lines are already close to the max_line_length of 88 chars per line -- or --
- The variable name clarifies something that is unclear
web_programming/instagram_pic.py
Outdated
metaTag = soup.find_all("meta", {"property": "og:image"}) #get all meta tags | ||
imgURL = metaTag[0]["content"] |
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.
metaTag = soup.find_all("meta", {"property": "og:image"}) #get all meta tags | |
imgURL = metaTag[0]["content"] | |
# The image URL is in the content field of the first meta tag with the property og:image | |
image_url = soup.find("meta", {"property": "og:image"})["content"] |
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.
Python variable names are in snake_case as discussed in CONTRIBUTING.md.
web_programming/instagram_pic.py
Outdated
r = requests.get(imgURL) | ||
fileName = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S") + ".jpg" | ||
with open(fileName, "wb") as fp: | ||
fp.write(r.content) |
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.
r = requests.get(imgURL) | |
fileName = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S") + ".jpg" | |
with open(fileName, "wb") as fp: | |
fp.write(r.content) | |
image_data = requests.get(imgURL).content | |
file_name = f"{datetime.now():%Y-%m-%d_%H:%M:%S}.jpg" | |
with open(file_name, "wb") as fp: | |
fp.write(image_data) |
Avoid single-letter variable names -- They make code look like it was written in the 1970's. The reader of this code does not care about the response, but they do care about the image_data so focus their attention on that.
Use f-strings which are more expressive especially with complex types like datetimes.
web_programming/instagram_pic.py
Outdated
fileName = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S") + ".jpg" | ||
with open(fileName, "wb") as fp: | ||
fp.write(r.content) | ||
print("Done. Image saved to disk as " + fileName) |
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.
print("Done. Image saved to disk as " + fileName) | |
print(f"Done. Image saved to disk as {file_name}.") |
web_programming/instagram_pic.py
Outdated
import datetime | ||
|
||
if __name__ == "__main__": | ||
url = input("Enter image 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.
url = input("Enter image url: ") | |
url = input("Enter image url: ").strip() |
As discussed in CONTRIBUTING.md.
Plz add type hints in your function parameters like this, def test(a: int, b: int) -> int: |
I corrected the code and commit it, but it still gives an error in pre-commit isort field |
Yes i saw that your flake8 and isort is failing |
Install isort in your machine and run isort in this file locally |
And also install flake8 to see what styling mistake you done and if you can't corrected manually then install black and run black on this file it will correct all your styling mistake and flake8 check should be clear |
thanks, I use isort and then All checks have passed |
Nice work! Thanks for doing this. |
cclauss please also review my pull request |
* Create instagram_pic * Update instagram_pic * Update instagram_pic * isort * Update instagram_pic.py Co-authored-by: Christian Clauss <[email protected]>
* Create instagram_pic * Update instagram_pic * Update instagram_pic * isort * Update instagram_pic.py Co-authored-by: Christian Clauss <[email protected]>
* Create instagram_pic * Update instagram_pic * Update instagram_pic * isort * Update instagram_pic.py Co-authored-by: Christian Clauss <[email protected]>
* Create instagram_pic * Update instagram_pic * Update instagram_pic * isort * Update instagram_pic.py Co-authored-by: Christian Clauss <[email protected]>
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.