'''

data_file_name = 'njprod-beacon-201_beacon.log.2014-04-06'
# data_file_name = 'small.txt'
output_file_name = 'us_ca_sf_data.csv'


data_file = os.path.join (path, data_file_name)
output_file = os.path.join (path, output_file_name)


# country: 29
# state: 30  US_CA
# entry point: 38
output_data = []

with open (data_file) as f:
    for line in f:
        line = line.strip ()
        attr_list = line.split (',')
        print len (attr_list)
        if (len(attr_list) == 60 
            and attr_list[30] == 'US_CA'
            and attr_list[31] == 'San Francisco'):
       		 # and attr_list[38] == '2'):
            output_data.append(attr_list)

 
write_csv (output_file, output_data)
print len (output_data)
Example #2
0
			print "invalid ip address"
			data.remove (record)
	return ip_map


data_file_name = 'us_ca_sf_data.csv'
data_file = os.path.join (path, data_file_name)
data = csv_reader (data_file)

ip_map = get_ip_map (data)
geo_list = []
geo_list.append (['Lat', 'Long', 'Name'])

cnt = 0
for ip in ip_map.keys():
	if (cnt > 10):
		break
	ip_json = get_geodata(ip)
	print ip_json
	curr_geo = []
	curr_geo.append (ip_json['latitude'])
	curr_geo.append (ip_json['longitude'])
	curr_geo.append ('; '.join (ip_map[ip]))
	geo_list.append (curr_geo)
	cnt += 1

print geo_list
write_csv ('../data/sf_geo_records.csv', geo_list)