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


Python Session.merge方法代码示例

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


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

示例1: create_this_week_quote

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import merge [as 别名]
def create_this_week_quote():
    if not is_trade_day(date.today()):
        return

    ss = Session()

    today = date.today()
    week_first_date = today - timedelta(days=today.weekday())

    securities = ss.query(Quote.code).distinct().all()
    for sec in securities:
        sec_quotes_of_this_week = ss.query(Quote).filter(
            and_(
                Quote.code == sec.code,
                Quote.datetime >= week_first_date,
                Quote.datetime <= today,
                Quote.period == 'd1'
            )
        ).all()

        if not sec_quotes_of_this_week:
            continue

        week_quote = merge_quotes(sec_quotes_of_this_week)
        week_quote.period = 'w1'
        ss.merge(week_quote)
        ss.commit()
开发者ID:bluecover,项目名称:jettingrocket,代码行数:29,代码来源:celery_cron.py

示例2: set_current_user

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import merge [as 别名]
 def set_current_user(self,user):
     self.update_user_data(user.token,"repeated-%s"%user.email.split("@")[0],user.tag_id)
     try:
         user.tag_id = self.tag_id
         session = Session()
         session.merge(current_user)
         session.commit()
     except:
         print "Unable to save Tag ID"
开发者ID:joranbeasley,项目名称:asana1,代码行数:11,代码来源:asana_helpers.py

示例3: pull_history_hq_of_index

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import merge [as 别名]
def pull_history_hq_of_index(index, start_date=None, end_date=None):
    if not start_date:
        start_date = index.listing_date
    hqs = ts.get_h_data(index.code, start=str(start_date), end=str(end_date),
                        index=True, autype='', pause=0.01)
    iterator = reversed(hqs.index)
    first_index = next(iterator)
    first_day_hq = hqs.loc[first_index]
    pre_close = first_day_hq['open']
    sess = Session()

    for timestamp in reversed(hqs.index):
        dt = timestamp.to_datetime()
        datetime_ = date(dt.year, dt.month, dt.day)
        row = hqs.loc[timestamp]

        open_price = row['open']
        close = row['close']
        low = row['low']
        high = row['high']
        volume = row['volume']
        amount = row['amount']
        change = close - pre_close
        change_pct = change_percent(close, pre_close)

        hq_day = Quote(
            code=index.code,
            datetime=datetime_,
            period='d1',
            open=open_price,
            close=close,
            low=low,
            high=high,
            pre_close=pre_close,
            change=change,
            percent=change_pct,
            volume=volume,
            amount=amount
        )

        sess.merge(hq_day)

        pre_close = close

        logging.info('[%s][%s]' %(str(index.code), str(datetime_)))

    sess.commit()
    logging.info(str(index.code) + ' db session commited')
开发者ID:bluecover,项目名称:jettingrocket,代码行数:50,代码来源:pull_index_hist_hq_from_tushare.py

示例4: response

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import merge [as 别名]
def response():
    if not current_user.is_anonymous():
        user_data = asana_api.exchange_token(current_user.refresh_token,"refresh_token")
        next = request.args.get("next","/")
    elif not request.args.get("code"):
        return redirect(constants.AUTH_ENDPOINT+"&state=%s"%request.args.get("next","/"))
    else:
        user_data = asana_api.exchange_token(request.args.get("code"),"code")
        print 'user data:',user_data
        next = request.args.get("state","/")
    s = Session()
    user = User.from_json(user_data)
    s.merge(user)
    login_user(user)
    s.commit()
    return redirect(next)
开发者ID:joranbeasley,项目名称:asana1,代码行数:18,代码来源:routes.py

示例5: __init__

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import merge [as 别名]
 def __init__(self,api_key,secret):
     self.api_key = api_key
     self.secret = secret
     if  current_user:
         self.token = current_user.token
         self.tag_name="repeated-%s"%current_user.email.split("@")[0]
         self.tag_id = self.get_tag(self.tag_name) if current_user.tag_id is None else current_user.tag_id
         try:
             current_user.tag_id = self.tag_id
             session = Session()
             session.merge(current_user)
             session.commit()
         except:
             print "xUnable to save Tag ID %rx"%(current_user,)
     else:
         self.token = None
