Example #1
0
    def getBasicInfo(self):
        url = get_urls('url_view')
        timestamp_ms = get_timestamp()
        appkey = get_key()
        UAS = get_user_agents()
        params = {'type': 'json', 'appkey': appkey, 'id': str(
            self.aid), '_': '{}'.format(timestamp_ms)}
        # print(params)
        headers = {'User-Agent': random.choice(UAS)}
        # print(headers)

        try:
            res = requests.get(url, params=params, headers=headers)
            res.raise_for_status()
        except Exception as e:
            # print(e)
            msg = 'aid({}) get error'.format(self.aid)
            bilivideolog.error(msg)
            return None
        data = json.loads(res.text)
        # print(data)
        if 'mid' in data:
            # ('added','mid','aid','tid','cid','typename','arctype','title','pic','pages','created')
            related_info = (get_timestamp_s(), data['mid'], self.aid, data['tid'],
                            data['cid'], data['typename'], data['arctype'],
                            data['title'], data['pic'],
                            data['pages'], data['created'])
            return related_info

        else:
            msg = 'aid({}) basic info request  return error'.format(self.aid)
            bilivideolog.info(msg)
            return None
Example #2
0
    def getAjaxInfo(self):
        """获取视频ajax信息"""
        url = get_urls('url_stat')
        timestamp_ms = get_timestamp()
        UAS = get_user_agents()
        params = {'aid': str(self.aid), '_': '{}'.format(timestamp_ms)}
        headers = {'User-Agent': random.choice(UAS)}

        try:
            res = requests.get(url, params=params, headers=headers)
            res.raise_for_status()
        except Exception as e:
            # print(e)
            msg = 'aid({}) get error'.format(self.aid)
            bilivideolog.error(msg)
            return None
        text = json.loads(res.text)
        # print(text)
        try:
            if text['code'] == 0:
                data = text['data']
                ajax_info = (data['view'], data['danmaku'], data['reply'],
                             data['favorite'], data['coin'], data['share'],
                             data['now_rank'], data['his_rank'], data['like'],
                             data['no_reprint'], data['copyright'])
                return ajax_info

            else:
                msg = 'aid({}) ajax request code return error'.format(self.aid)
                bilivideolog.info(msg)
                return None
        except TypeError:
            msg = 'aid({}) text return None'.format(self.aid)
            bilivideolog.info(msg)
            return None
Example #3
0
File: stock.py Project: wind9/noone
def get_stock_info2(stock_code):
    urls = get_urls()
    xq_url = urls.get('xueqiu2')
    xq_headers = headers
    xq_cookies = get_cookies()['xueqiu']
    period = "1day"
    price_type = 'before'
    req_url = xq_url.format(stock_code, period, price_type)
    day_price_list = []
    try:
        resp = requests.get(req_url, headers=headers, cookies=xq_cookies)
        price_info = json.loads(resp.content)
        if price_info['success'] == 'true':
            for d in price_info['chartlist']:
                stock_day_price = {}
                stock_day_price['trade_date'] = parse_time.timestamp2date(
                    d['timestamp'] / 1000)
                stock_day_price['stock_code'] = stock_code
                stock_day_price['open'] = d['open']
                stock_day_price['close'] = d['close']
                stock_day_price['high'] = d['high']
                stock_day_price['low'] = d['low']
                stock_day_price['chg'] = d['chg']
                stock_day_price['percent'] = d['percent']
                stock_day_price['volume'] = d['volume']
                stock_day_price['lot_volume'] = d['lot_volume']
                day_price_list.append(stock_day_price)
                #result = '{}\t{}\t{}\t{}\t{}\t{}'.format(time, open, close, high, low, percent)
    except Exception as e:
        print(e)
        storage.log("获取{}信息异常".format(stock_code))
        storage.exception(e)
    finally:
        return day_price_list
    def getVideoList(uid):
        url = get_urls('url_submit')
        timestamp_ms = get_timestamp()
        UAS = get_user_agents()
        headers = {'User-Agent': random.choice(UAS)}
        params = {'mid': str(uid), '_': '{}'.format(timestamp_ms)}
        video_num = 0
        video_pages = 0
        try:
            response = requests.get(url, headers=headers, params=params)
            text = json.loads(response.text)
            video_num = text['data']['count']
            video_pages = text['data']['pages']
        except Exception as e:
            msg = 'user({}) vnum text got error and {}'.format(uid, e)
            bilivideolog.error(msg)
            return None
        # 没投过稿
        if video_num < 1:
            return None

        def get_videoinfo(url, mid, pages):
            """返回所有aid的序列"""
            vlist = None
            for page in range(1, pages + 1):
                params = {
                    "mid": '{}'.format(mid),
                    "page": '{}'.format(page),
                    '_': '{}'.format(timestamp_ms)
                }
                try:
                    response = requests.get(url,
                                            headers=headers,
                                            params=params)
                    text = json.loads(response.text)
                    vlist = text['data']['vlist']
                    for item in vlist:
                        # vinfo:("mid", "aid",
                        # "tid","title","created","length","play","comment",
                        # "danmaku","favorite","hide_click")
                        vinfo = (item["mid"], item["aid"], item["typeid"],
                                 item["title"], item["created"],
                                 item["length"], item["play"], item["comment"],
                                 item["video_review"], item["favorites"],
                                 item["hide_click"])
                        # yield(item['aid'])
                        yield vinfo
                except Exception as e:
                    msg = 'uid({}) vlist get error and\n {}'.format(mid, e)
                    bilivideolog.error(msg)
                    return None

                time.sleep(1)  # 每页休息一下

        return get_videoinfo(url, uid, video_pages)
