# Path: locksmith/common.py
# def apicall(url, signkey, **params):
#     params['signature'] = get_signature(params, signkey)
#     data = sorted([(k,v) for k,v in params.iteritems()])
#     body = urllib.urlencode(data)
#     urllib2.urlopen(url, body)


import re, os, datetime, gzip
from locksmith.common import apicall
        if log_file.endswith('.gz'):
            file = gzip.open(os.path.join(log_directory, log_file), 'rb')
        else:
            file = open(os.path.join(log_directory, log_file), 'r')
        
        # loop over the rows
        for row in file:
            match = log_re.match(row)
            if match:
                record = match.groupdict()
                day = datetime.datetime.strptime(record['date'], log_date_format).date()
                if day == log_date and record['status'] == '200' and record['apikey'] and record['apikey'] != '-':
                    # normalize the endpoint
                    endpoint = log_custom_transform(record['endpoint']) if log_custom_transform else record['endpoint']
                    
                    # add it to the tally
                    if record['apikey'] not in totals:
                        totals[record['apikey']] = {}
                    
                    if endpoint not in totals[record['apikey']]:
                        totals[record['apikey']][endpoint] = 1
                    else:
                        totals[record['apikey']][endpoint] += 1
                elif day < log_date:
                    # this is the last log we need to parse
                    last_loop = True
        if last_loop:
            break
    
    # submit totals to hub

# Path: locksmith/common.py
# def apicall(url, signkey, **params):
#     params['signature'] = get_signature(params, signkey)
#     data = sorted([(k,v) for k,v in params.iteritems()])
#     body = urllib.urlencode(data)
#     urllib2.urlopen(url, body)


# Path: locksmith/logparse/report.py
import re, os, datetime, gzip
from locksmith.common import apicall

        if log_file.endswith('.gz'):
            file = gzip.open(os.path.join(log_directory, log_file), 'rb')
        else:
            file = open(os.path.join(log_directory, log_file), 'r')
        
        # loop over the rows
        for row in file:
            match = log_re.match(row)
            if match:
                record = match.groupdict()
                day = datetime.datetime.strptime(record['date'], log_date_format).date()
                if day == log_date and record['status'] == '200' and record['apikey'] and record['apikey'] != '-':
                    # normalize the endpoint
                    endpoint = log_custom_transform(record['endpoint']) if log_custom_transform else record['endpoint']
                    
                    # add it to the tally
                    if record['apikey'] not in totals:
                        totals[record['apikey']] = {}
                    
                    if endpoint not in totals[record['apikey']]:
                        totals[record['apikey']][endpoint] = 1
                    else:
                        totals[record['apikey']][endpoint] += 1
                elif day < log_date:
                    # this is the last log we need to parse
                    last_loop = True
        if last_loop:
            break
    
    # submit totals to hub

    submit_date = log_date.strftime('%Y-%m-%d')