Example #1
0
    def output(self, term):
        '''output current courses
        :param term: term, for example: 19
        '''
        import functools
        from rich.console import Console
        from rich.table import Table

        console = Console()
        table = Table(title=f'20{term} 我的课程')

        myCourses = self.aoxiang.myCourses(term)
        # header:
        #     0      1          2           3      4      5     6      7         8       9          10        11       12
        #   序号 ┃ 课程序号 ┃ 课程代码 ┃ 课程名称 ┃ 教师 ┃ 学分 ┃ 校区 ┃ 课程安排 ┃ 起止周 ┃ 课程介绍 ┃ 教学大纲 ┃ 考试类型 ┃ 操作
        header = list(map(lambda x: x[0], myCourses[0].items()))
        # only pick up [3, 5, ..]
        header = functools.reduce(lambda zero, x: zero + [header[x]],
                                  [3, 5, 6, 7, 8, 9, 11], [])

        for h in header:
            table.add_column(h)
        for course in myCourses:
            table.add_row(*[course[h] for h in header])

        table.row_styles = ['none', 'dim']

        console.print(table)
Example #2
0
    def output(self, *terms):
        '''
        :param terms: terms to get grade
        '''
        from rich.console import Console
        from rich.table import Table

        grades = self.aoxiang.grade(*terms)

        console = Console()

        # grade: [{head: value, head: value}, {...}]
        for grade in grades:
            # grade: [([head], [value]), (...)]
            grade = list(map(lambda x: list(zip(*x.items())), grade))
            # header:
            #   学年学期 ┃ 课程代码 ┃ 课程序号 ┃ 课程名称 ┃ 课程类别 ┃ 学分 ┃ 平时成绩 ┃ 期中成绩 ┃ 实验成绩 ┃ 期末成绩 ┃ 总评成绩 ┃ 最终 ┃ 绩点
            header = grade[0][0]
            title = grade[0][1][0] if terms else 'All Terms'
            grade = list(sorted(map(lambda x: x[1][3:], grade), reverse=True))

            table = Table(title=title, width=120)
            for h in header[3:]:
                table.add_column(h.replace('成绩', ''))
            for g in grade:
                table.add_row(*g)
            table.row_styles = ['none', 'dim']

            console.print(table)
Example #3
0
def getContacts(client):
    data = client.listFriends()
    table = Table(show_footer=False)
    table.add_column("Name", no_wrap=True)
    table.add_column("JID", no_wrap=True)
    table.add_column("Subscription", no_wrap=True)
    table.add_column("Status", no_wrap=True)
    table.add_column("Extra", no_wrap=True)
    table.title = (
        "[not italic]:girl_light_skin_tone: Users In Rooster [not italic]:boy_light_skin_tone:"
    )
    for row in data:
        table.add_row(*row)

    table.columns[4].header_style = "bold red"
    table.columns[3].header_style = "bold green"
    table.columns[2].header_style = "bold blue"
    table.columns[1].header_style = "red"
    table.columns[0].header_style = "cyan"
    table.row_styles = ["none", "dim"]
    table.border_style = "bright_yellow"
    for x in [
            box.SQUARE,
            box.MINIMAL,
            box.SIMPLE,
            box.SIMPLE_HEAD,
    ]:
        table.box = x
    console.print(table, justify="left")
Example #4
0
def getInfoUser(client):
    questions = [{
        'type': 'input',
        'message': 'Enter username to get info',
        'name': 'username'
    }]
    answers = prompt(questions, style=custom_style_2)
    data = client.getUserInfo(answers['username'])
    table = Table(show_footer=False)
    table.add_column("Email", no_wrap=True)
    table.add_column("JID", no_wrap=True)
    table.add_column("Username", no_wrap=True)
    table.add_column("Name", no_wrap=True)
    table.title = (
        "[not italic]:girl_light_skin_tone: Username Information [not italic]:boy_light_skin_tone:"
    )
    for row in data:
        table.add_row(*row)

    table.columns[3].header_style = "bold red"
    table.columns[2].header_style = "bold green"
    table.columns[1].header_style = "bold blue"
    table.columns[0].header_style = "cyan"
    table.row_styles = ["none", "dim"]
    table.border_style = "bright_yellow"
    for x in [
            box.SQUARE,
            box.MINIMAL,
            box.SIMPLE,
            box.SIMPLE_HEAD,
    ]:
        table.box = x
    console.print(table, justify="left")
Example #5
0
def render_tables():
    console = Console(
        width=60,
        force_terminal=True,
        file=io.StringIO(),
        legacy_windows=False,
        color_system=None,
    )

    table = Table(title="test table", caption="table caption", expand=True)
    table.add_column("foo",
                     footer=Text("total"),
                     no_wrap=True,
                     overflow="ellipsis")
    table.add_column("bar", justify="center")
    table.add_column("baz", justify="right")

    table.add_row("Averlongwordgoeshere", "banana pancakes", None)

    assert Measurement.get(console, table, 80) == Measurement(41, 48)

    for width in range(10, 60, 5):
        console.print(table, width=width)

    table.expand = False
    console.print(table, justify="left")
    console.print(table, justify="center")
    console.print(table, justify="right")

    assert table.row_count == 1

    table.row_styles = ["red", "yellow"]
    table.add_row("Coffee")
    table.add_row("Coffee", "Chocolate", None, "cinnamon")

    assert table.row_count == 3

    console.print(table)

    table.show_lines = True
    console.print(table)

    table.show_footer = True
    console.print(table)

    table.show_edge = False

    console.print(table)

    table.padding = 1
    console.print(table)

    table.width = 20
    assert Measurement.get(console, table, 80) == Measurement(20, 20)
    console.print(table)

    return console.file.getvalue()
