xiguaqq20 发表于 2017-5-5 06:24:25

python 时间整形转标准格式

  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)
  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 <= key and ip_region_list >= key:
  return ip_region_list
  else:
  if ip_region_list >= key:
  end = middle - 1
  else:
  begin = middle + 1
  def ip2region():
  of = open(sys.argv, 'r')
  nf = open(sys.argv, 'w')
  for line in of:
  items = line.strip().split(',')
  try:
  x = time.localtime(long(items))
  ymdhms = time.strftime('%Y-%m-%d %H:%M:%S',x)
  nf.write(','.join( [ ymdhms , items  , long2ip(long(items))  ]) + '\n')
  except Exception as e:
  print e
  print line
  if (__name__ == '__main__'):
  ip2region()
页: [1]
查看完整版本: python 时间整形转标准格式