diff options
| author | Pinapelz <donaldshan1@outlook.com> | 2023-06-20 02:15:12 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-20 02:15:12 -0700 |
| commit | 5b25b6e64140e02c244456973e9305fe43c355c6 (patch) | |
| tree | 6930d7ae771fb188fc6a3a0f7f1f81bad5bf84f2 /webapi/holodex.py | |
| parent | c929c11f9006db67e10ddd7fa599124a6edeadeb (diff) | |
| parent | 70237b5a5d82e8425eb5870a975bde497a6def08 (diff) | |
Merge pull request #2 from pinapelz/develop-rewrite
Refactored entire codebase
Diffstat (limited to 'webapi/holodex.py')
| -rw-r--r-- | webapi/holodex.py | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/webapi/holodex.py b/webapi/holodex.py index 6a5dc93..5f81892 100644 --- a/webapi/holodex.py +++ b/webapi/holodex.py @@ -1,4 +1,5 @@ from webapi.web_api import WebAPI +from typing import Iterable class HolodexAPI(WebAPI): @@ -6,62 +7,69 @@ class HolodexAPI(WebAPI): Class for interacting with the Holodex API """ - def __init__(self, api_key: str = None, member_count: int = 300, - organization: str = "Nijisanji"): - super().__init__(api_key = api_key, base_url = "https://holodex.net/api/v2/") + def __init__(self,api_key: str = None,member_count: int = 300,organization: str = "Nijisanji"): + super().__init__(api_key=api_key, base_url="https://holodex.net/api/v2/") self.member_count = member_count self.organization = organization self._inactive_channels = [] - self._active_channels = [] + self._channel_data = [] - def get_data_all_channels(self) -> list: + def get_subscriber_data(self) -> Iterable: """ Gets data for all channels in a particular organization """ members = self.member_count data = [] - filtered_data = [] + active_channels = [] offset = 0 while members > 0: data += self._download_url( - f"channels?type=vtuber&offset={offset}&limit=100&org={self.organization}") + f"channels?type=vtuber&offset={offset}&limit=100&org={self.organization}" + ) members -= 100 offset += 100 for channel in data: - print(channel['name']) - if channel['inactive'] is False: - try: - self._active_channels.append(channel['id'] + "," + channel['english_name']) - except (KeyError, TypeError, ValueError): - self._active_channels.append(channel['id'] + "," + channel['name']) - channel['description'] = self.get_channel_description(channel['id']) - filtered_data.append(channel) - else: - self._inactive_channels.append(channel['id']) - return filtered_data - - def get_exclude_channels(self) -> list: - """ - Gets the list of excluded channels - """ - return self._inactive_channels + print("DEBUG: ", channel["id"]) + try: + channel["description"] = self.get_channel_description(channel["id"]) + if channel["inactive"]: + self._inactive_channels.append(channel["id"]) + continue + active_channels.append(channel) + except (KeyError, TypeError, ValueError): + print("DEBUG:","An error occured with parsing ", channel["id"], channel["name"]) + continue + self._channel_data = active_channels + return active_channels def get_view_count(self, channel_id: str) -> int: """ Gets the view count for a particular channel """ data = self._download_url(f"channels/{channel_id}") - return data['view_count'] + return data["view_count"] def get_channel_description(self, channel_id: str) -> str: """ Gets the description for a particular channel """ data = self._download_url(f"channels/{channel_id}") - return data['description'] + return data["description"] + + def set_organization(self, organization: str): + """ + Sets the organization for the API + """ + self.organization = organization + + def get_inactive_channels(self) -> list: + """ + Gets the list of inactive channels + """ + return self._inactive_channels - def get_active_channels(self) -> list: + def get_generated_channel_data(self) -> list: """ - Gets the list of active channels + Gets the list of channel data """ - yield from self._active_channels + return self._channel_data |
