import os
import sys
import pickle
import string
import re
import time
from datetime import date
from csv_timestamp_datetime import *
ip_region_list = pickle.load(open('ip_region_list.pickle','r'))
ip_region_list.sort(key=lambda x: x[0])
list_len = len(ip_region_list)
def find(key):
begin = 0
end = list_len - 1
while(begin <= end):
middle = (begin + end) / 2
if ip_region_list[middle][0] <= key and ip_region_list[middle][1] >= key:
return ip_region_list[middle][2]
else:
if ip_region_list[middle][0] >= key:
end = middle - 1
else:
begin = middle + 1
def ip2region():
of = open(sys.argv[1], 'r')
nf = open(sys.argv[2], 'w')
for line in of:
items = line.strip().split(',')
try:
x = time.localtime(long(items[0]))
ymdhms = time.strftime('%Y-%m-%d %H:%M:%S',x)
nf.write(','.join( [ ymdhms , items[1] , long2ip(long(items[2])) ]) + '\n')
except Exception as e:
print e
print line
if (__name__ == '__main__'):
ip2region()
python 时间整形转标准格式
原创mb646331aa41439 博主文章分类:python ©著作权
©著作权归作者所有:来自51CTO博客作者mb646331aa41439的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章