예제 #1
0
def download_resource_file(on_request, resDir):
    global toneDir
    global on_callback
    global on_download
    global cb_data
    toneDir = resDir

    data = {
        'url': on_request['url'],
        'method': 'GET',
        'headers': {
            'Accept': '*/*'
        },
        'timeout': 30000,
        'params': ''
    }

    def cb(data):
        global on_callback
        global cb_data
        print(on_callback)
        on_callback = True
        cb_data = data

    http.request(data, cb)

    while True:
        if on_callback:
            break
        else:
            time.sleep(1)

    response = json.loads(cb_data)
    format = response['format']
    size = response['size']
    format = response['format']
    audio = response['audios'][0]
    id = audio['id']
    path = toneDir + id + '.' + format
    print('************ begin to download: ' + path)
    d_data = {'url': audio['url'], 'filepath': path}

    def d_cb(data):
        global on_download
        on_download = True

    http.download(d_data, d_cb)

    while True:
        if not on_download:
            break
        else:
            time.sleep(1)
    print('download succeed :' + path)
예제 #2
0
 def get_response_json(cls, _id, page, refer=None):
     url = cls.TEMPLATE.format(at=cls.ACCESS_TOKEN, _id=_id, count=cls.COUNT, page=page, )
     request = http.Request.from_default_browser(url, headers={"referer": refer})
     try:
         response = http.download(request)
     except Exception:
         return None
     else:
         return json.loads(response.body)
예제 #3
0
    def download_resource_file(self, on_request, resDir):
        global on_callback, on_download, cb_data
        data = {
            'url': on_request['url'],
            'method': 'GET',
            'headers': {},
            'timeout': 30000,
            'params': ''
        }

        def cb(data):
            global on_callback, cb_data
            on_callback = True
            cb_data = data

        http.request(data, cb)
        while True:
            if on_callback:
                on_callback = False
                break
            else:
                time.sleep(1)
        response = json.loads(cb_data['body'])
        audio = response['audios'][0]
        format = audio['format']
        id = audio['id']
        size = audio['size']
        path = self.toneDir + id + '.' + format
        print('************ begin to download: ' + path)
        d_data = {'url': audio['url'], 'filepath': path}

        def d_cb(data):
            global on_download
            on_download = True

        http.download(d_data, d_cb)
        while True:
            if on_download:
                on_download = False
                break
            else:
                time.sleep(1)
        print('download succeed :' + path)
예제 #4
0
 def get_response_json(cls, _id, page, refer=None):
     url = cls.TEMPLATE.format(_id=_id, page=page)
     refer = "http://cnews.qq.com/cnews/android/"
     request = http.Request.from_random_mobile(url, headers={"referer": refer})
     try:
         response = http.download(request)
     except Exception:
         return None
     else:
         return json.loads(response.body)
예제 #5
0
 def get_response_json(cls, _id, page, refer=None):
     offset = page * cls.LIMIT
     url = cls.TEMPLATE.format(_id=_id, offset=offset, limit=cls.LIMIT)
     request = http.Request.from_random_mobile(url, headers={"referer": refer})
     try:
         response = http.download(request)
     except Exception:
         return None
     else:
         return json.loads(response.body)
예제 #6
0
 def get(cls, _id, news_id, news_url, page=0):
     comment_url = cls.get_comment_url(news_url)
     request = http.Request.from_default_browser(url=comment_url, headers={"referer": news_url})
     try:
         response = http.download(request)
     except Exception:
         return list()
     result = json.loads(response.body)
     _comments = result.get("comment", [])
     comments = list()
     for _comment in _comments:
         comment = Comment()
         comment.user_name = _comment["nick_name"]
         comment.user_icon = _comment["logo_url"]
         dt = datetime.fromtimestamp(_comment["create_time"])
         comment.publish_time = dt.strftime("%Y-%m-%d %H:%M:%S")
         comment.n_like = _comment["like_num"]
         # comment["comment_id"] = _comment["content_id"]
         comment.text = _comment["content"]
         comments.append(comment)
     return comments
예제 #7
0
 def test_download(self):
     print http.download('http://omgmkt.qq.com/got/xz', os.path.join(BASE_DIR, 'temp', 't1', 't2', 'a'),
                         create_dirs=True)
