圆月山庄资源网 Design By www.vgjia.com

复制代码 代码如下:
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()

标签:
时间,标准格式

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com