예제 #1
0
    def get_keystats(self):
        def get_items(bs, text):

            span = bs.find("span", text=text)
            main_div = span.parent.parent

            items = []
            for tr in main_div.find_all("tr"):

                tds = tr.find_all("td")
                if len(tds) == 0:
                    continue

                items.append([tds[0].text, tds[1].text])

            return items

        url = STATS.format(ticker=self.ticker)
        bs = request(CONFIG, url).content
        bs = BeautifulSoup(bs, PARSER)

        items = get_items(bs, "Financial Highlights")
        items.extend(get_items(bs, "Trading Information"))
        items.extend(get_items(bs, "Valuation Measures"))

        key_stats = []
        for feature_name, feature in items:
            key = self.feature_conversion(feature_name)
            key_stats.append([*key, self.fmt(feature, metric=key[0])])

        df = pd.DataFrame(key_stats, columns=["feature", "modifier", "value"])
        pkey = ["feature", "modifier"]
        df.loc[:, pkey] = df[pkey].fillna('')
        self.keystats = df
예제 #2
0
 def upload_image(self, token, image_type):
     """上传图像"""
     description = '供应链-上传图像'
     method = "POST"
     path = "/sc/upload/image"
     url = HostPort + path
     image_body = self.upload_image_body(image_type)
     response = request(method, url, description, params=image_body, token=token,
                        platform=PlatformProjectEnums.SUPPLY_CHAIN.value,
                        content_type=ContentTypeEnums.FORM_DATA.value)
     return response
예제 #3
0
 def borrower_auth_sa_login_by_pwd(self):
     """供应链-用户密码登录"""
     description = '供应链-用户密码登录'
     method = "POST"
     path = "/sc/borrower/auth/!/login/bypwd"
     url = self.host_port + path
     params = self.borrower_auth_sa_login_by_pwd_body()
     response = request(method,
                        url,
                        description,
                        params=params,
                        platform=PlatformProjectEnums.SUPPLY_CHAIN.value)
     return response
예제 #4
0
 def borrower_reg_by_sms_code(self):
     """供应链-用户注册"""
     description = '供应链-用户注册'
     method = "POST"
     path = "/sc/auth/bysmscode"
     url = self.host_port + path
     params = self.borrower_reg_by_sms_code_body()
     response = request(method,
                        url,
                        description,
                        params=params,
                        platform=PlatformProjectEnums.SUPPLY_CHAIN.value)
     return response
예제 #5
0
 def borrower_auth_sms_code(self, mobile, template):
     """获取注册验证码"""
     description = '供应链-获取注册验证码'
     method = "POST"
     path = "/sc/auth/get"
     url = self.host_port + path
     params = self.borrower_auth_sms_code_body(mobile, template)
     response = request(method,
                        url,
                        description,
                        params=params,
                        platform=PlatformProjectEnums.SUPPLY_CHAIN.value)
     return response
예제 #6
0
    def get_dividends(self):

        url = SUMMARY.format(ticker=self.ticker)
        bs = BeautifulSoup(request(CONFIG, url).content, PARSER)

        table = bs.find_all("table")[1]
        div = table.find("td", {"data-test": "DIVIDEND_AND_YIELD-value"})

        if not div:
            div = table.find("td", {"data-test": "TD_YIELD-value"}).text
        else:
            div = div.text.split(' ')[1][1:-1]
            div = div.replace('N/A', '')

        return self.option_fmt(div, 'Dividend')
예제 #7
0
        def get_page(url):

            ctr, max_ctr = 0, 3
            while (ctr < max_ctr):

                bs = BeautifulSoup(request(CONFIG, url).content, PARSER)
                options = bs.find_all("option")

                if len(options) != 0:
                    break

                ctr += 1
                print(f"{self.ticker},Option Download,{ctr}")
                self.sleep()

            return bs, options
예제 #8
0
    def get_ohlc(self):

        url = OHLC.format(ticker=self.ticker)
        bs = BeautifulSoup(request(CONFIG, url).content, PARSER)

        prices = bs.find("table", {"data-test": "historical-prices"})
        prices = prices.find_all("tr")[1]
        prices = [price.text for price in prices]

        self.ohlc_date = datetime.strptime(prices[0],
                                           "%b %d, %Y").strftime("%Y-%m-%d")

        prices = list(map(self.option_fmt, prices[1:], OHLC_COLS[:-2]))
        prices = [self.ohlc_date, self.ticker] + prices + [self.div]
        self.adj_close = prices[-3]
        self.ohlc = pd.DataFrame([prices], columns=OHLC_COLS)
 def borrower_save_base_info(self, token):
     """保存借款人资料"""
     description = '供应链-保存借款人资料'
     method = "POST"
     path = "/sc/saveBaseInfo"
     url = self.host_port + path
     params = self.borrower_save_base_info_body()
     response = request(
         method,
         url,
         description,
         token=token,
         params=params,
         platform=PlatformProjectEnums.SUPPLY_CHAIN.value,
         content_type=ContentTypeEnums.SUPPLY_CHAIN_HEADER.value)
     return response