This example is described in detail in the following document: http://www.juniper.net/techpubs/en_US/release-independent/nce/information-products/topic-collections/nce/accounting-profiles-statistics-logging/accounting-profiles-statistics-logging.pdf
python accounting-profile-statistics-logging.py