<commit_before>import boto.ec2
import argparse

def get_ec2_instances(region, instance_name):
    ec2_conn = boto.ec2.connect_to_region(region)
    instances = ec2_conn.get_only_instances(filters={"instance-state-name":"running", "tag:Name":instance_name})

    dns = []
    for i in instances:
        priv_name = str(i.private_dns_name).split(".")[0]
        pub_name = str(i.public_dns_name)
        dns.append((priv_name, pub_name))

    dns.sort()
    
    return dns

def write_dns(dns_tup):
    f_priv = open('private_dns','w')
    f_pub = open('public_dns','w')

    for pair in dns_tup:
        print(pair)
        f_priv.write(pair[0] + "\n")
        f_pub.write(pair[1] + "\n")

    f_priv.close()
    f_pub.close()

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('region', help='Region')
    parser.add_argument('instance_name', help='InstanceName')
    args = parser.parse_args()

    dns_tup = get_ec2_instances(args.region, args.instance_name)
    write_dns(dns_tup)<commit_msg>added  histogram of instance types when fetching all instances from a region<commit_after>import boto.ec2
import argparse
import json

def get_ec2_instances(region, instance_name):
    ec2_conn = boto.ec2.connect_to_region(region)
    instances = ec2_conn.get_only_instances(filters={"instance-state-name":"running", "tag:Name":instance_name})

    dns = []
    instance_type = {}
    for i in instances:
        priv_name = str(i.private_dns_name).split(".")[0]
        pub_name = str(i.public_dns_name)
        dns.append((priv_name, pub_name))

        if i.instance_type in instance_type:
            instance_type[i.instance_type] += 1
        else:
            instance_type[i.instance_type] = 1

    dns.sort()

    print json.dumps(instance_type, indent=2, sort_keys=True)

    return dns

def write_dns(dns_tup):
    f_priv = open('private_dns','w')
    f_pub = open('public_dns','w')

    for pair in dns_tup:
        print(pair)
        f_priv.write(pair[0] + "\n")
        f_pub.write(pair[1] + "\n")

    f_priv.close()
    f_pub.close()

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('region', help='Region')
    parser.add_argument('instance_name', help='InstanceName')
    args = parser.parse_args()

    dns_tup = get_ec2_instances(args.region, args.instance_name)
    write_dns(dns_tup)
{'fraction_non_alphanumeric': 0.13171140939597314, 'fraction_numerical': 0.008808724832214765, 'mean_word_length': 3.4915254237288136, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4589588', 'n_tokens_mistral': 875, 'n_tokens_neox': 860, 'n_words': 142}