Example #6
0
    def output(self, *terms):
        '''
        :param terms: terms to get grade
        '''
        from rich.console import Console
        from rich.table import Table
        from rich.markdown import Markdown

        grades = self.aoxiang.grade(*terms)
        grade_sum = 0
        score_sum = 0

        gpa_exclude = []

        console = Console()

        def is_number(num):
            import re
            pattern = re.compile(r'^[-+]?[-0-9]\d*\.\d*|[-+]?\.?[0-9]\d*$')
            return bool(pattern.match(num))

        # grade: [{head: value, head: value}, {...}]
        for grade in grades:
            # grade: [([head], [value]), (...)]
            grade = list(map(lambda x: list(zip(*x.items())), grade))
            # header:
            #   学年学期 ┃ 课程代码 ┃ 课程序号 ┃ 课程名称 ┃ 课程类别 ┃ 学分 ┃ 平时成绩 ┃ 期中成绩 ┃ 实验成绩 ┃ 期末成绩 ┃ 总评成绩 ┃ 最终 ┃ 绩点
            header = grade[0][0]
            title = grade[0][1][0] if terms else 'All Terms'
            grade = list(sorted(map(lambda x: x[1][3:], grade), reverse=True))

            table = Table(title=title, width=120)
            for h in header[3:]:
                table.add_column(h.replace('成绩', ''))
            for g in grade:
                g = list(g)

                # 修复sb教务乱显示的成绩
                g[-2] = g[-2][:2] if g[-2] != '100' else g[-2]
                g[-2] = '95' if g[-2] == 'A' else g[-2]
                table.add_row(*g)

                if (is_number(g[-2][:2])) and is_number(g[-1]):
                    grade_sum += float(g[2])
                    score_sum += float(g[-2])*float(g[2])
                else:
                    gpa_exclude.append((g[0], g[-2][:2], g[-1]))

            table.row_styles = ['none', 'dim']

            console.print(table)

            md =  "GPA **排除**:\n" + "\n\n".join(map(lambda x: f'- **{x[0]}**: *{x[1]}*, *{x[2]}*', gpa_exclude))
            md += f"\n\n共 **{len(grade)}** 门课程,学分绩估算: **{score_sum / grade_sum :.4f}**"

            console.print(Markdown(md))
            console.print("\n")
Example #7
0
    def output(self, *terms):
        '''
        :param terms: terms to exam information
        '''
        from datetime import datetime
        from rich.console import Console
        from rich.table import Table

        exams = self.aoxiang.examInformations(*terms)

        console = Console()

        for term in exams:
            # exam: [([head], [value]), (...)]
            exam = list(map(lambda x: list(zip(*x.items())), exams[term]))
            # exam[0][0]:
            #   课程序号 ┃ 课程名称 ┃ 考试类型 ┃ 考试日期 ┃ 考试时间 ┃ 考场校区 ┃ 考场教学… ┃ 考场教室 ┃ 考试情况 ┃ 其它说明
            # remove 课程序号 and 其它说明
            header = exam[0][0][1:-1]
            exam = list(sorted(map(lambda x: x[1][1:-1], exam), reverse=True))

            table = Table(title=term, width=120)
            rowStyles = []
            for h in header:
                table.add_column(h)
            for e in exam:
                table.add_row(*e)

                if e[2] is None or e[3] is None:
                    rowStyles.append('dim')
                    continue

                examDate = e[2] + ' ' + e[3].split('~')[-1] + ':00'
                examDate = datetime.strptime(examDate, '%Y-%m-%d %H:%M:%S')

                if datetime.now() > examDate:
                    rowStyles.append('dim')
                else:
                    rowStyles.append('none')

            table.row_styles = rowStyles

            console.print(table)
Example #8
0
    highlight = ReprHighlighter()
    header("Example Table")
    console.print(table, justify="center")

    table.expand = True
    header("expand=True")
    console.print(table, justify="center")

    table.width = 50
    header("width=50")

    console.print(table, justify="center")

    table.width = None
    table.expand = False
    table.row_styles = ["dim", "none"]
    header("row_styles=['dim', 'none']")

    console.print(table, justify="center")

    table.width = None
    table.expand = False
    table.row_styles = ["dim", "none"]
    table.leading = 1
    header("leading=1, row_styles=['dim', 'none']")
    console.print(table, justify="center")

    table.width = None
    table.expand = False
    table.row_styles = ["dim", "none"]
    table.show_lines = True
Example #9
0
    with beat(10):
        console.print(table, justify="center")

    table.columns[2].footer_style = "bright_red"
    with beat(10):
        console.print(table, justify="center")

    table.columns[3].footer_style = "bright_green"
    with beat(10):
        console.print(table, justify="center")

    table.columns[4].footer_style = "bright_blue"
    with beat(10):
        console.print(table, justify="center")

    table.row_styles = ["none", "dim"]
    with beat(10):
        console.print(table, justify="center")

    for color in [
        "deep_pink4",
        "dark_khaki",
        "medium_purple2",
        "thistle3",
        "orange1",
    ]:
        table.border_style = color
        with beat(10):
            console.print(table, justify="center")

    for box in [