psnawp_api.utils.misc module#
Miscellaneous functions that are used throughout the psnawp module.
- extract_region_from_npid(npid: str) Country | None[source]#
Extracts the region code from a base64-encoded NPID string and converts it to a full country.
The function decodes the NPID, extracts the last two characters representing the ISO 3166-1 alpha-2 region code, and uses the pycountry library to map it to a full country.
- Parameters:
npid – The base64-encoded NPID string, which is decoded to extract the region code.
- Returns:
The region as a
Countryobject, orNoneif extraction fails or region is invalid.
This function assumes a valid NPID format (e.g., “VaultTec-Co@b7.us”). It splits the string to get the region code (e.g., “US”), which is then matched to the full country using the pycountry library.
- get_temp_db_path(filename: str | None = None) Path[source]#
Create a writable temporary directory and database file.
- Parameters:
filename – Name of the SQLite database file.
- Returns:
Path to the writable SQLite database.
- iso_format_to_datetime(iso_format: str | None) datetime | None[source]#
Converts an ISO 8601 formatted string to a
datetimeobject.- Parameters:
iso_format – The ISO 8601 formatted string (e.g., “2025-02-26T12:00:00Z”).
- Returns:
The corresponding
datetimeobject, orNoneif input isNone.
- parse_npsso_token(npsso_input: str) str[source]#
Accept string from the user that may contain either a valid npsso token or a json string with key “npsso” and value of the npsso token.
This function either succeeds at extracting the npsso token from the provided input (meaning a valid npsso json string was provided) or it returns the original input.
- Parameters:
npsso_input – User provided input for npsso token.
- Returns:
Extracted npsso token from user input or the original string.
- Raises:
PSNAWPInvalidTokenError – If malformed npsso JSON is supplied