开发者ID:joranbeasley,项目名称:asana1,代码行数:18,代码来源:asana_helpers.py

示例6: update_stock_profile

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import merge [as 别名]
def update_stock_profile(stock_codes):
    session = Session()
    failed_codes = []

    for code in stock_codes:
        try:
            stock = fetch_stock_profile(code)
            session.merge(stock)
            session.commit()
        except Exception as e:
            logging.warning('%s: %s' % (code, e))
            failed_codes.append(code)
            continue

    if failed_codes:
        sleep(60)
        update_stock_profile(failed_codes)
开发者ID:bluecover,项目名称:jettingrocket,代码行数:19,代码来源:pull_stock.py

示例7: index

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import merge [as 别名]
def index():
    index_codes = [
        '000001', '399102', '399006', '000300'
    ]
    for code in index_codes:
        market = util.index_market(code)
        hq = hq_last(market, code)

        now = datetime.now()
        this_date = date(now.year, now.month, now.day)
        this_minute = time(now.hour, now.minute, 0)

        change = hq['price'] - hq['pre_close']
        change_pct = change_percent(hq['price'], hq['pre_close'])

        snapshot = HQSnapshot(
            market=market,
            code=code,
            name=hq['name'],
            date=this_date,
            time=this_minute,
            price=hq['price'],
            pre_close=hq['pre_close'],
            open=hq['open'],
            low=hq['low'],
            high=hq['high'],
            change=change,
            percent=change_pct,
            volume=hq['volume'],
            money=hq['volume_money']
        )

        session = Session()
        session.merge(snapshot)
        session.commit()

        print 'sync: ', code

    return 'ok'
开发者ID:bluecover,项目名称:jettingrocket,代码行数:41,代码来源:manage.py

示例8: pull_close_quote

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import merge [as 别名]
def pull_close_quote():
    if not is_trade_day(date.today()):
        return

    ss = Session()
    for index in ss.query(HSIndex).all():
        quote = pull_last_quote(index, True)
        if quote:
            ss.merge(quote)
            ss.commit()

    updated = ss.query(Quote.code).filter(Quote.datetime >= date.today()).distinct().subquery()
    to_update = ss.query(Stock).filter(
        not_(
            Stock.code.in_(updated)
        )
    ).distinct().all()

    for stock in to_update:
        quote = pull_last_quote(stock, False)
        if quote:
            ss.add(quote)
            ss.commit()
开发者ID:bluecover,项目名称:jettingrocket,代码行数:25,代码来源:celery_cron.py

示例9: pull_history_quotes

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import merge [as 别名]
def pull_history_quotes(security, is_index, start_date=None, end_date=None):
    if not start_date or start_date < security.listing_date:
        start_date = security.listing_date

    try:
        quotes_df = ts.get_h_data(security.code, start=str(start_date), end=str(end_date), index=is_index, pause=0.01)
    except:
        logging.error('Pull tushare history quotes failed.')
        return

    index_riter = reversed(quotes_df.index)
    first = next(index_riter)
    first_hq = quotes_df.loc[first]
    pre_close = first_hq['open']
    sess = Session()

    for timestamp in reversed(quotes_df.index):
        dt = timestamp.to_datetime()
        datetime_ = date(dt.year, dt.month, dt.day)

        row = quotes_df.loc[timestamp]

        open = row['open']
        high = row['high']
        low = row['low']
        close = row['close']
        volume = row['volume']
        amount = row['amount']

        change = close - pre_close
        change_pct = change_percent(close, pre_close)

        '''
        turnover = None
        if security.tradable_shares != 0:
            turnover = volume / security.tradable_shares * 100
        '''

        quote = Quote(
            code=security.code,
            datetime=datetime_,
            period='d1',
            open=open,
            close=close,
            low=low,
            high=high,
            pre_close=pre_close,
            change=change,
            percent=change_pct,
            volume=volume,
            amount=amount
        )

        sess.merge(quote)
        pre_close = close

    try:
        sess.commit()
        logging.info(str(security.code) + ' db session commited')
    except:
        logging.error('Session commit failed.')
        return
开发者ID:bluecover,项目名称:jettingrocket,代码行数:64,代码来源:pull_stock_hist_hq_from_tushare.py


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