Skip to content

Add index parameter to scrape sensor#21084

Merged
fabaff merged 2 commits into
home-assistant:devfrom
davidbb:scrape-index
Feb 16, 2019
Merged

Add index parameter to scrape sensor#21084
fabaff merged 2 commits into
home-assistant:devfrom
davidbb:scrape-index

Conversation

@davidbb
Copy link
Copy Markdown
Contributor

@davidbb davidbb commented Feb 15, 2019

Description:

The scrape sensor selects the first element of the list returned by
BeautifulSoup. This commit adds an optional index parameter to allow the
selection of a different element from the list of results. To make this
a non-breaking change, if no index value is configured, the sensor
defaults to the previous behaviour of returning the first element.

Related issue (if applicable): fixes #

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#8590

Example entry for configuration.yaml (if applicable):

sensor:
 - platform: scrape
   name: h-index
   resource: https://scholar.google.ca/citations?user=cVeVZ1YAAAAJ
   select: "td:is(.gsc_rsb_std)"
   index: 2

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

The scrape sensor selects the first element of the list returned by
BeautifulSoup. This commit adds an optional index parameter to allow the
selection of a different element from the list of results. To make this
a non-breaking change, if no index value is configured, the sensor
defaults to the previous behaviour of returning the first element.
@davidbb davidbb requested a review from fabaff as a code owner February 15, 2019 01:30
@homeassistant
Copy link
Copy Markdown
Contributor

Hi @davidbb,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

Comment thread homeassistant/components/sensor/scrape.py Outdated
Copy link
Copy Markdown
Member

@fabaff fabaff left a comment

Choose a reason for hiding this comment

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

Thanks 🐦

@fabaff fabaff merged commit 4509cae into home-assistant:dev Feb 16, 2019
@ghost ghost removed the in progress label Feb 16, 2019
@balloob balloob mentioned this pull request Mar 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants