A Python interface to archive.org for programmatic access to the Internet Archive's digital library
—
Administrative functions for managing Archive.org user accounts. This module provides the Account class for account lookup, locking, and unlocking operations.
Note: Account management functionality requires administrative privileges on Archive.org.
Retrieve account information using various identifier types.
class Account:
"""
Administrative interface for managing Archive.org user accounts.
Attributes:
locked (bool): Whether the account is locked
verified (bool): Whether the account is verified
email (str): Account email address
canonical_email (str): Canonical email address
itemname (str): Account item name
screenname (str): Account screen name
notifications (list): List of notification settings
has_disability_access (bool): Whether account has disability access
lastlogin (str): Last login timestamp
createdate (str): Account creation date
session (ArchiveSession): Session object for API calls
"""
@classmethod
def from_account_lookup(cls, identifier_type: str, identifier: str, session=None):
"""
Factory method to create Account object by looking up user information.
Args:
identifier_type (str): Type of identifier to search by:
- 'email': Search by email address
- 'screenname': Search by screen name
- 'itemname': Search by item name
identifier (str): The identifier value (e.g., 'user@example.com')
session (ArchiveSession, optional): Session object to use for the request
Returns:
Account: Account object with populated user information
Raises:
AccountAPIError: If account lookup fails, access is denied, or account not found
requests.exceptions.RequestException: If the API request fails
Example:
>>> from internetarchive.account import Account
>>> account = Account.from_account_lookup('email', 'user@example.com')
>>> print(f"Account created: {account.createdate}")
"""
@classmethod
def from_json(cls, json_data: dict, session=None):
"""
Create Account object from JSON data.
Args:
json_data (dict): Account data from API response
session (ArchiveSession, optional): Session object to use
Returns:
Account: Account object created from JSON data
"""Lock and unlock user accounts with administrative comments.
def lock(self, comment: str):
"""
Lock the user account.
Args:
comment (str): Administrative comment explaining the reason for locking
Raises:
AccountAPIError: If locking fails or insufficient privileges
requests.exceptions.RequestException: If the API request fails
Example:
>>> account = Account.from_account_lookup('email', 'spam@example.com')
>>> account.lock("Account locked due to spam activity")
"""
def unlock(self, comment: str):
"""
Unlock the user account.
Args:
comment (str): Administrative comment explaining the reason for unlocking
Raises:
AccountAPIError: If unlocking fails or insufficient privileges
requests.exceptions.RequestException: If the API request fails
Example:
>>> account = Account.from_account_lookup('email', 'user@example.com')
>>> account.unlock("Issue resolved, account reinstated")
"""
def to_dict(self):
"""
Convert account data to dictionary format.
Returns:
dict: Account information as dictionary with all account attributes
Example:
>>> account = Account.from_account_lookup('email', 'user@example.com')
>>> account_data = account.to_dict()
>>> print(account_data['screenname'])
"""from internetarchive.account import Account
# Look up account by email
account = Account.from_account_lookup('email', 'user@example.com')
# Check account status
print(f"Account locked: {account.locked}")
print(f"Account verified: {account.verified}")
print(f"Screen name: {account.screenname}")
print(f"Last login: {account.lastlogin}")
# Get full account data
account_dict = account.to_dict()
print(account_dict)from internetarchive.account import Account
from internetarchive.exceptions import AccountAPIError
try:
# Look up problematic account
account = Account.from_account_lookup('screenname', 'spammer123')
if not account.locked:
# Lock the account with explanation
account.lock("Account locked due to repeated policy violations")
print(f"Account {account.screenname} has been locked")
else:
print(f"Account {account.screenname} is already locked")
except AccountAPIError as e:
print(f"Account operation failed: {e}")
if hasattr(e, 'error_data') and e.error_data:
print(f"Error details: {e.error_data}")from internetarchive.account import Account
from internetarchive.exceptions import AccountAPIError
# List of accounts to review
suspicious_emails = [
'user1@suspicious.com',
'user2@suspicious.com',
'user3@suspicious.com'
]
for email in suspicious_emails:
try:
account = Account.from_account_lookup('email', email)
print(f"\\nAccount: {account.screenname} ({email})")
print(f"Created: {account.createdate}")
print(f"Last login: {account.lastlogin}")
print(f"Verified: {account.verified}")
print(f"Locked: {account.locked}")
# Check if action needed based on account status
if not account.verified and account.lastlogin == 'never':
print("-> Potential unused account")
except AccountAPIError as e:
print(f"Could not lookup {email}: {e}")from internetarchive.account import Account
# Process account unlock request
def process_unlock_request(email, justification):
try:
account = Account.from_account_lookup('email', email)
if account.locked:
# Review account status
print(f"Account {account.screenname} currently locked")
print(f"Created: {account.createdate}")
print(f"Last login: {account.lastlogin}")
# Unlock with justification
unlock_comment = f"Account unlocked: {justification}"
account.unlock(unlock_comment)
print(f"Account {account.screenname} has been unlocked")
return True
else:
print(f"Account {account.screenname} is not locked")
return False
except AccountAPIError as e:
print(f"Failed to process unlock request: {e}")
return False
# Example usage
result = process_unlock_request(
'user@example.com',
'False positive spam detection, legitimate user verified'
)The Account class can raise several types of exceptions:
class AccountAPIError(Exception):
"""
Account API-related errors.
Attributes:
error_data (dict, optional): Additional error information from API response
"""Common scenarios that raise AccountAPIError:
Network and HTTP-related errors are propagated as requests.exceptions.RequestException or its subclasses.
To use the Account management functionality:
Install with Tessl CLI
npx tessl i tessl/pypi-internetarchive