Skip to content

Create fetch_amazon_product_data.py #7585

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

Merged
merged 13 commits into from
Oct 28, 2022
Merged

Conversation

SparshRastogi
Copy link
Contributor

This file provides a function which will take
a product name as input from the user,and fetch the necessary information about that kind of products from Amazon like the product title,link to that product,price of the product,the ratings of the product and the discount available on the product in the form of a csv file,this will help the users by improving searchability and navigability and find the right product easily and in a short period of time, it will also be beneficial for performing better analysis on products

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Uncyclopedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

This file provides a function which will take  
a product name as input from the user,and fetch the necessary  
information about that kind of products from Amazon like the product 
title,link to that product,price of the product,the ratings of 
the product and the discount available on the product  
in the form of a csv file,this will help the users by improving searchability  
and navigability and find the right product easily and in a short period of time, 
it will also be beneficial for performing better analysis on products
@algorithms-keeper algorithms-keeper bot added the require type hints https://docs.python.org/3/library/typing.html label Oct 24, 2022
Copy link

@algorithms-keeper algorithms-keeper bot left a 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.

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Oct 24, 2022
Copy link

@algorithms-keeper algorithms-keeper bot left a 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.



def get_product_info(
product="laptop",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide type hint for the parameter: product

@algorithms-keeper algorithms-keeper bot mentioned this pull request Oct 27, 2022
14 tasks
Added type hints and modified files to pass precommit test
Copy link

@algorithms-keeper algorithms-keeper bot left a 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.

from bs4 import BeautifulSoup as bs


def get_product_info(product="laptop") -> None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide type hint for the parameter: product

Copy link

@algorithms-keeper algorithms-keeper bot left a 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.

from bs4 import BeautifulSoup as bs


def get_product_info(product="laptop") -> None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide type hint for the parameter: product

Added type hints and made changes to pass the precommit
@algorithms-keeper algorithms-keeper bot removed the require type hints https://docs.python.org/3/library/typing.html label Oct 28, 2022
Comment on lines 19 to 22
# function that will take the product as input and return the
#product details as output
# in the form of a csv file,if no input is given,it
#will fetch the details of laptop by default
Copy link
Member

@cclauss cclauss Oct 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# function that will take the product as input and return the
#product details as output
# in the form of a csv file,if no input is given,it
#will fetch the details of laptop by default
"""
Take the product as input and return the product details as output in the form
of a csv file. If no input is given, it will fetch the details of `laptop` by default.
"""

@cclauss
Copy link
Member

cclauss commented Oct 28, 2022

Here are the errors under the Details link to the right of the ❌ below:

flake8...................................................................Failed
- hook id: flake8
- exit code: 1

web_programming/fetch_amazon_product_data.py:15:2: N813 camelcase 'BeautifulSoup' imported as lowercase 'bs'
web_programming/fetch_amazon_product_data.py:28:89: E501 line too long (129 > 88 characters)
web_programming/fetch_amazon_product_data.py:45:12: B007 Loop control variable 'j' not used within the loop body. If this is intended, start the name with an underscore.

mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

web_programming/fetch_amazon_product_data.py:82: error: Incompatible types in assignment (expression has type "str", variable has type "float")
Found 1 error in 1 file (checked 1092 source files)

@cclauss
Copy link
Member

cclauss commented Oct 28, 2022

Please return data from your function instead of putting it into a csv file. You can put that data into a csv somewhere else in this script. The reason for doing this is explained in CONTRIBUTING.md. The caller might want to do something else with the data (tweet it, or compare it or chart it over time or use it with IfThisThenThat) and your algorithm should not assume what the caller wants to do with the data that the function delivers. We want to see that the data can be stored in CSV but that action should be outside your algorithmic function.

@cclauss cclauss self-assigned this Oct 28, 2022
SparshRastogi and others added 2 commits October 28, 2022 09:58
Modified function to return the data in the form of Pandas Dataframe,modified type hints and added a functionality to let the user determine if they need the data in a csv file
@@ -42,7 +41,7 @@ def get_product_info(product: str = "laptop") -> None:
"Discount",
]
) # initializing a pandas dataframe to store the requisite information
for i, j in it.zip_longest(
for i,j in it.zip_longest(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

psf/black is going to undo this change in pre-commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So,isn't there any way to use the two simultaneously? Or should I remove the second variable?

@SparshRastogi SparshRastogi requested a review from cclauss October 28, 2022 14:31
Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made changes based on the review comments.

@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Oct 28, 2022
@cclauss cclauss merged commit 26cecea into TheAlgorithms:master Oct 28, 2022
@SparshRastogi
Copy link
Contributor Author

@cclauss thank you so much for the edits to the file,actually I have just recently started contributing to open source,so I didn't had much idea about that but after seeing your edits I got to learn a lot and it will be helpful for me while contributing in future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants