Example #1
0
    def expand_dates(self, start, end):
        """
        Given start and end dates (strings with format like "Sep 1, 2013"),
        returns a list of date objects covering that range.
        """
        start_date = common.str_to_date(start)
        end_date = common.str_to_date(end)

        result = []
        num_days = (end_date - start_date).days + 1
        for i in range(num_days):
            delta = datetime.timedelta(days=i)
            result.append(start_date + delta)

        return result
Example #2
0
def stock_industry_day():
    """
    根据同花顺得到板块数据分析
    http://q.10jqka.com.cn/stock/thshy/
    http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/1/quote/quote
    """
    urls = (
        'http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/1/quote/quote',
        'http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/2/quote/quote')
    for url in urls:
        content = httpGetContent(url)
        if content:
            json_stock = json.loads(content)
            industry_list = json_stock["data"]

            for industry in industry_list:
                industry_dict = {}
                industry_dict["date"] = str_to_date(json_stock["rtime"][:10],
                                                    "%Y-%m-%d")
                industry_dict["name"] = industry["platename"]
                industry_dict["industry_code"] = industry["platecode"]
                industry_dict["price"] = float(industry["zxj"])  # 最近价格
                industry_dict["volume"] = float(industry["cjl"])  # 总成交量多少万手
                industry_dict["total"] = float(industry["cje"])  # 总成交额多少亿元数据
                industry_dict["rise_percent"] = float(industry["zdf"])  # 涨跌幅
                industry_dict["rise_price"] = float(
                    industry["zde"])  # 涨跌额度(价格)
                industry_dict["net_inflow"] = float(
                    industry["jlr"])  # 净流入(亿元数据)
                yield industry_dict
Example #3
0
    def get_pto_by_person(self, out_lines):
        """
        Constructs list of PTO dates by person.

        This excludes company holidays and weekends. Duplicate dates are also
        removed.
        """
        # Gather "out" dates by person
        result = {}
        for l in out_lines.split("\n"):
            [person, vac_type, dates] = l.split("\t")
            if person not in result:
                result[person] = []

            if vac_type == "out":
                for d in dates.split(":"):
                    result[person].append(common.str_to_date(d))

        # Note holidays
        holidays = {}
        if "All" in result:
            for d in result["All"]:
                holidays[d] = True
            del result["All"]

        # Filter out holidays and weekends
        for p in result:
            new_values = []
            for d in result[p]:
                if d in holidays or common.is_weekend(d):
                    continue
                new_values.append(d)
            result[p] = list(set(new_values))
        return result
Example #4
0
def stock_industry_day():
    """
    根据同花顺得到板块数据分析
    http://q.10jqka.com.cn/stock/thshy/
    http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/1/quote/quote
    """
    urls = ('http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/1/quote/quote',
            'http://q.10jqka.com.cn/interface/stock/thshy/zdf/desc/2/quote/quote')
    for url in urls:
        content = httpGetContent(url)
        if content:
            json_stock = json.loads(content)
            industry_list = json_stock["data"]

            for industry in industry_list:
                industry_dict = {}
                industry_dict["date"] = str_to_date( json_stock["rtime"][:10],"%Y-%m-%d")
                industry_dict["name"] = industry["platename"]
                industry_dict["industry_code"] = industry["platecode"]
                industry_dict["price"] = float(industry["zxj"])        # 最近价格
                industry_dict["volume"] = float(industry["cjl"])       # 总成交量多少万手
                industry_dict["total"] = float(industry["cje"])        # 总成交额多少亿元数据
                industry_dict["rise_percent"] = float(industry["zdf"]) # 涨跌幅
                industry_dict["rise_price"] = float(industry["zde"])   # 涨跌额度(价格)
                industry_dict["net_inflow"] = float(industry["jlr"])   # 净流入(亿元数据)
                yield industry_dict