예제 #8
0
def download_resource_file(on_request, resDir):
    global toneDir, on_callback, on_download, cb_data
    toneDir = resDir

    data = {
        'url': on_request['url'],
        'method': 'GET',
        'headers': {
            'content-type': 'application/x-www-form-urlencoded'
        },
        'timeout': 30000,
        'params': ''
    }

    def cb(data):
        global on_callback, cb_data
        on_callback = True
        cb_data = data

    http.request(data, cb)

    while True:
        if on_callback:
            on_callback = False
            break
        else:
            time.sleep(1)
    # {
    #     "audios":
    #     [
    #         {   "format":"wav",
    #             "id":"zfbGet",
    #             "size":40204,
    #             "type":"custom",
    #             "url":"http://speech-solution.oss-cn-shanghai.aliyuncs.com/xxxx"
    #         }
    #     ],
    #     "format":"wav",
    #     "size":40204
    # }
    print(cb_data)
    response = json.loads(cb_data['body'])
    audio = response['audios'][0]
    format = audio['format']
    id = audio['id']
    size = audio['size']

    path = toneDir + id + '.' + format
    print('************ begin to download: ' + path)
    d_data = {'url': audio['url'], 'filepath': path}

    def d_cb(data):
        global on_download
        on_download = True

    http.download(d_data, d_cb)

    while True:
        if on_download:
            on_download = False
            break
        else:
            time.sleep(1)
    print('download succeed :' + path)
예제 #9
0
    def login(self,acc,pwd,vcode='',vcodestr=''):

        url = 'https://passport.baidu.com/v2/api/?login'
        pubkey , rsakey = self._get_publickey()

        #print pubkey
        #print rsakey
        key = rsa.PublicKey.load_pkcs1_openssl_pem(pubkey)
        password_rsaed = base64.b64encode(rsa.encrypt(pwd, key))

        data = {}
        data[u'staticpage'] = 'https://passport.baidu.com/static/passpc-account/html/v3Jump.html'
        data[u'charset'] = 'UTF-8'
        data[u'token'] = self.token
        data[u'tpl']='tb'
        data[u'subpro'] = ''
        data[u'apiver'] = 'v3'
        data[u'tt']=str(int(time.time()))
        data[u'codestring']=vcodestr
        data[u'safeflg'] = 0
        data[u'u']='https://passport.baidu.com/'
        data[u'isPhone'] = ''
        data[u'detect']= 1
        data[u'gid']='6A3375C-5CE5-4696-A8C2-8BBE62516FAF'
        data[u'quick_user']=0
        data[u'logintype']='basicLogin'
        data[u'logLoginType']= 'pc_loginBasic'
        data[u'idc']=''
        data[u'loginmerge']='true'
        data[u'username']=acc
        data[u'password']=password_rsaed
        data[u'verifycode'] = vcode
        data[u'rsakey']=rsakey
        data[u'crypttype']=12
        data[u'countrycode']=''
        data[u'callback']=0

        # start login
        data=http.request(url,data)
        #data=json.loads(data)
        err_no,code_string = self._check_login_error(data)
        '''
        if data[u'errInfo'][u'no']=='0':
            #login success & need save bduss
            bduss=data['user']['BDUSS'].encode('utf-8')
            bduss = 'BDUSS='+bduss.decode()
            self.__writebduss__(bduss)
        '''
        '''
        if data[u'errInfo'][u'no']=='500001':
            url = 'http://wappass.baidu.com/cgi-bin/genimage?'+data[u'data'][u'codeString'] + '&v='+str(int(time.time()*1000))
            http.download(url,cur_dir()+u'/',u'vcode.jpg')
            vc = raw_input('请输入验证码:')
            return self.login(baiduUtf(acc),base64.b64encode(pwd.encode('utf-8')).decode(),vc,data[u'data'][u'codeString'])
        '''
        # 是否需要验证码
        if err_no=='257' or err_no=='6' :
            url = 'https://passport.baidu.com/cgi-bin/genimage?'+ code_string + '&v='+str(int(time.time()*1000))
            http.download(url,cur_dir()+u'/',u'vcode.jpg')
            vc = raw_input('请输入验证码:')
            self.login(acc,pwd,vc,code_string)
        if err_no=='0':
            # bduss = None
            for item in http.cookies():
                if item.name == 'BDUSS':
                    self.bduss = item.value
                if item.name == 'BAIDUID':
                    self.baiduid = item.value
            #self.bdauth = 'BAIDUID=' + self.baiduid + '; BDUSS=' + self.bduss
            #print self.bdauth
            self.__writebduss__(self.bduss,self.baiduid)
            print 'relogin access!'