Skip to content
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

Enable hashing by .pk to convert lists into sets #1813

Merged
merged 2 commits into from
Feb 27, 2024

Conversation

DRVR1
Copy link
Contributor

@DRVR1 DRVR1 commented Feb 21, 2024

Sometimes, the retrieved userlist when using chunks, contains repeated followers. This can be fixed by converting the resulting list into a set, then the repeated users would be automatically removed. A set can only contain userShort objects if it can generate a hash out of them. This is why two new functions were added to the class UserShort. (hash and eq)

class UserShort(TypesBaseModel):
    def __hash__(self):
        return hash(self.pk)
    def __eq__(self, other):
        if isinstance(other, UserShort):
            return self.pk == other.pk
        return NotImplemented
    pk: str
    username: Optional[str] = None
    full_name: Optional[str] = ""
    profile_pic_url: Optional[HttpUrl] = None
    profile_pic_url_hd: Optional[HttpUrl] = None
    is_private: Optional[bool] = None
    # is_verified: bool  # not found in hashtag_medias_v1
    # stories: List = [] # not found in fbsearch_suggested_profiles

@subzeroid subzeroid merged commit eaeeac8 into subzeroid:master Feb 27, 2024
2 of 4 checks passed
@subzeroid
Copy link
Owner

@DRVR1 thank you! 🤝

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