Ejemplo n.º 1
0
 def login(self, username, password):
     pattern = re.compile(r'^0\d{2,3}\d{7,8}$|^1[34578]\d{9}$')
     if (pattern.match(username)):
         return self.phone_login(username, password)
     clientToken = get_token()
     print clientToken
     action = 'http://music.163.com/weapi/login'
     text = {
         'username': username,
         'password': password,
         'rememberLogin': '******',
         'clientToken': clientToken
     }
     data = encrypted_request(text)
     print data
     try:
         return self.httpRequest('Login_POST', action, data)
     except:
         return {'code': 501}
Ejemplo n.º 2
0
    #
    # If you use a modern, high-level designed HTTP client lib, Yeah, I mean requests, 
    # there is no this problem. 
    #
    except HTTPError, e:
        resp = e.read()
        status_code = e.code
    except URLError, e:
        resp = e.read()
        status_code = e.code
    else:
        status_code = r.code
        resp = r.read()
    return resp


if __name__ == '__main__':
    user_name = '******'
    password = '******'
    account_name = '******'
    demo_data_url = 'https://ais-sample-data.obs.myhwclouds.com/barcode.jpg'
    token = get_token(user_name, password, account_name)

    # call interface use the url
    result = ocr_barcode(token, '', demo_data_url)
    print result

    # call interface use the data
    result = ocr_barcode(token,  encode_to_base64('data/barcode.jpg'))
    print result
Ejemplo n.º 3
0
def url_image_tagging(token, url):
    image = download_url_base64(url)
    if len(image) == 0:
        print "%s\t%s" % (url, "ERRORdownload")
        return

    resp = image_tagging(token, image)
    print "%s\t%s" % (url, resp)


if __name__ == "__main__":
    user_name = "XXX"
    password = "******"
    account_name = "XXX"

    url_file = sys.argv[1]

    # token expire in 24hour
    token = get_token(user_name, password, account_name)
    if len(token) == 0:
        print "Error username password"
        sys.exit(-1)

    # test urls in file
    for line in open(url_file):
        url = line.strip()
        url_image_tagging(token, url)

    ## test a sigle url
    #url_image_tagging(token, 'http://www.example.com/example.jpg')
Ejemplo n.º 4
0
def send_message(post_json):
    # 发送模版消息接口
    url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s' % gettoken.get_token(
    )
    print url
    req = urllib2.Request(url, post_json)
    response = urllib2.urlopen(req)
    res = response.read()
    response.close()
    return res
Ejemplo n.º 5
0
Archivo: menu.py Proyecto: jsqwe5656/wx
 def __init__(self):
     self.accessToken = gettoken.get_token()
     print self.accessToken
Ejemplo n.º 6
0
from cutimage import cuti
import requests
import base64
import urllib.parse
from gettoken import get_token

token = get_token()
header = {'Content-Type': 'application/x-www-form-urlencoded'}
host = 'https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic'
params = {'access_token': token}
cuti()


def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()


image = get_file_content('test.png')


def basicGeneral(image):
    data = {}
    data['image'] = base64.b64encode(image).decode()
    return data


data = basicGeneral(image)


def run():
Ejemplo n.º 7
0
# @Author  : Zhangyp
# @File    : IMCIS_无效.py
# @Software: PyCharm
# @license : Copyright(C), eWord Technology Co., Ltd.
# @Contact : [email protected]
from locust import TaskSet, task
from locust import HttpLocust
from gettoken import get_token
from readini import s
import logging

# 请求头信息的数据类型设置为x-www-form-urlencoded
h1 = {'Content-Type': 'application/x-www-form-urlencoded'}

# 获取token的头信息
h2 = {'Authorization': get_token()}


class IMCISTask(TaskSet):
    def on_start(self):  #初始化函数每次执行任务前只执行一次
        print('test start...')

    # 获取token
    @task(int(s['token_w']))
    def gettoken(self):
        api = 'token_api'
        title = api.split('_')[0]
        payload = s['token_body']
        # payload = 'input={"organizationID":"12330122MB1856687C","account":"zyp","password":"******","rememberMe":false}'
        logging.info('test %s: %s' % (api, s[api]))
        try:
Ejemplo n.º 8
0
async def startup(uri, f):
    async with AioWebSocket(uri) as aws:
        converse = aws.manipulator
        n = 0
        while True:
            mes = await converse.receive()
            mes = mes.decode()
            # print(mes)
            f.write(mes + '\n')
            mes_json = json.loads(mes)
            manage_danmu(mes_json)
            n += 1
            if n == 3:
                mid = mes_json['msgId']
                await converse.send(
                    '{"body":{"msgId":"%s"},"op":6,"sid":0,"seq":0} 	' % mid)
                n = 0
            else:
                await converse.send('{"body":"{}","op":2,"sid":0,"seq":0}	')


if __name__ == '__main__':
    url = 'http://star.longzhu.com/sk2?from=filivehot5'
    appid, roomid, token = get_token(url)
    remote = f'ws://ws52.longzhu.com:8805/?appId={appid}&roomId={roomid}&msgVersion=1.0&token={token}'
    with open('data.txt', 'w', encoding='utf-8') as f:
        try:
            asyncio.get_event_loop().run_until_complete(startup(remote, f))
        except KeyboardInterrupt as exc:
            print(exc)