예제 #1
0
    def __change_table_1(self):
        table_1 = self.doc.tables[0]

        stocks_a = ['sh601992', 'sz000401', 'sz000856', 'sh600585', 'sz000002']
        var = -1
        for row in table_1.rows:
            cell = row.cells
            if var == -1:
                var = 0
                continue
            cell[0].text = ''
            cell[1].text = ''  # CNY
            cell[2].text = ''
            cell[3].text = ''
            cell[4].text = ''
            cell[5].text = ''
            cell[6].text = ''
            cell[7].text = ''

            run = cell[0].paragraphs[0].add_run(
                self.result['company'][stocks_a[var]]['stockName'])
            run.font.size = Pt(12)

            run = cell[1].paragraphs[0].add_run('CNY')
            run.font.size = Pt(12)

            run = cell[2].paragraphs[0].add_run(
                remaindecimal(
                    self.result['company'][stocks_a[var]]['currentPrice']))
            run.font.size = Pt(12)
            run.font.color.rgb = self.__get_font_color(
                float(self.result['company'][stocks_a[var]]['changeAmount']))

            run = cell[3].paragraphs[0].add_run(
                remaindecimal(
                    self.result['company'][stocks_a[var]]['changeAmount'],
                    symbol=1))
            run.font.size = Pt(12)
            run.font.color.rgb = self.__get_font_color(
                float(self.result['company'][stocks_a[var]]['changeAmount']))

            run = cell[4].paragraphs[0].add_run(
                remaindecimal(self.result['company'][stocks_a[var]]
                              ['priceChangeRatio'],
                              symbol=1) + '%')
            run.font.size = Pt(12)
            run.font.color.rgb = self.__get_font_color(
                float(self.result['company'][stocks_a[var]]['changeAmount']))

            run = cell[5].paragraphs[0].add_run(
                remaindecimal(
                    str(
                        float(self.result['company'][stocks_a[var]]['amount'])
                        / 100000000)))
            run.font.size = Pt(12)

            var = var + 1
예제 #2
0
    def __change_szcz(self):  # 深证成指 p = 4
        par = self.pars[4]
        par.text = ''
        run = par.add_run('深证成指收  ')
        run.font.size = Pt(14)
        run.font.bold = True

        run = par.add_run(
            '%s, %s, %s%%' %
            (remaindecimal(self.result['szcz']['nowpri']),
             remaindecimal(self.result['szcz']['increase'], symbol=1),
             remaindecimal(self.result['szcz']['increPer'], symbol=1)))
        run.font.size = Pt(14)
        run.font.bold = True
        run.font.color.rgb = self.__get_font_color(
            float(self.result['szcz']['increase']))
예제 #3
0
    def __change_hszs(self):  # 恒生指数 p = 6
        par = self.pars[6]
        par.text = ''
        run = par.add_run('恒生指数收  ')
        run.font.size = Pt(14)
        run.font.bold = True

        run = par.add_run(
            '%s, %s, %s%%' %
            (remaindecimal(self.result['hszs']['nowpri']),
             remaindecimal(self.result['hszs']['increase'], symbol=1),
             remaindecimal(self.result['hszs']['increPer'], symbol=1)))
        run.font.size = Pt(14)
        run.font.bold = True
        run.font.color.rgb = self.__get_font_color(
            float(self.result['hszs']['increase']))