Example #5
0
File: stock.py Project: wind9/noone
def get_stock_info(stock_code, start_date, end_date):
    urls = get_urls()
    xq_url = urls.get('xueqiu')
    xq_headers = headers
    xq_cookies = get_cookies()['xueqiu']
    start_timestamp = parse_time.date2timstamp(start_date)
    end_timestamp = parse_time.date2timstamp(end_date)
    now_timestamp = parse_time.get_now_timestamp()
    period = "1day"
    price_type = 'before'
    req_url = xq_url.format(stock_code, period, price_type, start_timestamp,
                            end_timestamp, now_timestamp)
    resp = requests.get(req_url, headers=headers, cookies=xq_cookies)
    jdata = json.loads(resp.content)
    return jdata
Example #6
0
    def getVideoList(uid):
        url = get_urls('url_submit')
        timestamp_ms = get_timestamp()
        UAS = get_user_agents()
        headers = {'User-Agent': random.choice(UAS)}
        params = {'mid': str(uid), '_': '{}'.format(timestamp_ms)}
        video_num = 0
        video_pages = 0
        try:
            response = requests.get(url, headers=headers, params=params)
            text = json.loads(response.text)
            video_num = text['data']['count']
            video_pages = text['data']['pages']
        except Exception:
            msg = 'user({}) vnum text got error'.format(uid)
            bilivideolog.error(msg)
            return None
        # 没投过稿
        if video_num < 1:
            return None

        def get_aids(url, mid, pages):
            """返回所有aid的序列"""
            vlist = None
            for page in range(1, pages + 1):
                params = {"mid": '{}'.format(mid), "page": '{}'.format(page),
                          '_': '{}'.format(timestamp_ms)}
                try:
                    response = requests.get(
                        url, headers=headers, params=params)
                    text = json.loads(response.text)
                    vlist = text['data']['vlist']
                    for item in vlist:
                        yield(item['aid'])
                except Exception as e:
                    msg = 'uid({}) vlist get error and\n {}'.format(mid, e)
                    bilivideolog.error(msg)
                    return None

                time.sleep(1)  # 休息一下

        return get_aids(url, uid, video_pages)
Example #7
0
    def getUserInfo(cls, uid):
        url = get_urls('url_user')
        timestamp_ms = get_timestamp()
        UAS = get_user_agents()
        headers = {'User-Agent': random.choice(UAS)}
        params = {'mid': str(uid), '_': '{}'.format(timestamp_ms)}

        try:
            res = requests.get(url, headers=headers, params=params)
            res.raise_for_status()
            text = json.loads(res.text)
        except Exception as e:
            msg = 'uid({}) get error'.format(uid)
            biliuserlog.error(msg)
            return None

        try:
            if text['code'] == 0:
                data = text['data']['card']

                info = (data['mid'], data['name'],
                        data['approve'], data['sex'],
                        data['DisplayRank'], data['regtime'],
                        data['spacesta'], data['birthday'],
                        data['place'],
                        data['article'], data['fans'],
                        data['attention'],
                        data['level_info']['current_level'],
                        data['official_verify']['type'],
                        data['vip']['vipStatus'])
                return info
            else:
                msg = 'uid({}) request code return error'.format(uid)
                biliuserlog.info(msg)
                return None
        except TypeError:
            msg = 'uid({}) text return None'.format(uid)
            biliuserlog.info(msg)
            return None