Passed
Push — master ( 795fc4...bbae7c )
by dai
11:39 queued 09:30
created

utils   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 47
dl 0
loc 62
rs 10
c 0
b 0
f 0
1
#!/usr/bin/env python
2
# encoding: utf-8
3
from __future__ import absolute_import, unicode_literals
4
5
import six
6
import datetime
7
8
9
def assemble_schedule(schedule_data):
10
    """ 组装课表回复数据 """
11
    week_day_text = ['日', '一', '二', '三', '四', '五', '六']
12
    strf = "%Y年%m月%d日"
13
    if six.PY2:
14
        strf = strf.encode("utf-8")
15
    description = datetime.datetime.now().strftime(strf)
16
17
    # 获取第一周 星期一 的课表
18
    weeks = 1
19
    what_day = 1
20
    articles = [{
21
        'title': '第%d周-星期%s' % (weeks, week_day_text[what_day]),
22
        'description': description,
23
        'url': ''
24
    }]
25
    for i, section in enumerate(schedule_data['schedule'][what_day - 1]):
26
        for c in section:
27
            if weeks in c['weeks_arr']:
28
                section_time = '第%d,%d节' % (i * 2 + 1, i * 2 + c['section'])
29
                content = '%s  地点:%s\n课程:%s' % (
30
                    section_time, c['place'], c['name'])
31
                articles.append({
32
                    'title': content,
33
                    'description': "",
34
                    'url': ''
35
                })
36
    articles.append({
37
        'title': '点击这里:查看完整课表',
38
        'description': '',
39
        'url': 'https://open.dairoot.cn/get_schedule'
40
    })
41
    return articles
42
43
44
def assemble_score(score_year, score_term, score_data):
45
    articles = [{
46
        'title': '期末成绩单',
47
        'description': '【第%s学年第%s学期】' % (score_year, score_term)
48
    }]
49
    for n, c in enumerate(score_data):
50
        if n > 5:
51
            break
52
        print(c)
53
        articles.append({
54
            'title': "课程:%s\n学分:%s 成绩:%s" % (c['lesson_name'], c['credit'],  c['score']),
55
        })
56
    articles.append({
57
        'title': '点击这里:查看完整成绩',
58
        'description': '',
59
        'url': ''
60
    })
61
    return articles
62