<commit_before># -*- coding: utf-8 -*-
# @Date    : 2014-07-01 21:26:10
# @Author  : <EMAIL> <EMAIL>
from tornado.httpclient import HTTPRequest, HTTPClient, HTTPError
from sqlalchemy.sql import or_
from ..models.course import Course
from ..models.gpa import Overview as GPAO
from ..models.srtp import Overview as SRTPO
from weekday import today, tomorrow, changedate, ismorning
from config import LOCAL
from get_api_return import get_api_return
import urllib
import json
import re


def curriculum(db, user, day):
    courses = db.query(Course).filter(
        Course.openid == user.openid, Course.day == day).all()
    p = re.compile(r'\[|\]|\(|\)')
    msg = u'<a href="%s/update/curriculum/%s">更新课表</a>\n\n' % (LOCAL, user.openid)
    for course in courses:
        msg += course.course + u'\n' + \
            '   '.join(p.split(course.period)).strip() + u'\n' + \
            '   '.join(p.split(course.place)).strip() + u'\n\n'
    if not msg:
        msg = u'没课哦'
    msg = msg.strip() + '\n\n' + \
        u'<a href="%s/curriculum/%s">查看课表</a>' % (
            LOCAL, user.openid)
    return msg

def new_curriculum(db, user):
    daymap = {'Mon':u'周一', 'Tue':u'周二', 'Wed':u'周三', 'Thu':u'周四', 'Fri':u'周五', 'Sat':u'周六', 'Sun':u'周日'}
    courses = db.query(Course).filter(
        Course.openid == user.openid, Course.day == changedate()).all()
    p = re.compile(r'\[|\]|\(|\)')
    msg = u'<a href="%s/update/curriculum/%s">更新课表</a>\n\n' % (LOCAL, user.openid)
    for course in courses:
        msg += course.course + u'\n' + \
            '   '.join(p.split(course.period)).strip() + u'  ' + daymap[course.day] + u'\n' + \
            '   '.join(p.split(course.place)).strip() + u'\n\n'
    if not msg:
        msg = u'没课哦'
    msg = msg.strip() + '\n\n' + \
        u'<a href="%s/curriculum/%s">查看课表</a>' % (
            LOCAL, user.openid)
    return msg

def pe_counts(user):
    msg = u''
    response = get_api_return('pe', user)
    if response['code'] == 200:
        msg += u'当前跑操次数 %s 次' % response['content']
    else:
        msg += response['content']
    if ismorning():
        response = get_api_return('pc', user)
        if response['code'] == 201:
            msg += u'\n\n0.0, 早起有益健康，小猴正在获取跑操情报，等会再试试'
        else:
            msg += u'\n\n小猴猜测' + response['content']
    return msg

def phylab(user):
    response = get_api_return('phylab',user)
    msg = u''
    if response['code'] ==200:
        content = response['content']
        for labType in content:
            if content[labType]!='':
                msg +=u'%s:\n' %labType
                for lab in content[labType]:
                    msg +=u'> %s\n' %lab['name']
                    msg +=u'%s   ' %lab['Teacher']
                    if not lab['Grade']:
                        msg +=u'%s\n' %lab['Address']
                        msg +=u'%s %s\n' %(lab['Date'],lab['Day'])
                    else:
                        msg +=u'成绩:%s\n' %lab['Grade']
                msg +=u'\n'
        if not msg:
            return u'没有物理实验哦'
        return msg[:-3]
    else:
        return response['content'] 

def rendered(user):
    response = get_api_return('library', user)
    msg = u''
    if response['code'] == 200:
        try:
            books = response['content']
            for book in books:
                detail = u'\n%s\n借书时间：%s\n到期时间：%s' % (
                    book['author'],
                    book['render_date'], book['due_date'])
                if book['renew_time'] == u'0':
                    msg += u'<a href="%s/renew/%s/%s">《%s》</a>%s' % (
                        LOCAL, user.openid, book['barcode'],
                        book['title'], detail)
                else:
                    msg += u'《%s》%s\n续借次数：%s' % (
                        book['title'], detail, book['renew_time'])
                msg += u'\n\n'<commit_msg>fix bug<commit_after># -*- coding: utf-8 -*-
