Searching for open bugs in a launchpad project

The launchpad API docs are OMG terrible, and it took me way too long to work out how to do this, so I thought I’d document it for later. Here’s how you list all the open bugs in a launchpad project using the API:

    import argparse
    import os
    from launchpadlib import launchpad
    LP_INSTANCE = 'production'
    CACHE_DIR = os.path.expanduser('~/.launchpadlib/cache/')
    def main(username, project):
        lp = launchpad.Launchpad.login_with(username, LP_INSTANCE, CACHE_DIR)
        for bug in lp.projects[project].searchTasks(status=["New",
                                                            "In Progress"]):
            print bug
    if __name__ == '__main__':
        parser = argparse.ArgumentParser(description='Fetch bugs from launchpad')
        args = parser.parse_args()
        main(args.username, args.project)