Example #5
0
def stock_finical_quarter(code):
    """
    通过同花顺行业数据得到数据报告信息。
    指标\日期	  基本每股收益	摊薄每股收益	每股净资产	每股现金流	每股未分配利润	每股公积金	主营收入	 利润总额	     净利润	 净资产收益率	销售毛利率	主营收入同比增长率	净利润同比增长率
    2013-3-31	0.04	      0.04	       5.33	      -0.68	       2.66	          1.37	    425230.9 37821.37	18722.95	0.79	26.43	143.93	19.68
    http://basic.10jqka.com.cn/600383/xls/Important_declaredate.xls"
    """
    url = "http://basic.10jqka.com.cn/%s/xls/Important_declaredate.xls" % (
        code)
    content = httpGetContent(url)
    stock_dict = {}
    if content:
        content = content.decode('gb2312').encode('utf8')
        data = cStringIO.StringIO(content)
        for i, line in enumerate(data):
            if i == 1:
                item = line.strip('\n').split('\t')
                date = str_to_date(item[0], "%Y-%m-%d")  # 日期
                earnings = decimal(item[2])  # 摊薄每股收益(数据相对准确)不以基本每股收益为准 0.04
                net_asset_value = decimal(item[3])  # 每股净资产 5.33
                cash_flow = decimal(item[4])  # 每股现金流 -0.86
                profit_per_share = decimal(item[5])  # 每股未分配利润
                capital_fund = decimal(item[6])  # 每股公积金
                main_income = decimal(item[7])  # 主营业收入
                total_profit = decimal(item[8])  # 利润总额
                total_net_profit = decimal(item[9])  # 净利润
                return_on_asserts = decimal(item[10])  # 净资产收益率 0.79%
                income_rise = decimal(item[12])  # 主营业收入同比增长率 143.93%
                net_profit_rise = decimal(item[13])  # 净利润同比增长率 19.68%
                stock_dict = {
                    "code": code,
                    "date": date,
                    "earnings": earnings,
                    "net_asset_value": net_asset_value,
                    "cash_flow": cash_flow,
                    "return_on_asserts": return_on_asserts,
                    "income_rise": income_rise,
                    "net_profit_rise": net_profit_rise,
                    "profit_per_share": profit_per_share,
                    "capital_fund": capital_fund,
                    "main_income": main_income,
                    "total_profit": total_profit,
                    "total_net_profit": total_net_profit
                }
                break
    return stock_dict
Example #6
0
def stock_finical_quarter(code):
    """
    通过同花顺行业数据得到数据报告信息。
    指标\日期	  基本每股收益	摊薄每股收益	每股净资产	每股现金流	每股未分配利润	每股公积金	主营收入	 利润总额	     净利润	 净资产收益率	销售毛利率	主营收入同比增长率	净利润同比增长率
    2013-3-31	0.04	      0.04	       5.33	      -0.68	       2.66	          1.37	    425230.9 37821.37	18722.95	0.79	26.43	143.93	19.68
    http://basic.10jqka.com.cn/600383/xls/Important_declaredate.xls"
    """
    url = "http://basic.10jqka.com.cn/%s/xls/Important_declaredate.xls" % (code)
    content = httpGetContent(url)
    stock_dict = {}
    if content:
        content = content.decode('gb2312').encode('utf8')
        data = cStringIO.StringIO(content)
        for i, line in enumerate(data):
            if i == 1:
                item = line.strip('\n').split('\t')
                date = str_to_date(item[0], "%Y-%m-%d")   # 日期
                earnings = decimal(item[2])               # 摊薄每股收益(数据相对准确)不以基本每股收益为准 0.04
                net_asset_value = decimal(item[3])        # 每股净资产 5.33
                cash_flow = decimal(item[4])              # 每股现金流 -0.86
                profit_per_share = decimal(item[5])       # 每股未分配利润
                capital_fund = decimal(item[6])           # 每股公积金
                main_income = decimal(item[7])            # 主营业收入
                total_profit = decimal(item[8])           # 利润总额
                total_net_profit = decimal(item[9])       # 净利润
                return_on_asserts = decimal(item[10])     # 净资产收益率 0.79%
                income_rise = decimal(item[12])           # 主营业收入同比增长率 143.93%
                net_profit_rise = decimal(item[13])       # 净利润同比增长率 19.68%
                stock_dict = {
                    "code": code,
                    "date": date,
                    "earnings": earnings,
                    "net_asset_value": net_asset_value,
                    "cash_flow": cash_flow,
                    "return_on_asserts": return_on_asserts,
                    "income_rise": income_rise,
                    "net_profit_rise": net_profit_rise,
                    "profit_per_share": profit_per_share,
                    "capital_fund": capital_fund,
                    "main_income": main_income,
                    "total_profit": total_profit,
                    "total_net_profit": total_net_profit
                }
                break
    return stock_dict