예제 #4
0
파일: other.py 프로젝트: jiangbiaoah/Stocks
    def export(self, text):
        result = json.loads(text)
        doc = Document()
        doc.styles['Normal'].font.name = u'宋体'
        doc.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'), u'Times New Roman')
        doc.styles['Normal'].font.size = Pt(12)

        current = datetime.datetime.now()

        p00 = doc.add_paragraph()
        p00.alignment = WD_ALIGN_PARAGRAPH.CENTER
        run = p00.add_run("%s年%s月%s日" % (current.year, current.month, current.day) + '\n' + "公司及同业公司股价表现")
        run.font.size = Pt(16)
        run.font.bold = False
        run.font.color.rgb = RGBColor(0, 0, 0)

        p1 = doc.add_paragraph()
        run = p1.add_run("(一)A股")
        run.font.size = Pt(16)

        p11 = doc.add_paragraph()
        run = p11.add_run("上证指数收  ")
        run.font.size = Pt(14)
        run.font.bold = True
        run = p11.add_run("%s, %s, %s%%" % (remaindecimal(result['szzs']['nowpri']), remaindecimal(result['szzs']['increase']), remaindecimal(result['szzs']['increPer'])))
        run.font.size = Pt(14)
        run.font.bold = True
        run.font.color.rgb = getFontColor(float(result['szzs']['increase']))

        p12 = doc.add_paragraph()
        run = p12.add_run("深证成指收  ")
        run.font.size = Pt(14)
        run.font.bold = True
        run = p12.add_run("%s, %s, %s%%" % (remaindecimal(result['szcz']['nowpri']), remaindecimal(result['szcz']['increase']), remaindecimal(result['szcz']['increPer'])))
        run.font.size = Pt(14)
        run.font.bold = True
        run.font.color.rgb = getFontColor(float(result['szcz']['increase']))

        table1 = doc.add_table(rows=6, cols=8, style="Light List Accent 2")
        cells1_0 = table1.rows[0].cells
        cells1_0[0].text = '公司'
        cells1_0[1].text = '货币'
        cells1_0[2].text = '今日收市价'
        cells1_0[3].text = '相比前一交易日'
        cells1_0[4].text = '涨跌幅度'
        cells1_0[5].text = '成交金额'
        cells1_0[6].text = '换手率'
        cells1_0[7].text = '总市值(亿元)'
        # stocks_a = ['H02009', 'H00914', 'H03323', 'H01313', 'H00688']
        stocks_a = ['金隅集团', ['冀东水泥'], ['冀东装备'], ['海螺水泥'], ['万科A']]
        i = 1
        for stock in stocks_a:
            table1.rows[i].cells[0].text = stock
            table1.rows[i].cells[1].text = 'CNY'
            table1.rows[i].cells[2].text = ''
            table1.rows[i].cells[3].text = ''
            table1.rows[i].cells[4].text = ''
            table1.rows[i].cells[5].text = ''
            table1.rows[i].cells[6].text = ''
            table1.rows[i].cells[7].text = ''
            i = i + 1

        p2 = doc.add_paragraph()
        run = p2.add_run("(二)H股")
        run.font.size = Pt(16)

        p21 = doc.add_paragraph()
        run = p21.add_run("恒生指数收  ")
        run.font.size = Pt(14)
        run.font.bold = True
        run = p21.add_run("%s, %s, %s%%" % (remaindecimal(result['hszs']['nowpri']), remaindecimal(result['hszs']['increase']), remaindecimal(result['hszs']['increPer'])))
        run.font.size = Pt(14)
        run.font.bold = True
        run.font.color.rgb = getFontColor(float(result['hszs']['increase']))

        table2 = doc.add_table(rows=6, cols=6, style="Light List Accent 2")
        table2.alignment = WD_TABLE_ALIGNMENT.CENTER
        cells2_0 = table2.rows[0].cells
        cells2_0[0].text = '公司'
        cells2_0[1].text = '货币'
        cells2_0[2].text = '今日收市价'
        cells2_0[3].text = '相比前一交易日'
        cells2_0[4].text = '涨跌幅度'
        cells2_0[5].text = '成交金额'

        stocks_hk = ['H02009', 'H00914', 'H03323', 'H01313', 'H00688']
        j = 1
        for stock in stocks_hk:
            table2.rows[j].cells[0].text = result['company'][stock]['stockName']
            table2.rows[j].cells[1].text = 'HKD'
            # table2.rows[j].cells[2].text = remaindecimal(result['company'][stock]['currentPrice'])
            # table2.rows[j].cells[3].text = remaindecimal(result['company'][stock]['changeAmount'])
            # table2.rows[j].cells[4].text = result['company'][stock]['priceChangeRatio']
            table2.rows[j].cells[5].text = result['company'][stock]['amount']

            run = table2.cell(j, 2).paragraphs[0].add_run(remaindecimal(result['company'][stock]['currentPrice']))
            run.font.color.rgb = getFontColor(float(result['company'][stock]['changeAmount']))
            run = table2.cell(j, 3).paragraphs[0].add_run(remaindecimal(result['company'][stock]['changeAmount']))
            run.font.color.rgb = getFontColor(float(result['company'][stock]['changeAmount']))
            run = table2.cell(j, 4).paragraphs[0].add_run(result['company'][stock]['priceChangeRatio'])
            run.font.color.rgb = getFontColor(float(result['company'][stock]['changeAmount']))

            j = j + 1

        doc.save('A股公司及同业公司股价表现-%s%s%s%s%s%s.docx' % (current.year, current.month, current.day, current.hour, current.minute, current.second))
        print("文档输出完成")
예제 #5
0
    def __change_table_2(self):
        table_2 = self.doc.tables[1]

        stocks_hk = ['H02009', 'H00914', 'H03323', 'H01313', 'H00688']
        var = -1
        for row in table_2.rows:
            cell = row.cells
            if var == -1:
                var = 0
                continue
            # for stock in stocks_hk:
            cell[0].text = ''
            cell[1].text = ''
            cell[2].text = ''
            cell[3].text = ''
            cell[4].text = ''
            cell[5].text = ''

            run = cell[0].paragraphs[0].add_run(
                self.result['company'][stocks_hk[var]]['stockName'])
            run.font.size = Pt(12)

            run = cell[1].paragraphs[0].add_run('HKD')
            run.font.size = Pt(12)

            run = cell[2].paragraphs[0].add_run(
                remaindecimal(
                    self.result['company'][stocks_hk[var]]['currentPrice']))
            run.font.size = Pt(12)
            run.font.color.rgb = self.__get_font_color(
                float(self.result['company'][stocks_hk[var]]['changeAmount']))

            run = cell[3].paragraphs[0].add_run(
                remaindecimal(
                    self.result['company'][stocks_hk[var]]['changeAmount'],
                    symbol=1))
            run.font.size = Pt(12)
            run.font.color.rgb = self.__get_font_color(
                float(self.result['company'][stocks_hk[var]]['changeAmount']))

            run = cell[4].paragraphs[0].add_run(
                self.result['company'][stocks_hk[var]]['priceChangeRatio'])
            run.font.size = Pt(12)
            run.font.color.rgb = self.__get_font_color(
                float(self.result['company'][stocks_hk[var]]['changeAmount']))

            amount = self.result['company'][stocks_hk[var]]['amount']
            # pattern = re.compile(r'\d+')
            # code = pattern.findall(amount)[0]
            number = None
            if amount.find(u'万') != -1:
                index = amount.find(u'万')
                number = amount[0:index]
                number = remaindecimal(str(float(number) / 10000))
            else:
                index = amount.find(u'亿')
                number = amount[0:index]
                number = remaindecimal(number)

            run = cell[5].paragraphs[0].add_run(number)
            run.font.size = Pt(12)

            var = var + 1