Пример #1
0
def get_all_traffic(*rs):
	''' resp.app_id=lc.get_app_id(resp) '''
	import datetime
	now=datetime.datetime.now()+datetime.timedelta(seconds=120)
	params = (
		('start', (now-datetime.timedelta(days=1)).isoformat()+'+08'),
		('end'  , now.isoformat()+'+08'),
		('groupName', 'web'),
	)
	m=py.len(rs)
	# r=[[],] * m  # [[('sum', 0],#to...#), ..m..  ### [[,],] SyntaxError###
	r=[py.list() for n in py.range(m) ]  #  [[],] * m 初始化会造成 r[0],r[1]...都是同一个 list
	for n,rsignin in py.enumerate(rs):
		email=rsignin.json()['email']
		app_id=get_app_id(rsignin)
		headers_t = {'x-xsrf-token': rsignin.cookies['XSRF-TOKEN'],
			'x-lc-id': get_app_id(rsignin),
			}
		rt = requests.get('https://us-w1-console-api.leancloud.app/1.1/engine/stats/outbound-traffic', headers=headers_t, params=params,cookies=rsignin.cookies)
		for k,v in rt.json()[0]['dps'].items():
			s=U.stime(int(k))
			s=s.replace('.00__.000','')
			r[n].append( [s,F.IntSize(v)] )
		size_len=F.IntSize(py.sum(U.get_col(r[n],1)),size=13-1),py.len(r[n])
		r[n].insert(0,size_len)
		r[n].insert(0,'%-17s:%-17s'%(email,app_id ))
	return r
Пример #2
0
async def get_all_pages(browser=None):
    if not browser:
        browser = await get_browser()
    ps = await browser.pages()
    # r=[]
    for n, pa in py.enumerate(ps):
        t = await pa.title()
        print(fr'{n:>02d} {t[:33]:33} {pa.url[33:]:33} {py.repr(pa)[-11:] }')
    return ps
Пример #3
0
async def get_taobao_cookies(p=False):
    cks = await taobao_trade.get_all_cookies()
    dck = {}
    for n, c in py.enumerate(cks):
        if 'taobao.com' in c['domain'] and not U.one_in([
                'login.',
                'airunit.',
                'cart.',
        ], c['domain']):
            dck[c['name']] = c['value']
            if p: print(n, '%-15s' % c['name'], c['domain'])
    return dck
Пример #4
0
async def get_taobao_user(page=None):
    if page:
        return await page.evaluate(taobao_trade.js_get_user)
    ps = await browser.pages()
    # r=[]
    for n, pa in py.enumerate(ps):
        u = await try_evaluate(pa, taobao_trade.js_get_user)
        if u:
            t = await pa.title()
            print(n, (t + '\t' + pa.url)[:99])
            return u
    raise NotFound_taobao_user
Пример #5
0
 def get_lr(*a, topN=U.IMAX):
     r = []
     for n, i in py.enumerate(iter_max(*a)):
         if n > topN: break
         i = U.sort(i)
         if i in r: continue
         r.append(i)
     lr = []
     for i in r:
         sum = py.round(py.sum(i), round)
         s = '%s Unique:' % (len(i), )
         s = U.IntCustomRepr(len(i), str='Len:' + s.rjust(6 + 1 + 4))
         lr.append([s, len(U.unique(i)), sum, *i])
     return lr
Пример #6
0
def rty(rows=None, **ka):
    if not rows: rows = grows
    rt = ''

    dcol_range = {}
    for k in py.list(ka):
        for nc, c in py.enumerate(k):
            if c in T._09:
                i = py.int(c)
                v = ka.pop(k)
                if py.isnum(v):
                    dcol_range[i] = [v, U.IMAX]
                elif py.istr(v):
                    if k[nc - 1] == '_':
                        dcol_range[-i] = v
                    else:
                        dcol_range[i] = v
                elif py.len(v) == 2:
                    dcol_range[i] = v
                else:
                    raise py.ArgumentError(' col range must int or [a,b] ')
                break
    if dcol_range:
        print(' dcol_range:', dcol_range)
    for index, row in enumerate(U.sort(rows, **ka)):
        _continue = 0
        for ic, ran in dcol_range.items():
            # rt+=f'#  {row}[{ic}]<hr>'
            # _continue=0
            if ic >= 0 and py.istr(row[ic]) and py.istr(ran):
                if not ran in row[ic]:
                    _continue = 1
            if ic < 0 and py.istr(row[ic]) and py.istr(ran):
                if ran in row[ic]:
                    _continue = 1
            if py.isnum(row[ic]) and py.isnum(ran[0]):
                if not ran[0] <= row[ic] <= ran[1]:
                    _continue = 1
        if _continue: continue

        if 'item.taobao.com/item.htm?id=' in row[-3]:
            row[-3] = T.sub(row[-3], 'id=', '')
        tb = f'''{row[-1]}
<span>{row[:4]}</span>  <br>
<a target="_blank" href="taobao://item.taobao.com/item.htm?id={row[-3]}">{'%4s'%index}  {row[-2]} </a>
<br><hr>
'''
        rt += tb
    return rt
Пример #7
0
def iter_max_list(*a, round=2, c1=[]):
    def get_lr(*a, topN=U.IMAX):
        r = []
        for n, i in py.enumerate(iter_max(*a)):
            if n > topN: break
            i = U.sort(i)
            if i in r: continue
            r.append(i)
        lr = []
        for i in r:
            sum = py.round(py.sum(i), round)
            s = '%s Unique:' % (len(i), )
            s = U.IntCustomRepr(len(i), str='Len:' + s.rjust(6 + 1 + 4))
            lr.append([s, len(U.unique(i)), sum, *i])
        return lr

    nc = -1
    y, max, *_ = a
    r = get_lr(y, max)
    lr_list = []
    for nc, c in py.enumerate(c1):
        lr = get_lr(y, max - c, topN=99)
        lr = U.sort(lr, column=1)[:9]
        for i in lr:
            i[1] += c
            i[1] = py.round(i[1], round)
            i.append([c])

        # lr_list.append(lr)
        # r.insert(i,(nc+1)*(n+1)-1)
        r.extend(lr)
    else:
        if nc < 1: return r
    # for i in py.range(9):
    # for lr in lr_list:
    # if len(lr)<=i:break
    # r.append(lr[i])
    return U.sort(r, column=1)
Пример #8
0
def flap_traffic(r):
	m=py.len(r)
	rm=[]
	
	for i,_row in py.enumerate(r[0]):
		skip=False
		row=[  r[0][i][0]  ]
		for n in py.range(m):
			if i<2:
				row[0]=U.len(*r)
				if i==0:
					n=r[n][i]
				if i==1:
					n=py.repr(  r[n][i][0] )
			else:
				if r[n][i][0] != row[0]:
					print(n,i)
					NOT_Equal
				n=py.repr( r[n][i][1] )
				# n=U.StrRepr( T.justify(py.repr(n),size=19)  )
			row.append(n )
		row=[U.StrRepr( T.justify(j,size=18,cut=1) )	for j in row]
		rm.append(row)
	return rm