### PSNAWP Quick Start Example Source: https://github.com/yoshikagekira/psnawp/blob/master/README.md This example demonstrates how to initialize the PSNAWP client with an NPSSO code, retrieve personal account information, registered devices, friends list, blocked users, and trophies for a specific game. It uses environment variables for the NPSSO code and requires dotenv for loading. ```python from os import getenv from dotenv import load_dotenv from psnawp_api import PSNAWP from psnawp_api.models.search import SearchDomain from psnawp_api.models.trophies import PlatformType load_dotenv() psnawp = PSNAWP(getenv("NPSSO_CODE", "NPSSO_CODE")) # Your Personal Account Info client = psnawp.me() print(f"Online ID: {client.online_id}") print(f"Account ID: {client.account_id}") print(f"Region: {client.get_region()}") print(f"Profile: {client.get_profile_legacy()} \n") # Your Registered Devices devices = client.get_account_devices() for device in devices: print(f"Device: {device} \n") # Your Friends List friends_list = client.friends_list() for friend in friends_list: print(f"Friend: {friend} \n") # Your Players Blocked List blocked_list = client.blocked_list() for blocked_user in blocked_list: print(f"Blocked User: {blocked_user} \n") # Your Friends in "Notify when available" List available_to_play = client.available_to_play() for user in available_to_play: print(f"Available to Play: {user} \n") # Your trophies (PS4) for trophy in client.trophies("NPWR22810_00", PlatformType.PS4): print(trophy) ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/yoshikagekira/psnawp/blob/master/CONTRIBUTING.md Installs all project dependencies using Poetry. ```bash poetry install --all-extras ``` -------------------------------- ### Install PSNAWP using pip Source: https://github.com/yoshikagekira/psnawp/blob/master/docs/additional_resources/README.md Install the PSNAWP library from PyPI using pip. This is the standard method for adding the library to your Python environment. ```default pip install PSNAWP ``` -------------------------------- ### Get User Information by Account ID Source: https://github.com/yoshikagekira/psnawp/blob/master/README.md Demonstrates how to retrieve a user's Online ID using their Account ID. ```python # Example of getting a user by their account ID user_account_id = psnawp.user(account_id="9122947611907501295") print(f"User Account ID: {user_account_id.online_id}") ``` -------------------------------- ### Get Pending Friend Requests and Accept Them Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieves all pending friend requests and accepts each one. Ensure the client is authenticated. ```python requests = client.friend_requests() for request in requests: print(f"Request from: {request.online_id}") # Accept the friend request request.accept_friend_request() ``` -------------------------------- ### Get 'Notify When Available' List Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieves a list of users who have set their status to 'Notify when available'. Requires an authenticated client. ```python available_list = client.available_to_play() for user in available_list: print(f"Notify when online: {user.online_id}") ``` -------------------------------- ### Get Presence for Multiple Users Source: https://context7.com/yoshikagekira/psnawp/llms.txt Efficiently retrieves the presence status for a list of user account IDs. Provide a list of account IDs. ```python friend_ids = ["account_id_1", "account_id_2", "account_id_3"] presences = client.get_presences(friend_ids) for basic_presence in presences.get("basicPresences", []): print(f"User {basic_presence.get('accountId')}: {basic_presence.get('availability')}") ``` -------------------------------- ### Get Blocked Users List Source: https://context7.com/yoshikagekira/psnawp/llms.txt Fetches a list of all users currently blocked by the authenticated account. Requires an authenticated client. ```python blocked = client.blocked_list() for blocked_user in blocked: print(f"Blocked: {blocked_user.online_id}") ``` -------------------------------- ### Get users available to play Source: https://github.com/yoshikagekira/psnawp/blob/master/docs/additional_resources/README.md Retrieve and display a list of friends who are currently available to play. This function iterates through the 'available to play' list and prints each user. ```python # Your Friends in "Notify when available" List available_to_play = client.available_to_play() for user in available_to_play: print(f"Available to Play: {user} ") ``` -------------------------------- ### Get Detailed Game Information Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieves and prints detailed information about a game, including its name, description, genre, publisher, and release date. Requires a game object. ```python details = game.get_details() for detail in details: print(f"Name: {detail.get('name')}") print(f"Description: {detail.get('descriptions', [{}])[0].get('value')}") print(f"Genre: {detail.get('genres')}") print(f"Publisher: {detail.get('publisherName')}") print(f"Release Date: {detail.get('releaseDate')}") ``` -------------------------------- ### Initialize PSNAWP and get personal account info Source: https://github.com/yoshikagekira/psnawp/blob/master/docs/additional_resources/README.md Initialize the PSNAWP client with your NPSSO code and retrieve your personal account information, including online ID, account ID, and region. Ensure your NPSSO_CODE is set in your environment variables or passed directly. ```python from os import getenv from dotenv import load_dotenv from psnawp_api import PSNAWP from psnawp_api.models.search import SearchDomain from psnawp_api.models.trophies import PlatformType load_dotenv() psnawp = PSNAWP(getenv("NPSSO_CODE", "NPSSO_CODE")) # Your Personal Account Info client = psnawp.me() print(f"Online ID: {client.online_id}") print(f"Account ID: {client.account_id}") print(f"Region: {client.get_region()}") print(f"Profile: {client.get_profile_legacy()} ") ``` -------------------------------- ### Get User Playing Time Source: https://github.com/yoshikagekira/psnawp/blob/master/docs/additional_resources/README.md Retrieves and prints the name, play count, and play duration for all titles played by the current user. Requires the client to be authenticated. ```python titles_with_stats = client.title_stats() for title in titles_with_stats: print( f" Game: {title.name} - Play Count: {title.play_count} - Play Duration: {title.play_duration} \n" ) ``` -------------------------------- ### Get All Chat Groups Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieves a list of all chat groups the user is a part of, with options for limiting and offsetting results. Requires an authenticated PSNAWP client. ```python groups = client.get_groups(limit=50, offset=0) for group in groups: info = group.get_group_information() print(f"Group ID: {group.group_id}") print(f"Group Name: {info.get('groupName', {}).get('value', 'DM')}") print(f"Members: {len(info.get('members', []))}") print("---") ``` -------------------------------- ### Get Detailed Game Info from Search Result Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieves detailed information for a game found via search, including access to its media assets like images and videos. Requires a search result for a game. ```python game_results = psnawp.search("Spider-Man", SearchDomain.FULL_GAMES, limit=1) for result in game_results: game_info = result.get("result", {}) # Access media (images, videos) for media in game_info.get("media", []): print(f"Media Type: {media.get('type')}" - Role: {media.get('role')}) print(f"URL: {media.get('url')}") ``` -------------------------------- ### Get Trophies for a Game Source: https://context7.com/yoshikagekira/psnawp/llms.txt Fetches trophies for a specific game, even if the user does not own it. Requires a game object and a trophy group ID. ```python trophies = game.trophies(trophy_group_id="all") for trophy in trophies: print(f"Trophy: {trophy.trophy_name} ({trophy.trophy_type})") ``` -------------------------------- ### Get Title Icon URL (PS3/PS4) Source: https://context7.com/yoshikagekira/psnawp/llms.txt Attempts to retrieve the title icon URL for PS3/PS4 games. Includes error handling for cases where the icon cannot be fetched. ```python try: icon_url = game.get_title_icon_url() print(f"Icon URL: {icon_url}") except Exception as e: print(f"Cannot get icon: {e}") ``` -------------------------------- ### Access and Get Group Information Source: https://context7.com/yoshikagekira/psnawp/llms.txt Accesses an existing group by its ID and retrieves its information, including the group name and a list of members. Requires an existing group ID. ```python group = psnawp.group(group_id="existing_group_id") info = group.get_group_information() print(f"Group Name: {info.get('groupName', {}).get('value')}") for member in info.get("members", []): print(f"Member: {member.get('onlineId')}") ``` -------------------------------- ### Get Title Stats and Play History Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieve play time statistics and game history for PS4 and PS5 titles for the authenticated user or another user. Requires initialization with an NPSSO code. ```python from psnawp_api import PSNAWP psnawp = PSNAWP("") client = psnawp.me() # Get title stats for authenticated user title_stats = client.title_stats(limit=20, offset=0, page_size=50) for title in title_stats: print(f"Game: {title.name}") print(f"Title ID: {title.title_id}") print(f"Play Count: {title.play_count}") print(f"Play Duration: {title.play_duration}") print(f"First Played: {title.first_played_date_time}") print(f"Last Played: {title.last_played_date_time}") print(f"Category: {title.category}") print("---") # Get title stats for another user user = psnawp.user(online_id="VaultTec_Trading") try: user_stats = user.title_stats(limit=10) for title in user_stats: print(f"{title.name}: {title.play_duration}") except Exception as e: print(f"Cannot view stats: {e}") # Privacy restricted ``` -------------------------------- ### Get User Playing Time Statistics Source: https://github.com/yoshikagekira/psnawp/blob/master/README.md Fetches and displays the playing time statistics for games on PS4 and PS5. It iterates through the titles, printing the game name, play count, and total play duration. ```python # Your Playing time (PS4, PS5 above only) titles_with_stats = client.title_stats() for title in titles_with_stats: print( f" Game: {title.name} - Play Count: {title.play_count} - Play Duration: {title.play_duration} " ) ``` -------------------------------- ### Get Trophy Groups Summary Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieves a summary of trophy groups for a game, including the game title and the total number of defined trophies. Requires a game object. ```python groups = game.trophy_groups_summary() print(f"Game: {groups.trophy_title_name}") print(f"Total Trophies: {groups.defined_trophies}") ``` -------------------------------- ### Get Trophy Titles for Specific Games Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieves trophy title information for a specific game using its title ID. Requires initialization with an NPSSO code. ```python from psnawp_api import PSNAWP from psnawp_api.models.trophies import PlatformType psnawp = PSNAWP("") client = psnawp.me() # Get trophy titles for specific games specific_titles = client.trophy_titles_for_title(title_ids=["CUSA00265_00"]) for title in specific_titles: print(f"Title: {title.title_name}") ``` -------------------------------- ### Get Overall Trophy Summary Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieves a summary of the authenticated user's trophy achievements, including level, progress, and counts for each trophy type. Requires initialization with an NPSSO code. ```python from psnawp_api import PSNAWP from psnawp_api.models.trophies import PlatformType psnawp = PSNAWP("") client = psnawp.me() # Get overall trophy summary summary = client.trophy_summary() print(f"Trophy Level: {summary.trophy_level}") print(f"Progress: {summary.progress}%") print(f"Tier: {summary.tier}") print(f"Bronze: {summary.earned_trophies.bronze}") print(f"Silver: {summary.earned_trophies.silver}") print(f"Gold: {summary.earned_trophies.gold}") print(f"Platinum: {summary.earned_trophies.platinum}") ``` -------------------------------- ### Get Conversation History Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieves the message history for a group chat, including sender, message body, and timestamp. Supports limiting the number of messages fetched. ```python messages = group.get_conversation(limit=20) for msg in messages.get("messages", []): sender = msg.get("sender", {}).get("onlineId") body = msg.get("body") timestamp = msg.get("createdTimestamp") print(f"[{timestamp}] {sender}: {body}") ``` -------------------------------- ### Get npsso code from PlayStation Network Source: https://github.com/yoshikagekira/psnawp/blob/master/docs/additional_resources/README.md This JSON snippet shows the expected format for the npsso code obtained from the PlayStation Network. This code is crucial for authenticating with the PSNAWP library. ```json {"npsso":"<64 character npsso code>"} ``` -------------------------------- ### Fetch trophies for a specific game Source: https://github.com/yoshikagekira/psnawp/blob/master/docs/additional_resources/README.md Retrieve trophies for a given game ID and platform type (e.g., PS4). This example shows how to fetch trophies for the game identified by 'NPWR22810_00' on PS4. ```python # Your trophies (PS4) for trophy in client.trophies("NPWR22810_00", PlatformType.PS4): print(trophy) ``` -------------------------------- ### Get Trophies with Progress Information Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieves trophy details for a specific game, including earned status, dates, rarity, and earn rate. Requires NP Communication ID and PlatformType. Use `include_progress=True`. ```python from psnawp_api import PSNAWP from psnawp_api.models.trophies import PlatformType psnawp = PSNAWP("") client = psnawp.me() # Get trophies with progress information trophies_with_progress = client.trophies( np_communication_id="NPWR22810_00", platform=PlatformType.PS4, include_progress=True ) for trophy in trophies_with_progress: print(f"Trophy: {trophy.trophy_name}") print(f"Earned: {trophy.earned}") print(f"Earned Date: {trophy.earned_date_time}") print(f"Rarity: {trophy.trophy_rarity}") print(f"Earn Rate: {trophy.trophy_earn_rate}%") print("---") ``` -------------------------------- ### Get Another User's Friends List Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieves the friends list of another user, if their privacy settings allow. Handles potential privacy exceptions. ```python other_user = psnawp.user(online_id="VaultTec_Trading") try: their_friends = other_user.friends_list(limit=50) for friend in their_friends: print(f"Their friend: {friend.online_id}") except Exception as e: print(f"Cannot view friends list: {e}") ``` -------------------------------- ### Get Trophy Groups Summary Source: https://context7.com/yoshikagekira/psnawp/llms.txt Fetches a summary of trophy groups for a game, including the main game and any DLCs, along with progress and earned trophy counts for each group. Requires NP Communication ID and PlatformType. Use `include_progress=True`. ```python from psnawp_api import PSNAWP from psnawp_api.models.trophies import PlatformType psnawp = PSNAWP("") client = psnawp.me() # Get trophy groups summary (main game + DLCs) groups_summary = client.trophy_groups_summary( np_communication_id="NPWR22810_00", platform=PlatformType.PS4, include_progress=True ) print(f"Title: {groups_summary.trophy_title_name}") for group in groups_summary.trophy_groups: print(f"Group: {group.trophy_group_name}") print(f"Progress: {group.progress}%") print(f"Earned: {group.earned_trophies}") ``` -------------------------------- ### Get All Trophy Titles (Games with Trophies) Source: https://context7.com/yoshikagekira/psnawp/llms.txt Fetches a list of all trophy titles (games) associated with the authenticated user's account. Includes game name, platform, progress, and NP Communication ID. Requires initialization with an NPSSO code. ```python from psnawp_api import PSNAWP from psnawp_api.models.trophies import PlatformType psnawp = PSNAWP("") client = psnawp.me() # Get all trophy titles (games with trophies) trophy_titles = client.trophy_titles(limit=50) for title in trophy_titles: print(f"Game: {title.title_name}") print(f"Platform: {title.title_platform}") print(f"Progress: {title.progress}%") print(f"NP Communication ID: {title.np_communication_id}") print(f"Earned: {title.earned_trophies}") print("---") ``` -------------------------------- ### Get User Chat Groups Source: https://github.com/yoshikagekira/psnawp/blob/master/README.md Retrieves and prints information about the user's chat groups. It iterates through the groups, extracts the first group's ID for later use, and prints details for each group. ```python groups = client.get_groups() first_group_id = None # This will be used later to test group methods for id, group in enumerate(groups): if id == 0: # Get the first group ID first_group_id = group.group_id group_info = group.get_group_information() print(f"Group {id}: {group_info} ") ``` -------------------------------- ### Get Individual Trophies for a Game (Without Progress) Source: https://context7.com/yoshikagekira/psnawp/llms.txt Fetches individual trophy details for a specific game, including name, description, type, and hidden status. Does not include progress information. Requires NP Communication ID and PlatformType. Use `limit=None` to retrieve all trophies. ```python from psnawp_api import PSNAWP from psnawp_api.models.trophies import PlatformType psnawp = PSNAWP("") client = psnawp.me() # Get individual trophies for a game (without progress) trophies = client.trophies( np_communication_id="NPWR22810_00", platform=PlatformType.PS4, trophy_group_id="all", # "all", "default", or "001", "002" for DLCs limit=None # Get all trophies ) for trophy in trophies: print(f"Trophy: {trophy.trophy_name}") print(f"Description: {trophy.trophy_detail}") print(f"Type: {trophy.trophy_type}") print(f"Hidden: {trophy.trophy_hidden}") print("---") ``` -------------------------------- ### Get Game Entitlements (Owned Games) Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieve a list of games owned by the authenticated user, including PS4 and PS5 titles. Can also be used to check if specific games are owned by providing a list of title IDs. ```python from psnawp_api import PSNAWP psnawp = PSNAWP("") client = psnawp.me() # Get all game entitlements (owned games) entitlements = client.game_entitlements(limit=50, offset=0, page_size=20) for game in entitlements: print(f"Game: {game.name}") print(f"Title ID: {game.title_id}") print(f"Entitlement ID: {game.entitlement_id}") print(f"Active Date: {game.active_date}") print("---") # Check if specific games are owned owned = client.game_entitlements( title_ids=["CUSA00265_00", "CUSA07408_00"] ) for game in owned: print(f"You own: {game.name}") ``` -------------------------------- ### Get User Information by Account ID Source: https://github.com/yoshikagekira/psnawp/blob/master/docs/additional_resources/README.md Retrieves the Online ID of a PlayStation Network user using their Account ID. This is an alternative method to fetching user details when the Account ID is known. ```python user_account_id = psnawp.user(account_id="9122947611907501295") print(f"User Account ID: {user_account_id.online_id}") ``` -------------------------------- ### Get Another User's Trophy Summary and Titles Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieves the trophy summary and a list of trophy titles for another user, provided their privacy settings allow. Requires the user's online ID and initialization with an NPSSO code. ```python from psnawp_api import PSNAWP from psnawp_api.models.trophies import PlatformType psnawp = PSNAWP("") user = psnawp.user(online_id="VaultTec_Trading") user_summary = user.trophy_summary() print(f"{user.online_id}'s Trophy Level: {user_summary.trophy_level}") user_titles = user.trophy_titles(limit=10) for title in user_titles: print(f"{title.title_name}: {title.progress}%") ``` -------------------------------- ### Get User Information by Online ID Source: https://github.com/yoshikagekira/psnawp/blob/master/docs/additional_resources/README.md Fetches and prints various details of a PlayStation Network user using their Online ID. This includes account ID, region, profile information, previous online IDs, presence status, friendship status, and blocked status. ```python example_user_1 = psnawp.user(online_id="VaultTec-Co") # Get a PSN player by their Online ID print(f"User 1 Online ID: {example_user_1.online_id}") print(f"User 1 Account ID: {example_user_1.account_id}") print(f"User 1 Region: {example_user_1.get_region()}") print(example_user_1.profile()) print(example_user_1.prev_online_id) print(example_user_1.get_presence()) print(example_user_1.friendship()) print(example_user_1.is_blocked()) ``` -------------------------------- ### Get User Profile Information by Online ID Source: https://github.com/yoshikagekira/psnawp/blob/master/README.md Retrieves and prints various details of a PlayStation Network user using their Online ID. This includes online ID, account ID, region, profile data, previous online IDs, presence status, friendship status, and block status. ```python # Other User's example_user_1 = psnawp.user(online_id="VaultTec-Co") # Get a PSN player by their Online ID print(f"User 1 Online ID: {example_user_1.online_id}") print(f"User 1 Account ID: {example_user_1.account_id}") print(f"User 1 Region: {example_user_1.get_region()}") print(example_user_1.profile()) print(example_user_1.prev_online_id) print(example_user_1.get_presence()) print(example_user_1.friendship()) print(example_user_1.is_blocked()) ``` -------------------------------- ### Run Static Analysis, Formatting, and Linting Source: https://github.com/yoshikagekira/psnawp/blob/master/CONTRIBUTING.md Executes the pre-push script to perform static analysis, formatting, and linting checks. ```bash python3 pre_push.py ``` -------------------------------- ### Run Tests Source: https://github.com/yoshikagekira/psnawp/blob/master/CONTRIBUTING.md Executes the test suite using the pre-push script. ```bash python3 pre_push.py -nu ``` -------------------------------- ### Initialize PSNAWP Client Source: https://context7.com/yoshikagekira/psnawp/llms.txt Requires an NPSSO cookie for authentication. Supports custom headers for localization and custom rate limiting configurations. ```python from psnawp_api import PSNAWP from pyrate_limiter import Rate, Duration # Basic initialization with NPSSO cookie psnawp = PSNAWP("<64 character npsso code>") # Initialize with custom headers for localization custom_headers = { "Accept-Language": "ja-JP", # Japanese language "Country": "JP" # Japan region } psnawp = PSNAWP("", headers=custom_headers) # Initialize with custom rate limit (use with caution) custom_rate = Rate(1, Duration.SECOND * 5) # 1 request per 5 seconds psnawp = PSNAWP("", rate_limit=custom_rate) ``` -------------------------------- ### Activate Virtual Environment Source: https://github.com/yoshikagekira/psnawp/blob/master/CONTRIBUTING.md Activates the Poetry-managed virtual environment for the project. ```bash poetry shell ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/yoshikagekira/psnawp/blob/master/CONTRIBUTING.md Template for the .env file required for running tests. ```bash NPSSO_CODE= USER_NAME= FRIEND_USER_NAME= BLOCKED_USER_NAME= ``` -------------------------------- ### Handle PSNAWP Not Found Errors Source: https://context7.com/yoshikagekira/psnawp/llms.txt Demonstrates how to catch and handle PSNAWPNotFoundError, which is raised when a requested user or resource does not exist. ```python from psnawp_api import PSNAWP from psnawp_api.core import ( PSNAWPAuthenticationError, PSNAWPNotFoundError, PSNAWPForbiddenError, PSNAWPBadRequestError, PSNAWPTooManyRequestsError, PSNAWPIllegalArgumentError, ) try: psnawp = PSNAWP("") user = psnawp.user(online_id="NonExistentUser12345") except PSNAWPNotFoundError as e: print(f"User not found: {e}") ``` -------------------------------- ### Create a New Group with Users Source: https://context7.com/yoshikagekira/psnawp/llms.txt Creates a new group chat with specified users. Requires PSNAWP user objects for each member. ```python user1 = psnawp.user(online_id="Friend1") user2 = psnawp.user(online_id="Friend2") new_group = psnawp.group(users_list=[user1, user2]) print(f"Created group: {new_group.group_id}") ``` -------------------------------- ### Create a New Group Chat Source: https://github.com/yoshikagekira/psnawp/blob/master/docs/additional_resources/README.md Shows how to create a new group chat with specified users. It then retrieves and prints the information for the newly created group. The users must be valid PSN users. ```python # Create a new group with other users - i.e. 'VaultTec-Co' and 'test' example_user_2 = psnawp.user(online_id="test") new_group = psnawp.group(users_list=[example_user_1, example_user_2]) print(new_group.get_group_information()) # You can use the same above methods to interact with the new group - i.e. send messages, change name, etc. ``` -------------------------------- ### Retrieve Authenticated Client Information Source: https://context7.com/yoshikagekira/psnawp/llms.txt Use the me() method to access account data, trophies, and messaging features for the authenticated user. ```python from psnawp_api import PSNAWP psnawp = PSNAWP("") client = psnawp.me() # Get basic account information print(f"Online ID: {client.online_id}") print(f"Account ID: {client.account_id}") print(f"Region: {client.get_region()}") # Get legacy profile with detailed information profile = client.get_profile_legacy() print(f"About Me: {profile.get('profile', {}).get('aboutMe')}") print(f"Plus Member: {profile.get('profile', {}).get('plus')}") # Get registered devices devices = client.get_account_devices() for device in devices: print(f"Device Type: {device.get('deviceType')}") print(f"Device ID: {device.get('deviceId')}") # Get shareable profile link with QR code shareable = client.get_shareable_profile_link() print(f"Profile URL: {shareable.get('shareableProfileUrl')}") print(f"QR Code URL: {shareable.get('qrCodeUrl')}") ``` -------------------------------- ### Handle PSNAWP Forbidden Errors Source: https://context7.com/yoshikagekira/psnawp/llms.txt Demonstrates how to catch and handle PSNAWPForbiddenError, which is raised when access to a resource is denied, such as a private user profile. ```python from psnawp_api import PSNAWP from psnawp_api.core import ( PSNAWPAuthenticationError, PSNAWPNotFoundError, PSNAWPForbiddenError, PSNAWPBadRequestError, PSNAWPTooManyRequestsError, PSNAWPIllegalArgumentError, ) try: user = psnawp.user(online_id="PrivateUser") presence = user.get_presence() except PSNAWPForbiddenError as e: print(f"Access denied (private profile): {e}") ``` -------------------------------- ### Handle PSNAWP Authentication Errors Source: https://context7.com/yoshikagekira/psnawp/llms.txt Demonstrates how to catch and handle PSNAWPAuthenticationError, which occurs when the provided NPSSO code is invalid. ```python from psnawp_api import PSNAWP from psnawp_api.core import ( PSNAWPAuthenticationError, PSNAWPNotFoundError, PSNAWPForbiddenError, PSNAWPBadRequestError, PSNAWPTooManyRequestsError, PSNAWPIllegalArgumentError, ) try: psnawp = PSNAWP("") except PSNAWPAuthenticationError as e: print(f"Authentication failed: {e}") print(f"Error code: {e.code}") print(f"Reference ID: {e.reference_id}") ``` -------------------------------- ### Handle Generic PSNAWP Errors Source: https://context7.com/yoshikagekira/psnawp/llms.txt Demonstrates generic exception handling for any PSNAWPError, allowing access to the error code and message. ```python from psnawp_api.core import PSNAWPError try: # Any PSNAWP operation result = some_operation() except PSNAWPError as e: print(f"PSNAWP error: {e}") print(f"Code: {e.code}") print(f"Message: {e.message}") ``` -------------------------------- ### Interact with a Group Chat Source: https://github.com/yoshikagekira/psnawp/blob/master/docs/additional_resources/README.md Demonstrates how to interact with an existing group chat, including retrieving group information, fetching recent messages, sending a message, changing the group's name, and leaving the group. Requires a valid `first_group_id`. ```python group = psnawp.group(group_id=first_group_id) # This is the first group ID we got earlier - i.e. the first group in your groups list print(group.get_group_information()) print(group.get_conversation(10)) # Get the last 10 messages in the group group.send_message("Hello World") group.change_name("API Testing 3") group.leave_group() ``` -------------------------------- ### Handle PSNAWP Too Many Requests Errors Source: https://context7.com/yoshikagekira/psnawp/llms.txt Demonstrates how to catch and handle PSNAWPTooManyRequestsError, which is raised when the API rate limit is exceeded. ```python from psnawp_api import PSNAWP from psnawp_api.core import ( PSNAWPAuthenticationError, PSNAWPNotFoundError, PSNAWPForbiddenError, PSNAWPBadRequestError, PSNAWPTooManyRequestsError, PSNAWPIllegalArgumentError, ) try: # Too many rapid requests for i in range(1000): client = psnawp.me() except PSNAWPTooManyRequestsError as e: print(f"Rate limited: {e}") ``` -------------------------------- ### Invite Members to a Group Source: https://context7.com/yoshikagekira/psnawp/llms.txt Invites additional users to an existing group chat. Requires a group object and a list of PSNAWP user objects to invite. ```python user3 = psnawp.user(online_id="Friend3") group.invite_members([user3]) ``` -------------------------------- ### Create GameTitle Object with Known NP Communication ID Source: https://context7.com/yoshikagekira/psnawp/llms.txt Initializes a GameTitle object using a title ID, NP Communication ID, and platform, avoiding an extra API call to fetch the NP Communication ID. Requires initialization with an NPSSO code. ```python from psnawp_api import PSNAWP from psnawp_api.models.trophies import PlatformType psnawp = PSNAWP("") # Create GameTitle with known np_communication_id (avoids extra API call) game = psnawp.game_title( title_id="CUSA00265_00", platform=PlatformType.PS4, np_communication_id="NPWR22810_00" ) ``` -------------------------------- ### Search for Add-ons/DLC Source: https://context7.com/yoshikagekira/psnawp/llms.txt Searches the PlayStation Store for add-ons and DLC. Supports specifying search query and limit. Returns add-on details like name and classification. ```python addon_results = psnawp.search( search_query="Expansion Pass", search_domain=SearchDomain.ADD_ONS, limit=5 ) for result in addon_results: addon = result.get("result", {}) print(f"Add-on: {addon.get('name')}") print(f"Type: {addon.get('localizedStoreDisplayClassification')}") ``` -------------------------------- ### Handle PSNAWP Bad Request Errors Source: https://context7.com/yoshikagekira/psnawp/llms.txt Demonstrates how to catch and handle PSNAWPBadRequestError, which is raised for malformed requests or invalid parameters. ```python from psnawp_api import PSNAWP from psnawp_api.core import ( PSNAWPAuthenticationError, PSNAWPNotFoundError, PSNAWPForbiddenError, PSNAWPBadRequestError, PSNAWPTooManyRequestsError, PSNAWPIllegalArgumentError, ) try: group = psnawp.group(group_id="invalid_group_id") group.change_name("New Name") except PSNAWPBadRequestError as e: print(f"Bad request: {e}") ``` -------------------------------- ### Search for Full Games Source: https://context7.com/yoshikagekira/psnawp/llms.txt Searches the PlayStation Store for full game titles. Allows specifying search query, domain, limit, offset, and page size. Returns game details including name, ID, platforms, and pricing. ```python game_results = psnawp.search( search_query="Grand Theft Auto", search_domain=SearchDomain.FULL_GAMES, limit=10, offset=0, page_size=20 ) for result in game_results: game = result.get("result", {}) print(f"Name: {game.get('name')}") print(f"ID: {game.get('id')}") print(f"Platforms: {game.get('platforms')}") # Get pricing info price = game.get("price", {}) if price: print(f"Price: {price.get('discountedPrice')} {price.get('currencyCode')}") if price.get("discountText"): print(f"Discount: {price.get('discountText')}") print("---") ``` -------------------------------- ### Retrieve registered account devices Source: https://github.com/yoshikagekira/psnawp/blob/master/docs/additional_resources/README.md Fetch and display a list of devices registered to your PlayStation Network account. This requires an authenticated PSNAWP client. ```python # Your Registered Devices devices = client.get_account_devices() for device in devices: print(f"Device: {device} ") ``` -------------------------------- ### Create GameTitle Object from Title ID Source: https://context7.com/yoshikagekira/psnawp/llms.txt Initializes a GameTitle object using a title ID and platform, making an API call to retrieve the NP Communication ID. Requires initialization with an NPSSO code. ```python from psnawp_api import PSNAWP from psnawp_api.models.trophies import PlatformType psnawp = PSNAWP("") # Create GameTitle from title_id (makes API call to get np_communication_id) game = psnawp.game_title( title_id="CUSA00265_00", platform=PlatformType.PS4 ) print(f"Title ID: {game.title_id}") print(f"NP Communication ID: {game.np_communication_id}") ``` -------------------------------- ### Initialize PS3 Game Object Source: https://context7.com/yoshikagekira/psnawp/llms.txt Initializes a game object for a PS3 title, requiring the title ID, platform type, and np_communication_id. The np_communication_id is mandatory for PS3/Vita games. ```python ps3_game = psnawp.game_title( title_id="NPWR00132_00", platform=PlatformType.PS3, np_communication_id="NPWR00132_00" # Required for PS3/Vita ) ``` -------------------------------- ### Handle PSNAWP Illegal Argument Errors Source: https://context7.com/yoshikagekira/psnawp/llms.txt Demonstrates how to catch and handle PSNAWPIllegalArgumentError, which is raised when a required argument is missing or invalid. ```python from psnawp_api import PSNAWP from psnawp_api.core import ( PSNAWPAuthenticationError, PSNAWPNotFoundError, PSNAWPForbiddenError, PSNAWPBadRequestError, PSNAWPTooManyRequestsError, PSNAWPIllegalArgumentError, ) try: # Missing required argument user = psnawp.user() # No online_id or account_id except PSNAWPIllegalArgumentError as e: print(f"Invalid argument: {e}") ``` -------------------------------- ### Manage Friends List Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieve and manage friend relationships, including listing friends with pagination support. ```python from psnawp_api import PSNAWP psnawp = PSNAWP("") client = psnawp.me() # Get friends list (up to 1000 friends) friends = client.friends_list(limit=100) for friend in friends: print(f"Friend: {friend.online_id} ({friend.account_id})") ``` -------------------------------- ### Search for Game Titles Source: https://github.com/yoshikagekira/psnawp/blob/master/docs/additional_resources/README.md Performs a search for game titles based on a query and domain. It then iterates through the search results and prints the invariant name of each result. Ensure `SearchDomain.FULL_GAMES` is imported or available. ```python search = psnawp.search(search_query="GTA 5", search_domain=SearchDomain.FULL_GAMES) for search_result in search: print(search_result["result"]["invariantName"]) ``` -------------------------------- ### Look Up Other Users Source: https://context7.com/yoshikagekira/psnawp/llms.txt Retrieve profile, presence, and friendship status for other users using their Online ID or Account ID. ```python from psnawp_api import PSNAWP psnawp = PSNAWP("") # Get user by Online ID (gamertag) user = psnawp.user(online_id="VaultTec_Trading") print(f"Online ID: {user.online_id}") print(f"Account ID: {user.account_id}") # Get user by Account ID user = psnawp.user(account_id="1802043923080044300") # Get user profile details profile = user.profile() print(f"Avatar URL: {profile.get('avatarUrls', [{}])[0].get('avatarUrl')}") print(f"Languages: {profile.get('languagesUsed')}") print(f"About Me: {profile.get('aboutMe')}") # Get user's region region = user.get_region() if region: print(f"Country: {region.name}") # Check presence (online/offline status) try: presence = user.get_presence() print(f"Online Status: {presence.get('basicPresence', {}).get('availability')}") print(f"Last Online: {presence.get('basicPresence', {}).get('lastAvailableDate')}") except Exception as e: print(f"Cannot view presence: {e}") # Check friendship status friendship = user.friendship() print(f"Friend Status: {friendship.get('friendRelation')}") print(f"Mutual Friends: {friendship.get('mutualFriendsCount')}") # Check if user is blocked is_blocked = user.is_blocked() print(f"Is Blocked: {is_blocked}") # Get shareable profile link link = user.get_shareable_profile_link() print(f"Share URL: {link.get('shareableProfileUrl')}") ``` -------------------------------- ### Search for Users Source: https://context7.com/yoshikagekira/psnawp/llms.txt Searches for users on the PlayStation Network. Allows specifying search query and limit. Returns user details including online ID, account ID, and highlights. ```python user_results = psnawp.search( search_query="VaultTec", search_domain=SearchDomain.USERS, limit=10 ) for result in user_results: print(f"User: {result.get('socialMetadata', {}).get('onlineId')}") print(f"Account ID: {result.get('socialMetadata', {}).get('accountId')}") print(f"Highlights: {result.get('highlight', {}).get('onlineId')}") ``` -------------------------------- ### Search for Game Titles Source: https://github.com/yoshikagekira/psnawp/blob/master/README.md Searches for game titles based on a query and a specified domain. It iterates through the search results and prints the invariant name of each result. ```python # Searching for Game Titles search = psnawp.search(search_query="GTA 5", search_domain=SearchDomain.FULL_GAMES) for search_result in search: print(search_result["result"]["invariantName"]) ``` -------------------------------- ### Retrieve and display blocked users list Source: https://github.com/yoshikagekira/psnawp/blob/master/docs/additional_resources/README.md Fetch and print a list of users that have been blocked on your PlayStation Network account. The code iterates through the blocked list and prints each blocked user's information. ```python # Your Players Blocked List blocked_list = client.blocked_list() for blocked_user in blocked_list: print(f"Blocked User: {blocked_user} ") ``` -------------------------------- ### Leave a Group Source: https://context7.com/yoshikagekira/psnawp/llms.txt Allows the current user to leave a group chat. Requires a group object. ```python group.leave_group() ``` -------------------------------- ### Send a Message to a Group Source: https://context7.com/yoshikagekira/psnawp/llms.txt Sends a message to a group chat. Requires a group object and the message content. ```python response = group.send_message("Hello from PSNAWP!") print(f"Message sent: {response.get('messageUid')}") ``` -------------------------------- ### Retrieve and display chat group information Source: https://github.com/yoshikagekira/psnawp/blob/master/docs/additional_resources/README.md Fetch and display information about your PlayStation Network chat groups. The code iterates through the groups, retrieves details for each, and prints them. It also stores the first group's ID for potential further use. ```python # Your Chat Groups groups = client.get_groups() first_group_id = None # This will be used later to test group methods for id, group in enumerate(groups): if id == 0: # Get the first group ID first_group_id = group.group_id group_info = group.get_group_information() print(f"Group {id}: {group_info} ") ``` -------------------------------- ### Fetch and display friends list Source: https://github.com/yoshikagekira/psnawp/blob/master/docs/additional_resources/README.md Retrieve and print the list of friends associated with your PlayStation Network account. This function iterates through the friends list and prints each friend's details. ```python # Your Friends List friends_list = client.friends_list() for friend in friends_list: print(f"Friend: {friend} ") ``` -------------------------------- ### Remove a Friend or Decline a Friend Request Source: https://context7.com/yoshikagekira/psnawp/llms.txt Removes a user from the friends list or declines an incoming friend request. Requires the user's online ID. ```python user = psnawp.user(online_id="SomeUser") user.remove_friend() ``` -------------------------------- ### Kick a Member from a Group Source: https://context7.com/yoshikagekira/psnawp/llms.txt Removes a member from a group chat. Includes error handling for cases where the member cannot be kicked. ```python try: group.kick_member(user3) except Exception as e: print(f"Cannot kick member: {e}") ``` -------------------------------- ### Interact with a Chat Group Source: https://github.com/yoshikagekira/psnawp/blob/master/README.md Performs various operations on a specific chat group, identified by its ID. This includes retrieving group information, fetching recent messages, sending a message, changing the group's name, and leaving the group. ```python # Messaging and Groups Interaction group = psnawp.group(group_id=first_group_id) # This is the first group ID we got earlier - i.e. the first group in your groups list print(group.get_group_information()) print(group.get_conversation(10)) # Get the last 10 messages in the group group.send_message("Hello World") group.change_name("API Testing 3") group.leave_group() ``` -------------------------------- ### Change Group Name Source: https://context7.com/yoshikagekira/psnawp/llms.txt Changes the name of a group chat. This functionality is not available for direct messages (DMs). Includes error handling for unsupported operations. ```python try: group.change_name("My New Group Name") except Exception as e: print(f"Cannot change name: {e}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.