Example #7
0
def stock_finical_post():
    """抓取同花顺业绩公告板块
    http://data.10jqka.com.cn/financial/yjgg/
    http://data.10jqka.com.cn/financial/yjgg/page/56/ajax/1/
    """
    headers = {
        "Host": "data.10jqka.com.cn",
        "Referer": "http://data.10jqka.com.cn/financial/yjyg/",
        "X-Requested-With": "XMLHttpRequest"
    }
    count = range(1, 60)
    urls = [
        "http://data.10jqka.com.cn/financial/yjgg/page/%s/ajax/1/" % num
        for num in count
    ]
    for url in urls:
        content = httpGetContent(url, headers, "gb2312")
        if content:
            soup = BeautifulSoup(content)
            stock_item = soup.select("tbody > tr")
            for item in stock_item:
                tds = item.select('td')
                stock_dict = {}
                for i, td in enumerate(tds):
                    if i == 1:  # 代码
                        stock_dict["code"] = td.select('a')[0].string
                    elif i == 3:  # 日期
                        stock_dict["date"] = str_to_date(td.string, "%Y-%m-%d")
                    elif i == 4:  # 每股收益
                        stock_dict["earnings"] = decimal(td.string)
                    elif i == 5:  # 营业收入
                        stock_dict["main_income"] = decimal(td.string)
                    elif i == 6:  # 营业收入同比增长%
                        stock_dict["income_rise"] = validate_decimal(td.string)
                    elif i == 7:  # 净利润 万元
                        stock_dict["net_profit"] = decimal(td.string)
                    elif i == 8:  #净利润同比增长%
                        stock_dict["net_profit_rise"] = validate_decimal(
                            td.string)
                yield stock_dict
Example #8
0
def stock_finical_post():
    """抓取同花顺业绩公告板块
    http://data.10jqka.com.cn/financial/yjgg/
    http://data.10jqka.com.cn/financial/yjgg/page/56/ajax/1/
    """
    headers = {
        "Host": "data.10jqka.com.cn",
        "Referer": "http://data.10jqka.com.cn/financial/yjyg/",
        "X-Requested-With": "XMLHttpRequest"
    }
    count = range(1, 60)
    urls = ["http://data.10jqka.com.cn/financial/yjgg/page/%s/ajax/1/" % num for num in count]
    for url in urls:
        content = httpGetContent(url, headers, "gb2312")
        if content:
            soup = BeautifulSoup(content)
            stock_item = soup.select("tbody > tr")
            for item in stock_item:
                tds = item.select('td')
                stock_dict = {}
                for i, td in enumerate(tds):
                    if i == 1:   # 代码
                        stock_dict["code"] = td.select('a')[0].string
                    elif i == 3: # 日期
                        stock_dict["date"] = str_to_date(td.string, "%Y-%m-%d")
                    elif i == 4: # 每股收益
                        stock_dict["earnings"] = decimal(td.string)
                    elif i == 5: # 营业收入
                        stock_dict["main_income"] = decimal(td.string)
                    elif i == 6: # 营业收入同比增长%
                        stock_dict["income_rise"] = validate_decimal(td.string)
                    elif i == 7: # 净利润 万元
                        stock_dict["net_profit"] = decimal(td.string)
                    elif i == 8: #净利润同比增长%
                        stock_dict["net_profit_rise"] = validate_decimal(td.string)
                yield stock_dict