zoukankan      html  css  js  c++  java
  • Python读取SSR服务器的mudb.json配置文件的流量使用情况

    附代码

    #! /usr/bin/env python
    # -*- coding: utf-8 -*-
    import sys
    import json
    f = file("/usr/local/shadowsocksr/mudb.json");
    json1 = json.load(f);
    f.close();
    
    result = {}
    result['field'] = ['port', 'd', 'u']
    result['data'] = []
    for x in json1:
            row=[]
            row.append(x[u"port"])
            row.append(x[u"d"])
            row.append(x[u"u"])
            #json2[x[u"port"]]=row;
            result['data'].append(row);
    
    print ''
    sys.stdout.write(json.dumps(result))

     改良下

    #! /usr/bin/env python
    # -*- coding: utf-8 -*-
    import sys
    import json
    f = file("/usr/local/shadowsocksr/mudb.json");
    json1 = json.load(f);
    f.close();
    
    result = {}
    result['field'] = ['port', 'd', 'u']
    result['data'] = []
    for x in json1:
            if(int(x[u"d"])==0 and int(x[u"u"])==0):
                    continue
            row=[]
            row.append(x[u"port"])
            row.append(x[u"d"])
            row.append(x[u"u"])
            result['data'].append(row);
    
    print ''
    sys.stdout.write(json.dumps(result))

    最后一个

    文件名

     1 #!/usr/bin/env python
     2 # -*- coding: utf-8 -*-
     3 import sys
     4 import json
     5 f = file("/usr/local/shadowsocksr/mudb.json");
     6 json1 = json.load(f);
     7 f.close();
     8 
     9 result = {}
    10 result['field'] = ['port', 'd', 'u']
    11 result['data'] = []
    12 for x in json1:
    13         if(int(x[u"d"])==0 and int(x[u"u"])==0):
    14                 continue
    15         row=[]
    16         row.append(x[u"port"])
    17         row.append(x[u"d"])
    18         row.append(x[u"u"])
    19         result['data'].append(row)
    20 
    21 sys.stdout.write("
    ")
    22 sys.stdout.write(json.dumps(result))
     1 #!/usr/bin/env python
     2 # -*- coding: utf-8 -*-
     3 import sys
     4 import json
     5 f = file("/usr/local/shadowsocksr/mudb.json");
     6 json1 = json.load(f);
     7 f.close();
     8 
     9 result = {}
    10 result['field'] = ['port', 'd', 'u']
    11 result['data'] = []
    12 for x in json1:
    13         if(int(x[u"d"])==0 and int(x[u"u"])==0):
    14                 continue
    15         row=[]
    16         row.append(x[u"port"])
    17         row.append(x[u"d"])
    18         row.append(x[u"u"])
    19         result['data'].append(row)
    20 
    21 sys.stdout.write("
    ")
    22 sys.stdout.write(json.dumps(result))
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import sys
    import json
    f = file("/usr/local/shadowsocksr/mudb.json");
    json1 = json.load(f);
    f.close();
    
    result = {}
    result['field'] = ['port', 'd', 'u']
    result['data'] = []
    for x in json1:
            if(int(x[u"d"])==0 and int(x[u"u"])==0):
                    continue
            row=[]
            row.append(x[u"port"])
            row.append(x[u"d"])
            row.append(x[u"u"])
            result['data'].append(row)
    
    sys.stdout.write("
    ")
    sys.stdout.write(json.dumps(result))
  • 相关阅读:
    最短路一类问题总结
    [Luogu] UVA1205 Color a Tree
    [Luogu] UVA1193 Radar Installation
    [Luogu] P2859 [USACO06FEB]Stall Reservations S
    [Luogu] P1248 加工生产调度
    [Luogu] P3694 邦邦的大合唱站队
    [Luogu] CF229D Towers
    windows server清理文件
    python连接ES进行数据过滤删除,新增查询、创建索引功能
    ES以更新时间为标准,分离数据
  • 原文地址:https://www.cnblogs.com/xiangxisheng/p/8027200.html
Copyright © 2011-2022 走看看