An API for maintaining LSoft lists using the twill package
lsoft_api.py provides basic add/delete/list functions for maintaining LSoft LISTSERV lists using twill to "login in" and use LSoft's web interface.
Add/delete operations are slow. In theory it should be able to do as many as you want, but for large numbers of additions or deletes it may be better to do bulk updates through the web site interactively.
The "public" functions:
addLSoftMember(list, addr, cred)
delLsoftMember(list, addr, cred)
getLSoftMembers(list, cred)
The cred property is a dict containing 'serv' (server URL, e.g. https://lists.purdue.edu), 'acct' (email address of list owner), and 'pass' (clear-text login password for acct)
The functions return the tuple (status, data) where status is OK
or FAIL
, data is either a list of member addresses (getLSoftMembers) or the text result of the add/delete operation.
The "hidden" functions and resources:
- lsoft_urlfmt
- dict of URL templates for "get", "add", and "del" functions
- LSOFTHTMLParser
- subclass of HTMLParser to parse web response to actions
- DevNull()
- provides devnull for twill operations
- lsoft_login(cred)
- logs in to LSoft with the account provided in cred, gets authentication token (stored temporarily in cred) used in future web requests
- lsoft_transact(cred, op, list, member)
- performs op[eration] (get, add, or del) on list and optional member (for add/del), handles response, updates authentication token, and returns text response to caller
The example code contains an example of using configparser to fetch credentials from a configuration file so the script can be shared by multiple users, each with their own private credential file. The code is not dependent on the method of storing and retrieving the password, just that it exist in clear text in the credential structure.
Caution
The password, though protected with file permissions, is still in clear text in a file. It is recommended that you use a non-person service account that is only used for LSoft list manipulation.