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


Python Stock.name方法代码示例

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


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

示例1: stock_add

# 需要导入模块: from models import Stock [as 别名]
# 或者: from models.Stock import name [as 别名]
def stock_add(request):
    from app.remote.stocks import StockHistoryClient
    from app.forms import StockWizardForm
    from app.models import Company, Stock

    if request.method == "POST":
        form = StockWizardForm(request.POST)
        pprint(form.is_valid())
        if form.is_valid():
            # save
            company = Company()
            company.name = form.cleaned_data['company_name']
            company.country = form.cleaned_data['company_country']
            company.save()

            stock = Stock()
            stock.company = company
            stock.name = form.cleaned_data['name']
            stock.wkn = form.cleaned_data['wkn']
            stock.isin = form.cleaned_data['isin']
            stock.symbol = form.cleaned_data['symbol']
            stock.type = form.cleaned_data['type']
            stock.default_stock_exchange = form.cleaned_data['default_stock_exchange']
            stock.save()

            return HttpResponseRedirect(reverse('stock', args=(stock.symbol,)))
        else:
            pprint(form.errors)
    else:
        data = None
        if 'wkn_or_isin' in request.GET:
            shc = StockHistoryClient()
            data = shc.get_basics_by_wkn_or_isin(wkn_or_isin=request.GET['wkn_or_isin'])

            data['company_country'] = data['country']
            data['company_name'] = data['name']

        form = StockWizardForm(initial=data)

    return render_to_response(
        'stock_wizard_add.html',
        {
            'form': form
        },
        context_instance=RequestContext(request)
    )
开发者ID:mrcrgl,项目名称:stockstore,代码行数:48,代码来源:views.py

示例2: fetch_stock_profile

# 需要导入模块: from models import Stock [as 别名]
# 或者: from models.Stock import name [as 别名]
def fetch_stock_profile(stock_code):
    market = 'sh' if stock_code.startswith('6') else 'sz'
    url = stock_page_url.format(market=market, stock_code=stock_code)
    resp = requests.get(url)
    soup = BeautifulSoup(resp.content.decode('gbk'))

    name_elem = soup.find('h2', id='name')
    stock_name = name_elem.text if name_elem else None

    # last_price = soup.find('strong', id='price9').text

    status = 'L'
    '''
        上市状态
            上市: L
            退市: DE
        dead_status = [u'已退市', u'终止上市']
        stop_status = [u'暂停上市']
        if stock_name in dead_status:
            status = 'DE'
        elif stock_name in stop_status:
            status = 'S'
    '''

    texts = []
    trs = soup.find('table', id='rtp2').find('tbody').find_all('tr')
    for tr in trs:
        tds = tr.find_all('td')
        for td in tds:
            texts.append(td.text.split(u':'))

    datas = {_[0]: _[1] for _ in texts}

    eps = value_or_zero(datas.get(u'收益(一)'), Decimal)
    if eps == 0:
        eps = value_or_zero(datas.get(u'收益(二)'), Decimal)
    if eps == 0:
        eps = value_or_zero(datas.get(u'收益(三)'), Decimal)

    pe = value_or_zero(datas.get(u'PE(动)'), Decimal)
    asset_value_per_share = value_or_zero(datas.get(u'净资产'), Decimal)
    pb = value_or_zero(datas.get(u'净利率'), cn_text_to_number)
    revenue = value_or_zero(datas.get(u'总收入'), cn_text_to_int)
    revenue_growth = value_or_zero(texts[5][1], cn_text_to_number)
    net_profit = value_or_zero(datas.get(u'净利润'), cn_text_to_number)
    net_profit_growth = value_or_zero(texts[7][1], cn_text_to_number)
    roe = value_or_zero(datas.get(u'ROE'), cn_text_to_number)
    outstanding_shares = value_or_zero(datas.get(u'总股本'), cn_text_to_int)
    tradable_shares = value_or_zero(datas.get(u'流通股'), cn_text_to_int)
    market_value = value_or_zero(datas.get(u'总值'), cn_text_to_number)
    circulating_value = value_or_zero(datas.get(u'流值'), cn_text_to_number)
    retained_earnings_per_share = value_or_zero(datas.get(u'每股未分配利润'), cn_text_to_number)
    debt_ratio = value_or_zero(datas.get(u'负债率'), cn_text_to_number)
    listing_date_str = value_or_zero(datas.get(u'上市时间'), str, zero='-')
    gross_profit_margin = value_or_zero(datas.get(u'毛利率'), cn_text_to_number)
    if listing_date_str != '-':
        listing_date = datetime.strptime(listing_date_str, '%Y-%m-%d').date()
    else:
        listing_date = '-'

    stock = Stock(
        market=market,
        code=stock_code,
        status=status,
        listing_date=listing_date,
        outstanding_shares=outstanding_shares,
        tradable_shares=tradable_shares,
        market_value=market_value,
        circulating_value=circulating_value,
        revenue=revenue,
        revenue_growth=revenue_growth,
        net_profit=net_profit,
        net_profit_growth=net_profit_growth,
        asset_value_per_share=asset_value_per_share,
        retained_earnings_per_share=retained_earnings_per_share,
        debt_ratio=debt_ratio,
        gross_profit_margin=gross_profit_margin,
        pe=pe,
        pb=pb,
        eps=eps,
        roe=roe,
        update_time=datetime.now())

    if stock_name:
        stock.name = stock_name

    return stock
开发者ID:bluecover,项目名称:jettingrocket,代码行数:89,代码来源:stock_profile.py


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