Exemplo n.º 1
0
def entry_into_force_time(url):
    '''
    获取生效时间
    :param url:
    :return: str 2016-01-10
    '''
    first_res = requests.get(url=baes_url + url, headers=headers)
    first_res.encoding = 'utf-8'
    soup = BeautifulSoup(first_res.text, 'lxml')
    date_y = get_date_object(
        str(soup.find('div',
                      class_='article_opt').find('i').text).strip()).year
    p_list = soup.find('div', class_='allZoom').find_all('p')
    take_effect_text = re.findall(r'(\w+月\w+日正式生效)', p_list[0].text)
    if take_effect_text:
        date_m_d = re.findall(r'([0-9]+)', take_effect_text[0])
        if len(date_m_d) == 2:
            com_date = '%s%s%s' % (date_y, date_m_d[0], date_m_d[1])
        else:
            com_date = '%s%s%s' % (date_m_d[0], date_m_d[1], date_m_d[2])
    else:
        take_effect_text = re.findall(r'(\w+月\w+日正式生效)', p_list[1].text)
        if take_effect_text:
            date_m_d = re.findall(r'([0-9]+)', take_effect_text[0])
            if len(date_m_d) == 2:
                com_date = '%s%s%s' % (date_y, date_m_d[0], date_m_d[1])
            else:
                com_date = '%s%s%s' % (date_m_d[0], date_m_d[1], date_m_d[2])
        else:
            take_effect_text = re.findall(r'(\w+月\w+日正式生效)', p_list[-1].text)
            if not take_effect_text:
                print('请查看具体页面:%s' % url)
            date_m_d = re.findall(r'([0-9]+)', take_effect_text[0])
            if len(date_m_d) == 2:
                com_date = '%s%s%s' % (date_y, date_m_d[0], date_m_d[1])
            else:
                com_date = '%s%s%s' % (date_m_d[0], date_m_d[1], date_m_d[2])
    com_date = get_date_object(com_date, "%Y%m%d").date()
    return com_date
Exemplo n.º 2
0
    'first': [],
    'second': [],
    'third': [],
}
constituent_shares_list = LmInnerReportDBMgr.get_data_list('lm_index_data', {'code': '000016'},
                                                           'constituent_shares_list')
__list = sorted(constituent_shares_list, key=lambda item: item['date'], reverse=True)

max_date = __list[0]['date']
min_date = __list[-1]['date']
# 1、获取此指数从头到尾的所有日期
date_list = getEveryDay(min_date, max_date, 1)
date_list = sorted(date_list, reverse=True)
# 2、将日期按照规则分配到date_dict中
for date in date_list:
    date_obj = get_date_object(date)
    # [每一年的10-31到09-01]
    if 9 <= date_obj.month <= 10:
        date_dict['first'].append(date)
    # [每一年08-31到05-01]
    elif 5 <= date_obj.month <= 8:
        date_dict['second'].append(date)
    # [最新日期到此年限或上一年的11-01(要判断最新日期月份是不是12月,如果是12月那么就是当前年份的11-01,如果是1月或2月或3月或4月,就用上一年份的11-01)]
    # [最新日期此年的4月30到一下年的11-01日]
    else:
        date_dict['third'].append(date)

