#!/usr/bin/env python # Corey Goldberg (corey@goldb.org) # Coradiant TrueSight - Bulk Data Export import httplib import time import zipfile host_name = 'HOST NAME OR IP GOES HERE' user_name = 'USER NAME GOES HERE' password = 'PASSWORD GOES HERE' mins = 10 # mins of data to export def main(): start_time, end_time = start_end_times(120) # start from 2 mins ago so coradiant has time to publish data path = '/getdata?usr=' + user_name + '&pwd=' + password + '&id=75&start=' + start_time + '&end=' + end_time + '&format=csv' zip_file_name = 'coradiant_data.zip' download_coradiant_data(path, 'coradiant_data.zip') unzip('coradiant_data.zip') def download_coradiant_data(path, zip_file_name): # make HTTPS connection and get document conn = httplib.HTTPSConnection(host_name) conn.request('GET', path) response = conn.getresponse() # write the message body to file as binary fh = open(zip_file_name, 'wb') fh.write(response.read()) fh.close() def start_end_times(offset_secs): start_time = time.strftime('%Y.%m.%d.%H.%M', time.localtime(time.time() - (mins * 60 + offset_secs))) end_time = time.strftime('%Y.%m.%d.%H.%M', time.localtime(time.time() - offset_secs)) return (start_time, end_time) def unzip(file_name): fh = open(file_name, 'rb') zfobj = zipfile.ZipFile(fh) zfobj = zipfile.ZipFile(fh) for name in zfobj.namelist(): outfile = open(name, 'wb') outfile.write(zfobj.read(name)) outfile.close() fh.close() if __name__ == "__main__": main()