Chinaunix首页 | 论坛 | 博客
  • 博客访问: 28864
  • 博文数量: 6
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 60
  • 用 户 组: 普通用户
  • 注册时间: 2017-11-02 19:46
个人简介

刚开始接触linux运维开发,希望有个自己的博客,能够记录自己生活学习的点点滴滴,能够记录自己的成长,学过的东西,学过的技术,说忘就忘。同时希望以后入行后有个地方能够分享自己的工作经验,这大概就是我的申请理由,希望这个博客能够实现为这个小小的运维人员的需求,谢谢

我的朋友
最近访客

分类: Python/Ruby

2017-12-18 23:10:43


击()折叠或打开

  1. #!/usr/bin/env python
  2. import xlwt,xlrd,datetime,json,os,xlutils.copy
  3. a={
  4.     'VpcPeeringConnection': {
  5.         'AccepterVpcInfo': {
  6.             'CidrBlock': 'abc',
  7.             'Ipv6CidrBlockSet': [
  8.                 {
  9.                     'Ipv6CidrBlock': 'qwe'
  10.                 },
  11.             ],
  12.             'CidrBlockSet': [
  13.                 {
  14.                     'CidrBlock': 'qwrqrqrwrqr'
  15.                 },
  16.             ],
  17.             'OwnerId': '123asf',
  18.             'PeeringOptions': {
  19.                 'AllowDnsResolutionFromRemoteVpc': True,
  20.                 'AllowEgressFromLocalClassicLinkToRemoteVpc': True,
  21.                 'AllowEgressFromLocalVpcToRemoteClassicLink': True
  22.             },
  23.             'VpcId': 'asdfghjk',
  24.             'Region': ';lkjhg'
  25.         },
  26.         'ExpirationTime': "aaaa",
  27.         'RequesterVpcInfo': {
  28.             'CidrBlock': '12qwesd',
  29.             'Ipv6CidrBlockSet': [
  30.                 {
  31.                     'Ipv6CidrBlock': 'mjhngb'
  32.                 },
  33.             ],
  34.             'CidrBlockSet': [
  35.                 {
  36.                     'CidrBlock': 'oikujhg'
  37.                 },
  38.             ],
  39.             'OwnerId': 'lkjh',
  40.             'PeeringOptions': {
  41.                 'AllowDnsResolutionFromRemoteVpc': True,
  42.                 'AllowEgressFromLocalClassicLinkToRemoteVpc': True,
  43.                 'AllowEgressFromLocalVpcToRemoteClassicLink': True
  44.             },
  45.             'VpcId': 'waqsd',
  46.             'Region': 'awsd'
  47.         },
  48.         'Status': {
  49.             'Code': "'initiating-request'",
  50.             'Message': 'lk_mjhn'
  51.         },
  52.         'Tags': [
  53.             {
  54.                 'Key': 'mhngbv',
  55.                 'Value': 'gfd'
  56.             },
  57.         ],
  58.         'VpcPeeringConnectionId': 'ytgrf'
  59.     }
  60. }
  61. #os.remove('./bcd111.xls')
  62. def write_excel(filename,dic):
  63.     sh = xlwt.Workbook()
  64.     sheet1 = sh.add_sheet('table123')
  65.     sheet1.write(0,0,"CidrBlock")
  66.     sheet1.write(0,1,"Ipv6CidrBlock")
  67.     sheet1.write(0,2,'OwnerId')
  68.     sheet1.write(0, 3, 'VpcId')
  69.     
  70.     dic_key = dic.keys()
  71.     temp =1
  72.     for key_names in dic_key:
  73.         key_name = a[key_names].keys()
  74.         for names in key_name:
  75.             if isinstance(a[key_names][names],dict):
  76.                 if 'CidrBlock' in dic[key_names][names].keys() or 'Ipv6CidrBlock' in dic[key_names][names].keys() or 'OwnerId' in dic[key_names][names].keys() or 'VpcId' in dic[key_names][names].keys() :
  77.                     sheet1.write(temp,0,dic[key_names][names].get('CidrBlock',''))
  78.                     sheet1.write(temp, 1, dic[key_names][names].get('Ipv6CidrBlock',''))
  79.                     sheet1.write(temp, 2, str(dic[key_names][names].get('OwnerId', '')))
  80.                     sheet1.write(temp, 3, dic[key_names][names].get('VpcId', ''))
  81.                     temp = temp+1
  82.     sh.save(filename)

  83. write_excel('bcd111.xls',a)


阅读(1239) | 评论(0) | 转发(0) |
0

上一篇:shell基础一

下一篇:没有了

给主人留下些什么吧!~~