-
-
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,16 @@ | ||||||||||||||||||
import requests | ||||||||||||||||||
from bs4 import BeautifulSoup | ||||||||||||||||||
import datetime | ||||||||||||||||||
|
||||||||||||||||||
if __name__ == "__main__": | ||||||||||||||||||
url = input("Enter image url: ") | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
As discussed in CONTRIBUTING.md. |
||||||||||||||||||
print("Downloading image...") | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Use f-strings as discussed in CONTRIBUTING.md |
||||||||||||||||||
req = requests.get(url) | ||||||||||||||||||
soup = BeautifulSoup(req.content, "html.parser") | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Avoid creating variables that are only used on the next line unless:
|
||||||||||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Python variable names are in snake_case as discussed in CONTRIBUTING.md. |
||||||||||||||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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. |
||||||||||||||||||
print("Done. Image saved to disk as " + fileName) | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
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.
Please run
isort
on the imports.