PythonistaGuild / TwitchIO

An Async Bot/API wrapper for Twitch made in Python.
https://twitchio.dev
MIT License
798 stars 162 forks source link

class User `view_count` deprecated #318

Closed ccppoo closed 2 years ago

ccppoo commented 2 years ago

https://github.com/TwitchIO/TwitchIO/blob/114950a731290cff9a2b8c7cfd7b101f3eafc6af/twitchio/user.py#L1494-L1525

https://discuss.dev.twitch.tv/t/get-users-api-endpoint-view-count-deprecation/37777

from twitch developers

Beginning April 15, 2022, the data in “view_count” will not be updated and will contain stale data.

view count field response from Endpoint https://api.twitch.tv/helix/users

Not https://api.twitch.tv/helix/clips

before version update, this part

https://github.com/TwitchIO/TwitchIO/blob/114950a731290cff9a2b8c7cfd7b101f3eafc6af/twitchio/user.py#L1522

should be

 self.view_count: Tuple[int] = (data.get("view_count", 0),) 

or add

class User(PartialUser):

    #  "view_count" ->  "_view_count"
    __slots__ = (
        " ... ",
        "_view_count",
        "created_at",
        "email",
        "_cached_rewards",
    )

    def __init__(self, http: "TwitchHTTP", data: dict):
        self._http = http
        self.id = int(data["id"])
        self.name: str = data["login"]
        self.display_name: str = data["display_name"]
        self.type = UserTypeEnum(data["type"])
        self.broadcaster_type = BroadcasterTypeEnum(data["broadcaster_type"])
        self.description: str = data["description"]
        self.profile_image: str = data["profile_image_url"]
        self.offline_image: str = data["offline_image_url"]
        self._view_count: Tuple[int] = (data.get("view_count", 0), )  # this isn't supposed to be a tuple but too late to fix it!
        self.created_at = parse_timestamp(data["created_at"])
        self.email: Optional[str] = data.get("email")
        self._cached_rewards = None

    @property
    def view_count(self,) -> Tuple[int]:
        twitch_dev_ref = "https://discuss.dev.twitch.tv/t/get-users-api-endpoint-view-count-deprecation/37777"
        logging.info(f"WARNING User::view count is deprecated and not updated since April 14, 2022,\n check {twitch_dev_ref}")
        return self._view_count

    def __repr__(self):
        return f"<User id={self.id} name={self.name} display_name={self.display_name} type={self.type}>"
github-actions[bot] commented 2 years ago

Hello! Thanks for the issue. If this is a general help question, for a faster response consider joining the official Discord Server

Else if you have an issue with the library please wait for someone to help you here.

IAmTomahawkx commented 2 years ago

We have not received a concrete date for removal of this field yet, and as such nothing has been pushed by our team, as we have bigger fish to fry. feel free to turn this into a PR if you'd like to see this implemented faster! As for your second suggestion, this would be best suited to be in the docs, not a warning every time the attribute is accessed.

As this library follows semver principals, we cannot remove or modify this field in the current major version of the lib, although it will be done for our 3.0 release, whenever that happens in the distant future. If you'd like to see a warning in the docs, consider opening a pull request (you can do both in 1 pr).

IAmTomahawkx commented 2 years ago

This has been addressed in e59a4f36306461955049809e368c5ef871a0f785