当前位置: 首页>>代码示例>>Python>>正文


Python Session.add_all方法代码示例

本文整理汇总了Python中models.Session.add_all方法的典型用法代码示例。如果您正苦于以下问题:Python Session.add_all方法的具体用法?Python Session.add_all怎么用?Python Session.add_all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Session的用法示例。


在下文中一共展示了Session.add_all方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: import_index_history_ohlcv

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import add_all [as 别名]
def import_index_history_ohlcv():
    indices = ['000001', '399001', '399006', '000016']
    for i in indices:
        datas = read_tdx_ohlcv('../data/index_history/%s.txt' % i)
        records = [
            IndexOhlcv(
                code=i,
                datetime=data[0],
                period='d',
                open=data[1],
                high=data[2],
                low=data[3],
                close=data[4],
                volume=data[5],
                amount=data[6]
            )
            for data in datas
        ]

        ss = Session()
        ss.add_all(records)
        ss.commit()
开发者ID:bluecover,项目名称:jettingrocket,代码行数:24,代码来源:tdx_ohlcv.py

示例2: get_quotes

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import add_all [as 别名]
def get_quotes(start, end, codes=None):
    sess = Session()
    criterion = Stock.status == 'L'
    if isinstance(codes, list):
        criterion = and_(criterion, Stock.code.in_(codes))
    stocks = sess.query(Stock).filter(criterion).all()

    for stock in stocks:
        try:
            begin_date = start if start else stock.listing_date
            end_date = end if end else date.today()
            payload = {
                'field': '',
                'beginDate': begin_date.strftime('%Y%m%d'),
                'endDate': end_date.strftime('%Y%m%d'),
                'secID': '',
                'ticker': stock.code,
                'tradeDate': ''
            }

            resp = requests.get(equd_adj_quote_history, headers=headers, params=payload)
            json_res = resp.json()
            if json_res['retCode'] != 1:
                logging.error('Request failed: [%s] %s' % (stock.code, json_res['retMsg']))
                continue

            quotes_data = json_res['data']
            quote_records = []
            for data in quotes_data:
                if not data['isOpen']:
                    continue

                adj_factor = data['accumAdjFactor']
                open = Decimal(data['openPrice'] / adj_factor).quantize(Decimal('.001'))
                close = Decimal(data['closePrice'] / adj_factor).quantize(Decimal('.001'))
                low = Decimal(data['lowestPrice'] / adj_factor).quantize(Decimal('.001'))
                high = Decimal(data['highestPrice'] / adj_factor).quantize(Decimal('.001'))
                pre_close = Decimal(data['actPreClosePrice']).quantize(Decimal('.001'))

                quote = Quote(
                    code=stock.code,
                    datetime=data['tradeDate'],
                    period='d1',
                    open=open,
                    close=close,
                    low=low,
                    high=high,
                    pre_close=pre_close,
                    change=close - pre_close,
                    percent=change_percent(close, pre_close),
                    volume=data['turnoverVol'],
                    amount=data['turnoverValue'],
                    turnover=data['turnoverRate'] * 100
                )

                quote_records.append(quote)

            sess.add_all(quote_records)
            sess.commit()

        except Exception as e:
            logging.error('Exception: [%s]' % stock.code)
            logging.error(e)
            continue
开发者ID:bluecover,项目名称:jettingrocket,代码行数:66,代码来源:quotes.py

示例3: date

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import add_all [as 别名]
        week_quotes.append(quote)

    return week_quotes


if __name__ == '__main__':
    start = date(2016, 6, 6)
    end = date(2016, 6, 8)

    ss = Session()

    securities = ss.query(Quote.code).distinct().all()

    for sec in securities:
        day_quotes = ss.query(Quote).filter(
            and_(
                Quote.code == sec.code,
                Quote.period == 'd1',
                Quote.datetime >= start,
                Quote.datetime <= end
            )
        ).order_by(Quote.datetime.asc()).all()

        if not day_quotes:
            continue

        week_quotes = create_week_quote(day_quotes)

        ss.add_all(week_quotes)
        ss.commit()
开发者ID:bluecover,项目名称:jettingrocket,代码行数:32,代码来源:merge_quotes.py

示例4: app

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import add_all [as 别名]
            if sess:
                db.delete(sess)
            self.response.delete_cookie("session_id")
            return { "message":"logged out" } 
        return { "message":"Not logged in" }

class app(WSGI):
    routes = [ 
        ('/home', Home()),
        ('/login', Login()),
        ('/logout', Logout())
    ]

if __name__ == "__main__":

    print("DB: Creating users table in memory...")    
    Base.metadata.create_all(engine)

    print("DB: Adding users...")
    db.add_all([
        User(username="foo", password="foo")
    ])

    from wsgiref.simple_server import make_server
    try:
        print("Serving on 0.0.0.0:8080...")
        make_server('0.0.0.0', 8080, app).serve_forever()
    except KeyboardInterrupt:
        pass
    print("Done")
开发者ID:Cesar0510,项目名称:pycnic,代码行数:32,代码来源:full-auth.py


注:本文中的models.Session.add_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。