Client

Client is the bread and butter of the Shawk framework. You’ll use this to connect to a Gmail account in both SMTP and IMAP protocols.

Typically the workflow will resemble creating a Client, adding contacts, configuring an inbox for IMAP, and listening for messages.

shawk.Client

Define the Client interface in Shawk.

class shawk.Client.Client(user, pwd, inbox=True, auto=True)[source]

Bases: object

Define the main Shawk interface.

add_contact(number, carrier, name=None)[source]

Create a new Contact instance and add to contacts.

You can also pass a list of numbers, carriers, and names to create multiple at once.

auto_refresh()[source]

Refresh the inbox automatically on an interval.

disable_auto_refresh()[source]

Disable auto refresh of inbox.

enable_auto_refresh(start=True)[source]

Enable auto refresh of inbox.

Will also begin refreshing now, but can be disabled with start=False.

export_contacts(path)[source]

Export the current contacts to a Shawk CSV file.

get_contact(message)[source]

Return the Contact from a given message’s sender.

Returns None if sender not in contacts.

get_contact_from_address(address)[source]

Return the Contact matching a given address.

Returns None if not in contacts.

get_refresh_interval()[source]

Return the refresh interval for auto refresh.

import_contacts(path)[source]

Import contacts from a Shawk CSV file.

print_contacts()[source]

Print the contacts

refresh()[source]

Refresh the inbox only once.

remove_contact(contact=None, number=None, name=None)[source]

Remove a contact from contacts.

send(message, contact=None, address=None, number=None, name=None, carrier=None)[source]

Send a message.

Can determine a contact to use via a number of different specifications, but it is advised to specify a Contact object if possible.

However, passing a specific address takes precedence over any other input.

set_refresh_interval(time)[source]

Define the refresh interval for auto refresh.

setup_inbox(password, user=None, folder='INBOX', refresh=False, auto=False, ssl=True)[source]

Configure an IMAP connection for receiving SMS.

Optionally configure behaviours such as auto-refresh, refresh immediately once configured, or specify a folder.

Folder specifications are useful if you configure your Gmail account to filter messages from certain senders to be moved to a specific folder, that way they don’t clutter your Gmail Inbox folder.

text_handler(pattern=None, modifiers='')[source]

Define a decorator that accepts a regular expression in string form for handlers.

Sets the default text handler if no string is provided.