print(date_dict['third'])
print(__list[0]['date'])
print(__list[0]['cfg'])
if __list[0]['date'] in date_dict['first']:
Exemplo n.º 3
0
def lrb(response, stock_code):
    '''

    :param response: 利润表的数据 str
    :param stock_code: 股票代码
    :return:
    '''
    zd_list = [
        "YEAREND_DATE", "GROSS_REVENUE", "OPERATIONG_RECEIPT",
        "INTEREST_REVENUE", "EARNED_PREMIUM", "POUNDAGE_AND_COMMISSION_INCOME",
        "SALES_INCOME_OF_REAL_ESTATE", "OTHER_BUSINESS_INCOME",
        "TOTAL_OPERATING_COST", "COST_IN_BUSINESS", "INTEREST_EXPENSE",
        "POUNDAGE_AND_COMMISSION_EXPENSES", "SALE_COST_OF_REAL_ESTATE",
        "RESEARCH_AND_DEV_ELOPMENT_COST", "SURRENDER_VALUE",
        "PAYMENT_NET_EXPENDITURE", "EXTRACT_INSURANCE_CONTRACT_RESERVE_NET",
        "EXPENDITURE_DIVIDEND_POLICY", "REINSURANCE_EXPENSES",
        "OTHER_BUSINESS_COSTS", "BUSINESS_TAXES_AND_SURCHARGES",
        "SELLING_EXPENSES", "MANAGEMENT_EXPENSES", "FINANCIAL_EXPENSES",
        "ASSETS_IMPAIRMENT_LOSS", "FAIR_VALUE_CHANGE_INCOME",
        "INVESTMENT_PROFIT",
        "INVESTMENT_INCOME_FOR_VENTURES_AND_JOINT_VENTURES",
        "EXCHANGE_EARNINGS", "FUTURES_PROFIT_AND_LOSS", "MANAGED_INCOME",
        "SUBSIDY_INCOME", "OTHER_BUSINESS_PROFITS", "OPERATING_PROFIT",
        "NON_BUSINESS_INCOME", "NON_BUSINESS_ESPENDITURE",
        "DISPOSAL_LOSS_OF_NON_CURRENT_ASSETS", "TOTAL_PROFIT",
        "INCOME_TAX_EXPENSE", "UNCINFIRMED_INVESTMENT_LOSS", "NET_MARGIN",
        "VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN",
        "NET_PROFIT_OF_THE_MERGED_PARTY_BEFORE_MERGER",
        "MINORITY_SHAREHOLDER_PROFIT_AND_LOSS", "BASIC_PER_SHARE_PROFIT",
        "BILUTED_EARNINGS_PER_SHARE"
    ]

    lrb_data = [{j[0]: j[1]
                 for j in i} for i in (zip(zd_list, it) for it in zip(*[
                     item.strip().split(",")[1:-1]
                     for item in response.text.strip().split("\n")
                 ]))]
    for i in range(len(lrb_data)):
        '''
        处理单季度归属母公司净利润数据
        '''
        try:
            first_data = lrb_data[i]
            second_data = lrb_data[i + 1]
            first_date_obj = get_date_object(first_data['YEAREND_DATE'])
            second_date_obj = get_date_object(second_data['YEAREND_DATE'])
            if first_date_obj.month == 3 or first_date_obj.year != second_date_obj.year:
                # 3月的库里数据就是单季度的,则直接设置新字段存入mongo
                # print('三月的数据,可直接存入库中...first: {},second: {}'.format(first_data['YEAREND_DATE'],
                #                                                     second_data['YEAREND_DATE']))
                SIGNLE_VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN = float(
                    first_data['VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN'])
            elif first_date_obj.year == second_date_obj.year and (
                    first_date_obj.month - second_date_obj.month) == 3:
                # 6月- 3月 9月 - 6月,或12月 - 9月,直接将数据做减法
                # print('month相差3个月,则做减法输出 first: {},second: {}'.format(first_data['YEAREND_DATE'],
                #                                                       second_data['YEAREND_DATE']))
                try:
                    SIGNLE_VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN = float(
                        first_data[
                            'VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN']
                    ) - float(second_data[
                        'VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN'])
                except ValueError:
                    print('净利润数据为:--,无法计算,则忽略')
                    SIGNLE_VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN = ''
            else:
                print('未上市的财报不需要处理')
                # print('有问题的数据 first:{},second:{}'.format(first_data['YEAREND_DATE'], second_data['YEAREND_DATE']))
                SIGNLE_VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN = ''
        except IndexError:
            first_data = lrb_data[i]
            # print('最后一条数据,不需要进行任何操作first: {}'.format(first_data['YEAREND_DATE']))
            SIGNLE_VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN = float(
                first_data['VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN'])
        lrb_data[i][
            'SIGNLE_VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN'] = SIGNLE_VEST_IN_PARENT_COMPANY_PROPRIETOR_NET_MARGIN
    db_report_date = LmInnerReportDBMgr.get_code('lm_stock_data', stock_code,
                                                 'financial_report_date')
    if db_report_date:
        if date_turn_timestamp(db_report_date, lrb_data[0]['YEAREND_DATE']):
            LmInnerReportDBMgr.save_set_result('lm_stock_data',
                                               {'code': stock_code},
                                               'report.lrb', lrb_data)
    else:
        LmInnerReportDBMgr.save_insert_result(
            'lm_stock_data', {
                'code': stock_code,
                'financial_report_date': lrb_data[0]['YEAREND_DATE'],
                'report': {
                    'lrb': lrb_data
                }
            })