Demo entry 6632682

py

   

Submitted by anonymous on Jul 28, 2017 at 04:08
Language: Python. Code size: 2.5 kB.

#!/usr/bin/env python
import sys 
import time
import logging
import re

import binascii
import base64

baidu_base64_alphabet = "0KajD7AZcF2QnPr5fwiHRNygmupUTIXx69BWb-hMCGJo_V8Eskz1YdvL34letqSO"
standard_base64_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

def decode_k(k_str):
    related_dict = {}
    for i in range(len(baidu_base64_alphabet)):
        related_dict[baidu_base64_alphabet[i]] = standard_base64_alphabet[i]
    map_str = []
    for c in k_str:
        map_str.append(related_dict[c])
    for i in range(4 - len(k_str) % 4): 
        map_str.append('=')
    try:
        decoded_str = base64.b64decode(''.join(map_str))
    except:
        return None
    return ','.join(decoded_str.split('\0'))

def contains(s1,s2):
    for e1 in s1: 
        for e2 in s2: 
            if e1==e2:
                return True
    return False


KV_COL = 47

START = time.mktime((2015,9,23,0,0,0,0,0,0))
END = time.mktime((2015,9,23,23,59,59,0,0,0))

dev_all={} # dev count dist
dev_sdk={}
dev_api={}

for line in sys.stdin:
    line = line.strip()
    column = line.split('\t')
    if len(column)<KV_COL :
        continue

    kv = column[KV_COL - 1]
    kv_data=kv.split(',')
    decoded_k_str = decode_k(column[29])

    if decoded_k_str is None:
        continue

    decoded_k_str = decoded_k_str.replace('\n','')
    # print len(decoded_k_str.split(','))

    dev_tps=re.findall(r'dev_tp=(.+?),',decoded_k_str)
    accts=re.findall(r'acct=(.+?),',decoded_k_str)

    if len(dev_tps)<1:
        continue
    if len(accts)<1:
        continue

    dev_tp=dev_tps[0]
    acct=accts[0]

    if dev_tp=='-':
        continue

    if dev_tp not in dev_all:
        dev_all[dev_tp]=1
    else:
        dev_all[dev_tp]+=1

    if not ("accessid=7" in line and acct=='sdk') and not ("accessid=7" in line and acct=='api'):
        pass
    else:
        if "accessid=7" in line and acct=='sdk':
            if dev_tp not in dev_sdk:
                dev_sdk[dev_tp]=1
            else:
                dev_sdk[dev_tp]+=1
        elif  "accessid=7" in line and acct=='api':
            if dev_tp not in dev_api:
                dev_api[dev_tp]=1
            else:
                dev_api[dev_tp]+=1
        else:
            pass

for key in dev_all:
    print key+'\t'+str(dev_all[key])+','+str(dev_sdk.get(key,0))+','+str(dev_api.get(key,0))

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).