Chinaunix首页 | 论坛 | 博客
  • 博客访问: 181768
  • 博文数量: 18
  • 博客积分: 334
  • 博客等级: 入伍新兵
  • 技术积分: 233
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-20 14:45
文章分类

全部博文(18)

文章存档

2015年(5)

2013年(7)

2012年(6)

我的朋友

分类: Python/Ruby

2013-03-28 09:32:23


点击(此处)折叠或打开

  1. import json
  2. import os
  3. import time
  4. import datetime
  5. import sys

  6. #c处理ascii码异常情况
  7. reload(sys)
  8. sys.setdefaultencoding( "utf-8" )

  9. target_dir = '/logs/out/dana/target'
  10. report_dir = '/logs/out/dana/report'

  11. now_time = datetime.datetime.now()
  12. last_time = now_time + datetime.timedelta(days=-1)
  13. last_time_nyr = last_time.strftime('%Y%m%d')
  14. #获取外部输入值
  15. time_argv1 = sys.argv[1]
  16. time_argv2 = sys.argv[2]

  17. json_client = target_dir + '/' + time_argv1 + '/' + time_argv2 + '/' + 'json_client.txt'
  18. json_client_results = target_dir + '/' + time_argv1 + '/' + time_argv2 + '/' + 'json_client_results.txt'

  19. a = open(json_client)
  20. b = a.readlines()
  21. c = open(json_client_results,"a")
  22. #get() 为如果为空的话转为空输出;str()强制转换成字符串型
  23. for line in b:
  24.     m = json.loads(line)
  25.     CP_CH = str(m.get('CP_CH',''))                                                
  26.     CP_CITYID = str(m.get('CP_CITYID',''))                                    
  27.     CP_IMEI = str(m.get('CP_IMEI',''))                                            
  28.     CP_MODEL = str(m.get('CP_MODEL',''))                                
  29.     CP_PLTFM = str(m.get('CP_PLTFM',''))                            
  30.     CP_PRT = str(m.get('CP_PRT',''))                            
  31.     CP_RATIO = str(m.get('CP_RATIO',''))                                
  32.     CP_TOUCH = str(m.get('CP_TOUCH',''))                                        
  33.     CP_UID = str(m.get('CP_UID',''))                                        
  34.     CP_VER = str(m.get('CP_VER',''))                                    
  35.     CP_PHONENUM = str(m.get('CP_PHONENUM',''))                                
  36.     CP_TPL = str(m.get('CP_TPL',''))                                            
  37.     CP_RESVER = str(m.get('CP_RESVER',''))                                    
  38.     CP_PUBRESPATH = str(m.get('CP_PUBRESPATH',''))                                
  39.     CP_LON = str(m.get('CP_LON',''))                                        
  40.     CP_LAT = str(m.get('CP_LAT',''))                                    
  41.     CP_ACTIONS = m["actions"][0]["action"]                                    

  42.     #print CP_CITYID + "|" + CP_IMEI
  43.     #print CP_IMEI
  44.     e = CP_CH + "|" + CP_CITYID + "|" + CP_IMEI + "|" + CP_MODEL + "|" + CP_PLTFM + "|" + CP_PRT + "|" + CP_RATIO + "|" + CP_TOUCH + "|" + CP_UID + "|" + CP_VER + "|" + CP_PHONENUM + "|" + CP_TPL + "|" + CP_RESVER + "|" + CP_PUBRESPATH + "|" + CP_LON + "|" + CP_LAT + "|" + CP_ACTIONS + "\n"
  45.     #e = CP_CITYID + "|" + CP_IMEI + "|" + CP_UID + "|" + "|" + CP_LAT + "|" + "\n"
  46.     #print e.encode("UTF-8")

  47.     c.write(e.encode("UTF-8"))

  48. c.close()
  49. a.close()

阅读(2258) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~