# @Date    : 2014-07-01 21:26:10
# @Author  : <EMAIL> <EMAIL>
from tornado.httpclient import HTTPRequest, HTTPClient, HTTPError
from sqlalchemy.sql import or_
from ..models.course import Course
from ..models.gpa import Overview as GPAO
from ..models.srtp import Overview as SRTPO
from weekday import today, tomorrow, changedate, ismorning
from config import LOCAL
from get_api_return import get_api_return
import urllib
import json
import re


def curriculum(db, user, day):
    courses = db.query(Course).filter(
        Course.openid == user.openid, Course.day == day).all()
    p = re.compile(r'\[|\]|\(|\)')
    msg = u'<a href="%s/update/curriculum/%s">更新课表</a>\n\n' % (LOCAL, user.openid)
    for course in courses:
        msg += course.course + u'\n' + \
            '   '.join(p.split(course.period)).strip() + u'\n' + \
            '   '.join(p.split(course.place)).strip() + u'\n\n'
    if not msg:
        msg = u'没课哦'
    msg = msg.strip() + '\n\n' + \
        u'<a href="%s/curriculum/%s">查看课表</a>' % (
            LOCAL, user.openid)
    return msg

def new_curriculum(db, user):
    daymap = {'Mon':u'周一', 'Tue':u'周二', 'Wed':u'周三', 'Thu':u'周四', 'Fri':u'周五', 'Sat':u'周六', 'Sun':u'周日'}
    courses = db.query(Course).filter(
        Course.openid == user.openid, Course.day == changedate()).all()
    p = re.compile(r'\[|\]|\(|\)')
    msg = u'<a href="%s/update/curriculum/%s">更新课表</a>\n\n' % (LOCAL, user.openid)
    for course in courses:
        msg += course.course + u'\n' + \
            '   '.join(p.split(course.period)).strip() + u'  ' + daymap[course.day] + u'\n' + \
            '   '.join(p.split(course.place)).strip() + u'\n\n'
    if not msg:
        msg = u'没课哦'
    msg = msg.strip() + '\n\n' + \
        u'<a href="%s/curriculum/%s">查看课表</a>' % (
            LOCAL, user.openid)
    return msg

def pe_counts(user):
    msg = u''
    response = get_api_return('pe', user)
    if response['code'] == 200:
        msg += u'当前跑操次数 %s 次' % response['content']
    else:
        msg += response['content']
    if ismorning():
        response = get_api_return('pc', user)
        if response['code'] == 201:
            msg += u'\n\n0.0, 早起有益健康，小猴正在获取跑操情报，等会再试试'
        else:
            msg += u'\n\n小猴猜测' + response['content']
    return msg

def phylab(user):
    response = get_api_return('phylab',user)
    msg = u''
    if response['code'] ==200:
        content = response['content']
        for labType in content:
            if content[labType]!='':
                msg +=u'%s:\n' %labType
                for lab in content[labType]:
                    msg +=u'> %s\n' %lab['name']
                    msg +=u'%s   ' %lab['Teacher']
                    if not lab['Grade']:
                        msg +=u'%s\n' %lab['Address']
                        msg +=u'%s %s\n' %(lab['Date'],lab['Day'])
                    else:
                        msg +=u'成绩:%s\n' %lab['Grade']
                msg +=u'\n'
        if not msg:
            return u'没有物理实验哦'
        return msg[:-3]
    elif response['code'] == 599:
        return u"正在获取最新数据，再点一次就有啦！"
    else:
        return response['content']

def rendered(user):
    response = get_api_return('library', user)
    msg = u''
    if response['code'] == 200:
        try:
            books = response['content']
            for book in books:
                detail = u'\n%s\n借书时间：%s\n到期时间：%s' % (
                    book['author'],
                    book['render_date'], book['due_date'])
                if book['renew_time'] == u'0':
                    msg += u'<a href="%s/renew/%s/%s">《%s》</a>%s' % (
                        LOCAL, user.openid, book['barcode'],
                        book['title'], detail)
                else:
                    msg += u'《%s》%s\n续借次数：%s' % (
                        book['title'], detail, book['renew_time'])
                msg += u'\n\n'
{'fraction_non_alphanumeric': 0.18498521660881861, 'fraction_numerical': 0.008355829798174572, 'mean_word_length': 1.888971407352395, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4178674', 'n_tokens_mistral': 2881, 'n_tokens_neox': 2825, 'n_words': 569}