Skip to content

oldas.session

Provides a class for getting and managing a login session.

Session

Session(
    client: str,
    auth_code: str | None = None,
    timeout: int = 60,
    logger: Logger | None = None,
)

Class for handling a TheOldReader login session.

Parameters:

Name Type Description Default

client

str

The name of the client that is logging in.

required

auth_code

str | None

Optional authorisation code to resume a session.

None

timeout

int

The timeout in seconds to use when making calls.

60

logger

Logger | None

Optional logging object.

None
Note

The client should be a unique name you give your client application that is using this library.

auth_code property

auth_code: str | None

The auth code, if we are logged in, else None.

logged_in property

logged_in: bool

Are we logged in?

add_tag async

add_tag(item: str | list[str], tag: str | State) -> bool

Add a tag to an item.

Parameters:

Name Type Description Default

item

str | list[str]

The item(s) to perform the edit on.

required

tag

str | State

The tag to add.

required

Returns:

Type Description
bool

True if the add tag operation worked,

bool

False if not.

get async

get(endpoint: str, **params: Any) -> RawData

Make a GET call to the API.

Parameters:

Name Type Description Default

endpoint

str

The endpoint to call.

required

params

Any

Any extra parameters that need to be passed.

{}

Returns:

Type Description
RawData

A dictionary that is the JSON data.

Raises:

Type Description
OldASError

If there was an error connecting or logging in.

login async

login(user: str, password: str) -> Self

Log into TheOldReader.

Parameters:

Name Type Description Default

user

str

The user name to log in with.

required

password

str

The password to log in with.

required

Returns:

Type Description
Self

Self.

Raises:

Type Description
OldASError

If there was an error connecting or logging in.

logout

logout() -> Self

Log out of the TheOldReader.

Returns:

Type Description
Self

Self.

post async

post(url: str, **data: Any) -> RawData

Make a POST call to the API.

Parameters:

Name Type Description Default

url

str

The URL to call.

required

data

Any

The data to pass.

{}

Returns:

Type Description
RawData

The response from the call to the API.

Raises:

Type Description
OldASError

If there was an error connecting or logging in.

post_ok async

post_ok(url: str, **data: Any) -> bool

Make a POST call to the API.

Parameters:

Name Type Description Default

url

str

The URL to call.

required

data

Any

The data to pass.

{}

Returns:

Type Description
bool

True if the call worked, False if not.

Raises:

Type Description
OldASError

If there was an error connecting or logging in.

remove_tag async

remove_tag(item: str | list[str], tag: str | State) -> bool

Remove a tag from an item.

Parameters:

Name Type Description Default

item

str | list[str]

The item(s) to perform the edit on.

required

tag

str | State

The tag to remove.

required

Returns:

Type Description
bool

True if the remove tag operation worked,

bool

False if not.