pwncollege.pwncollege
— The pwncollege API Client
Session Caching
If the cache
option is sent when initializing an API client, the library will follow this algorithm:
- Check if the given path exists
If it does, load the
cookie_token
from the file.Check if the
cookie_token
is expiredIf it is, fall back to a login prompt
If it isn’t, fall back to a login prompt
After any login prompts, and at program exit, the current token pair will be dumped out to the cache file.
If the option is not set, no cache is used at all.
API Client
- class pwncollege.pwncollege.PWNClient(email: str | None = None, password: str | None = None, cache: str | None = None, site_base: str = 'https://pwn.college/', app_cookie: str | None = None, notif: bool = True)[source]
The client via which API requests are made
Examples
Connecting to the API:
from pwncollege import PWNClient client = PWNClient(email="user@example.com", password="S3cr3tP455w0rd!") client = PWNClient(email="unique1234", password="S3cr3tP455w0rd!") value for email can also be username
Authenticates to the API.
If cache is set, the client will attempt to load access tokens from the given path. If they cannot be found, or are expired, normal API authentication will take place, and the tokens will be dumped to the file for the next launch.
- Parameters:
email – The authenticating user’s email address
password – The authenticating user’s password
cache – The path to load/store access tokens from/to
app_cookie – Authenticate using a provided App Cookie
- create_challenge(dojo: str, module: str, chall: Challenge) Challenge [source]
Creates a Challenge object from needed info
- do_login(email: str | None = None, password: str | None = None, app_cookie: str | None = None)[source]
Authenticates against the API. If credentials are not provided, they will be prompted for.
- do_request(endpoint, json_data=None, data=None, post=False, nonce: str | None = None, patch: bool = False) Response [source]
- Parameters:
endpoint – The API/normal endpoint to request
json_data – Data to be sent in JSON format
data – Data to be sent in application/x-www-form-urlencoded format
post – Force POST request
- Returns:
The JSON response from the API or the raw response if not JSON
- dump_to_cache(cache: str)[source]
Dumps the current access and refresh tokens to a file :param cache: The path to the cache file
- get_challenges(dojo: str, module: str) List['Challenge'] [source]
Requests a list of Challenge from the API in a module
- Parameters:
dojo – The dojo to fetch challenges from
module – The module to fetch challenges from
Returns: A list of Challenge
- get_dojo_ranking(dojo: str, duration: int = 0, page: int = 1) Leaderboard [source]
Returns: A Leaderboard of the top 20 Users in the Dojo
- get_module_ranking(dojo: str, module: str, duration: int = 0, page: int = 1) Leaderboard [source]
Returns: A Leaderboard of the top 20 Users in the Module
- get_modules(dojo: str) List[str] [source]
Requests a list of available modules in a dojo
- Parameters:
dojo – The dojo to fetch modules from
Returns: A list of modules
- get_user(user_id: int) User [source]
- Parameters:
user_id – The platform ID of the User to fetch
Returns: The requested User