-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from zytedata/job-navigation
Add job posting navigation classes.
- Loading branch information
Showing
8 changed files
with
132 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from typing import List, Optional | ||
|
||
import attrs | ||
|
||
from zyte_common_items.base import Item | ||
from zyte_common_items.components import ListMetadata, ProbabilityRequest, Request | ||
from zyte_common_items.converters import ( | ||
to_metadata_optional, | ||
to_probability_request_list_optional, | ||
url_to_str, | ||
) | ||
|
||
|
||
@attrs.define(kw_only=True) | ||
class JobPostingNavigationMetadata(ListMetadata): | ||
"""Metadata class for :data:`zyte_common_items.JobPostingNavigation.metadata`.""" | ||
|
||
|
||
@attrs.define(kw_only=True) | ||
class JobPostingNavigation(Item): | ||
"""Represents the navigational aspects of a job posting listing page on a | ||
job website""" | ||
|
||
#: Main URL from which the data is extracted. | ||
url: str = attrs.field(converter=url_to_str) | ||
|
||
#: List of job postings available on this page. | ||
items: Optional[List[ProbabilityRequest]] = attrs.field( | ||
default=None, converter=to_probability_request_list_optional, kw_only=True # type: ignore[misc] | ||
) | ||
|
||
#: A link to the next page, if available. | ||
nextPage: Optional[Request] = None | ||
|
||
#: Number of the current page. | ||
#: | ||
#: It should only be extracted if the webpage shows a page number. | ||
#: | ||
#: It must be 1-based. For example, if the first page of a listing is | ||
#: numbered as 0 on the website, it should be extracted as `1` nonetheless. | ||
pageNumber: Optional[int] = None | ||
|
||
#: Data extraction process metadata. | ||
metadata: Optional[JobPostingNavigationMetadata] = attrs.field( | ||
default=None, converter=to_metadata_optional(JobPostingNavigationMetadata), kw_only=True # type: ignore[misc] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from typing import List, Optional | ||
|
||
import attrs | ||
from web_poet import Returns | ||
|
||
from zyte_common_items.components import ProbabilityRequest, Request | ||
from zyte_common_items.fields import auto_field | ||
from zyte_common_items.items import JobPostingNavigation, JobPostingNavigationMetadata | ||
from zyte_common_items.processors import probability_request_list_processor | ||
|
||
from .base import BasePage, Page | ||
from .mixins import HasMetadata | ||
|
||
|
||
class BaseJobPostingNavigationPage( | ||
BasePage, Returns[JobPostingNavigation], HasMetadata[JobPostingNavigationMetadata] | ||
): | ||
""":class:`BasePage` subclass for :class:`JobPostingNavigation`.""" | ||
|
||
class Processors(BasePage.Processors): | ||
subCategories = [probability_request_list_processor] | ||
items = [probability_request_list_processor] | ||
|
||
|
||
class JobPostingNavigationPage( | ||
Page, Returns[JobPostingNavigation], HasMetadata[JobPostingNavigationMetadata] | ||
): | ||
""":class:`Page` subclass for :class:`JobPostingNavigation`.""" | ||
|
||
|
||
@attrs.define | ||
class AutoJobPostingNavigationPage(BaseJobPostingNavigationPage): | ||
job_posting_navigation: JobPostingNavigation | ||
|
||
@auto_field | ||
def items(self) -> Optional[List[ProbabilityRequest]]: | ||
return self.job_posting_navigation.items | ||
|
||
@auto_field | ||
def metadata(self) -> Optional[JobPostingNavigationMetadata]: | ||
return self.job_posting_navigation.metadata | ||
|
||
@auto_field | ||
def nextPage(self) -> Optional[Request]: | ||
return self.job_posting_navigation.nextPage | ||
|
||
@auto_field | ||
def pageNumber(self) -> Optional[int]: | ||
return self.job_posting_navigation.pageNumber | ||
|
||
@auto_field | ||
def url(self) -> Optional[str]: | ||
return self.job_posting_navigation.url |