コード例 #1
0
def write_info_to_database(session: DBSession, rows):
    rows = [format_row(info_json) for info_json in rows]
    for row in rows:
        rowDict = zip(header(), row)
        rowDict = {a[0]: a[1] for a in rowDict}
        session.merge(FundInfo1(**rowDict))
    session.commit()
コード例 #2
0
def write_info_to_database(session: DBSession, rows):
    obj_list = []
    for row in rows:
        try:
            row['基金代码'] = row['code']
            row['净值日期'] = row['date']
            # row['单位净值'] = float(row['单位净值'])
            # row['累计净值'] = float(row['累计净值'])
            del row['code']
            del row['date']

            obj_list.append(FundTrend(**row))
        except Exception as e:
            print(e)
    session.bulk_save_objects(obj_list)
    session.commit()
コード例 #3
0
ファイル: pyspider_howbuy.py プロジェクト: ekansrm/crawler
    def crawl_info(self, response):

        info = get_fund_info(pq(response.text))

        if not info['_success']:
            return {'_success': False}

        session = DBSession()

        session.merge(
            FundInfoJson(code=info['代码'],
                         type='20201111',
                         json=json.dumps(info)))
        session.merge(
            FundProc(code=info['代码'],
                     info_status=0,
                     info_retry=0,
                     info_mdf=get_today_dt()))

        session.commit()
        session.close()

        return {'_success': True}