#!/usr/bin/env python

"""
Step 2
======
In this step, we'll add the histories module to list our histories
and get details on our most recently used history.
"""
import os
import sys
import pprint

import users_1
import histories_2

# ----------------------------------------------------------------------------- main
if __name__ == '__main__':
    try:
        users = users_1.get_users()
        histories = histories_2.get_histories()
        # since what's returned from our resource scripts are python dictionaries or lists,
        #   we can access parts of the dictionary to get datum/data-points about our history (or any other resource)

        # here, we'll get the first history using the list access syntax
        # (galaxy returns lists of histories ordered by the time they were most recently used/updated)
        current_history_summary = histories[0]
        # then, we'll get the id of that history using the dictionary access syntax
        current_history_id = current_history_summary[ 'id' ]

        # with that id, we can use the get_history function we made in histories_2
        current_history_details = histories_2.get_history( current_history_id )
        
    except Exception, exc:
        print 'Error getting history information:', str( exc )
        sys.exit( 1 )

    print 'current history:'
    pprint.pprint( current_history_details, indent=2 )
