Example #1
0
 def get_spo_detail_data(provider: Provider, sleep, desc, pc, lock, region,
                         batch):
     # 现金增资
     SpoDetail.record_data(provider=provider,
                           share_para=(desc, pc, lock, True, region),
                           sleeping_time=sleep,
                           batch_size=batch)
def test_000778_spo_detial():
    result = SpoDetail.query_data(session=session,
                                  provider='eastmoney',
                                  return_type='domain',
                                  codes=['000778'],
                                  end_timestamp='2018-09-30',
                                  order=SpoDetail.timestamp.desc())
    assert len(result) == 4
    latest: SpoDetail = result[0]
    assert latest.timestamp == to_pd_timestamp('2017-04-01')
    assert latest.spo_issues == 347600000
    assert latest.spo_price == 5.15
    assert latest.spo_raising_fund == 1766000000
Example #3
0
def test_000778_spo_detial():
    result = SpoDetail.query_data(
        session=session,
        provider="eastmoney",
        return_type="domain",
        codes=["000778"],
        end_timestamp="2018-09-30",
        order=SpoDetail.timestamp.desc(),
    )
    assert len(result) == 4
    latest: SpoDetail = result[0]
    assert latest.timestamp == to_pd_timestamp("2017-04-01")
    assert latest.spo_issues == 347600000
    assert latest.spo_price == 5.15
    assert latest.spo_raising_fund == 1766000000
Example #4
0
    def on_finish(self):
        last_year = str(now_pd_timestamp(Region.CHN).year)
        codes = [item.code for item in self.entities]
        need_filleds = DividendFinancing.query_data(
            region=self.region,
            provider=self.provider,
            codes=codes,
            return_type='domain',
            filters=[DividendFinancing.spo_raising_fund.is_(None)],
            end_timestamp=last_year)

        desc = SpoDetail.__name__ + ": update relevant table"
        with tqdm(total=len(need_filleds),
                  ncols=90,
                  desc=desc,
                  position=2,
                  leave=True) as pbar:
            from sqlalchemy import func

            session = get_db_session(region=self.region,
                                     provider=self.provider,
                                     data_schema=self.data_schema)

            for item in need_filleds:
                result = SpoDetail.query_data(
                    region=self.region,
                    provider=self.provider,
                    entity_id=item.entity_id,
                    start_timestamp=item.timestamp,
                    end_timestamp="{}-12-31".format(item.timestamp.year),
                    return_type='func',
                    func=func.sum(SpoDetail.spo_raising_fund))

                if isinstance(result, (int, float)):
                    item.spo_raising_fund = result
                    session.commit()
                pbar.update()

        super().on_finish()
Example #5
0
    def on_finish(self):
        last_year = str(now_pd_timestamp().year)
        codes = [item.code for item in self.entities]
        need_filleds = DividendFinancing.query_data(
            provider=self.provider,
            codes=codes,
            return_type='domain',
            session=self.session,
            filters=[DividendFinancing.spo_raising_fund.is_(None)],
            end_timestamp=last_year)

        for item in need_filleds:
            df = SpoDetail.query_data(
                provider=self.provider,
                entity_id=item.entity_id,
                columns=[SpoDetail.timestamp, SpoDetail.spo_raising_fund],
                start_timestamp=item.timestamp,
                end_timestamp="{}-12-31".format(item.timestamp.year))
            if pd_is_not_null(df):
                item.spo_raising_fund = df['spo_raising_fund'].sum()
                self.session.commit()
        super().on_finish()
Example #6
0
def test_spo_detail():
    try:
        SpoDetail.record_data(provider='eastmoney', codes=SAMPLE_STOCK_CODES)
    except:
        assert False