zytedata / zyte-common-items

Contains the common item definitions used in Zyte.
BSD 3-Clause "New" or "Revised" License
9 stars 6 forks source link

new ProbabilityMixin class with get_probability() on items #65

Closed BurnzZ closed 1 year ago

BurnzZ commented 1 year ago

Related to https://github.com/zytedata/zyte-common-items/pull/64, it would seem it's beneficial to extend get_probability() on item instances as well.

Motivation: In a spider callback, it's easier to do something like:

def parse_item(self, response, item: Product):
    probability = item.get_probability()
    if probability and probability >= 0.1:
        yield item

than:

def parse_item(self, response, item: Product):
    probability = None
    if metadata := getattr(item, "metadata", None):
        probability = metadata.probability

    if probability and probability >= 0.1:
        yield item
codecov-commenter commented 1 year ago

Codecov Report

Merging #65 (70cfd1a) into main (3002dcb) will not change coverage. The diff coverage is 0.00%.

:exclamation: Current head 70cfd1a differs from pull request most recent head e5cecec. Consider uploading reports for the commit e5cecec to get more accurate results

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #65 +/- ## ===================================== Coverage 0.00% 0.00% ===================================== Files 8 8 Lines 870 873 +3 ===================================== - Misses 870 873 +3 ``` | [Files](https://app.codecov.io/gh/zytedata/zyte-common-items/pull/65?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | | |---|---|---| | [zyte\_common\_items/components.py](https://app.codecov.io/gh/zytedata/zyte-common-items/pull/65?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-enl0ZV9jb21tb25faXRlbXMvY29tcG9uZW50cy5weQ==) | `0.00% <0.00%> (ø)` | | | [zyte\_common\_items/base.py](https://app.codecov.io/gh/zytedata/zyte-common-items/pull/65?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-enl0ZV9jb21tb25faXRlbXMvYmFzZS5weQ==) | `0.00% <0.00%> (ø)` | |