示例#1
0
def format_date_param(start_date, end_date):
    if end_date is None:
        end_date = get_current_day()

    if start_date is None:
        start_date = get_target_date(-360, '%Y-%m-%d')

    return start_date, end_date
示例#2
0
def get_pledge_info(market='SH', date = None):
    if date is None:
        date = get_current_day(format = '%Y-%m-%d')

    if market == 'SH':
        return shex_agent.get_pledge_info(date)

    if market == 'SZ':
        return szex_agent.get_pledge_info(date)

    return None, None
示例#3
0
    def get_recent_daily_aqi_onecity(self, city):
        url = 'http://datacenter.mep.gov.cn/websjzx/report!list.vm'
        if city not in city_code_map:
            print("this city is not ready !" + city)
            return None

        city_code = city_code_map[city]

        data = {
            'citycodes': city_code,
            'citytime': get_current_day(),
            'xmlname': "1513844769596kqzllb"
        }

        rsp = self.do_request(url, data, self.proxies)

        # 2. 开始解析返回数据,并从html中提取需要的内容
        data = list()
        soup = BeautifulSoup(rsp, "html5lib")
        divs = soup.find_all('div')

        for div in divs:
            if div.has_attr('class') and 'report_main' in div['class']:
                rows = div.table.findAll('tr')
                for row in rows:
                    cols = row.findAll('td')
                    if len(cols) == 7:
                        date = cols[1].text
                        aqi = cols[3].text
                        level = cols[5].text
                        indicator = cols[4].text
                        data.append({
                            "date": date,
                            "aqi": aqi,
                            "level": level,
                            "indicator": indicator,
                        })

        df = pd.DataFrame(data)
        return df
示例#4
0
    def get_lgt_share(self, market='SH', date=None):
        url = "http://sc.hkexnews.hk/TuniS/www.hkexnews.hk/sdw/search/mutualmarket_c.aspx?t=%s" % (
            market)

        today = get_current_day()
        if date is None:
            date = today

        search_date = datetime.datetime.strptime(date, "%Y-%m-%d")
        year, month, day = search_date.year, search_date.month, search_date.day

        data = {
            'today': date_convert(today, "%Y-%m-%d", "%Y%m%d"),
            'ddlShareholdingDay': "%02d" % day,
            'ddlShareholdingMonth': "%02d" % month,
            'ddlShareholdingYear': year,
            'sortBy': '',
            'alertMsg': '',
            'btnSearch.x': 23,
            'btnSearch.y': 5,
        }
        aspx_param = self.get_aspx_param(url)
        data.update(aspx_param)

        self.add_headers({
            "Content-Type": "application/x-www-form-urlencoded",
        })

        rsp = self.do_request(url, data, "POST")

        # 2. 开始解析返回数据,并从html中提取需要的内容
        data = list()
        soup = BeautifulSoup(rsp, "html5lib")
        divs = soup.find_all('div')

        result_date = ""
        for div in divs:
            if div.has_attr('id') and 'pnlResult' in div['id']:

                res_div = div.find_all('div')
                if (len(res_div)) > 0:
                    result_date = HKExAgent.clear_text(res_div[0].text)
                    result_date = result_date.replace("持股日期: ", "").strip()
                    result_date = date_convert(result_date, "%d/%m/%Y",
                                               "%Y-%m-%d")
                rows = div.table.findAll('tr')
                for row in rows:
                    cols = row.findAll('td')
                    if len(cols) == 4:
                        code = HKExAgent.clear_text(cols[0].text)
                        name = HKExAgent.clear_text(cols[1].text)
                        share_num = HKExAgent.clear_text(cols[2].text)
                        percent = HKExAgent.clear_text(cols[3].text)
                        data.append({
                            "code":
                            HKExAgent.process_code(market, code),
                            "name":
                            name,
                            "share_num":
                            share_num,
                            "percent":
                            percent,
                            "date":
                            result_date,
                        })

        df = pd.DataFrame(data)
        return df
示例#5
0
    def get_lgt_share(self, market='SH', date=None):
        url = "http://sc.hkexnews.hk/TuniS/www.hkexnews.hk/sdw/search/mutualmarket_c.aspx?t=%s" % (
            market)

        today = get_current_day()
        if date is None:
            date = today

        data = {
            'today': date_convert(today, "%Y-%m-%d", "%Y%m%d"),
            'sortBy': 'stockcode',
            'sortDirection': 'asc',
            'alertMsg': '',
            'txtShareholdingDate': date_convert(date, "%Y-%m-%d", "%Y/%m/%d"),
            'btnSearch': "搜寻",
        }
        aspx_param = self.get_aspx_param(url)
        data.update(aspx_param)

        self.add_headers({
            "Content-Type": "application/x-www-form-urlencoded",
        })

        rsp = self.do_request(url, data, "POST")

        # 2. 开始解析返回数据,并从html中提取需要的内容
        data = list()
        soup = BeautifulSoup(rsp, "html5lib")
        divs = soup.find_all('div')

        result_date = ""
        for div in divs:
            if div.has_attr('id') and 'pnlResult' in div['id']:

                res_span = div.find_all('span')

                if (len(res_span)) > 0:
                    result_date = HKExAgent.clear_text(res_span[0].text)
                    result_date = result_date.replace("持股日期:", "").strip()
                    result_date = date_convert(result_date, "%Y/%m/%d",
                                               "%Y-%m-%d")
                rows = div.table.findAll('tr')
                for row in rows:
                    cols = row.findAll('td')
                    if len(cols) == 4:
                        code = HKExAgent.clear_text(cols[0].text.replace(
                            "股份代号:", ""))
                        name = HKExAgent.clear_text(cols[1].text.replace(
                            "股份名称:", ""))
                        share_num = HKExAgent.clear_text(cols[2].text.replace(
                            "于中央结算系统的持股量:", ""))
                        percent = HKExAgent.clear_text(cols[3].text.replace(
                            "占于深交所上市及交易的A股总数的百分比:",
                            "").replace("占于上交所上市及交易的A股总数的百分比:", ""))
                        data.append({
                            "code":
                            HKExAgent.process_code(market, code),
                            "name":
                            name,
                            "share_num":
                            share_num,
                            "percent":
                            percent,
                            "date":
                            result_date,
                        })

        df = pd.DataFrame(data)
        return df