Exemplo n.º 1
0
 def send_newnotice(self, spider, user):
     spider.get_html(urls.notice + self.course_id)
     for notice in parse.get_newnotice(spider.html, self.news[1], self.enable_notice):
         url = urls.notice_detail + notice[0]
         spider.get_html(url)
         detail = parse.get_noticedetail(spider.html)
         title = '【' + 'New Notice ' + self.name +  '】' + notice[1]
         text = 'author: \n' + notice[2] + '\n\n'
         text += 'detail: \n' + detail
         mail.send_to_email(title, text, user[2])
Exemplo n.º 2
0
 def send_newfile(self, spider, user, db):
     """
     Send the information that new files have been put in the website
     If the information has been sent, then change the status to 1
     """
     for key, newfile in self.file.items():
         if newfile[4] == 0:
             title = '【' + 'New File ' + self.name + '】' + newfile[1]
             text = 'Detail: \n\n    ' + newfile[2] + '\n\n'
             text += 'File size: \n\n    ' + newfile[3] + '\n\n'
             mail.send_to_email(title, text, user[2])
             self.file[key][4] = 1
             sql = "update File set send_state = '%d' \
                    where course_id = '%s' and file_id = '%s' and user_id = '%s'" \
                    % (1, self.course_id, key, user[0])
             db.update(sql)
Exemplo n.º 3
0
 def send_newhomework(self, spider, user, db):
     for key, homework in self.homework.items():
         if homework[3] == 0:
             spider.get_html(urls.homework_detail + homework[0])
             info = parse.get_homeworkdetail(spider.html)
             if info == '':
                 info = 'NULL'
             title = '【' + 'New HomeWork ' + self.name +  '】' + homework[1]
             text = 'Instruction:\n' + info + '\n\n'
             text += 'Deadline:\n' + str(homework[2])
             mail.send_to_email(title, text, user[2])
             homework[3] = 1
             sql = "update Homework set send_state = '%d' \
                    where course_id = '%s' and homework_id = '%s' and user_id = '%s'" \
                    % (homework[3], self.course_id, key, user[0])
             db.update(sql)
Exemplo n.º 4
0
    def alarm_homework(self, user, db):
        for key, homework in self.homework.items():
            residual_time = (homework[2] - datetime.today()).total_seconds()
            title = '【' + 'Homework Alarm ' + self.name +  '】' + homework[1]
            text = 'Deadline:\n' + str(homework[2]) + '\n\n'

            if residual_time <= 10800 and homework[4] <= 2:
                text += 'The residual time is less than 3 hours.\n\n'
                mail.send_to_email(title, text, user[2])
                homework[4] = 3
            elif residual_time <= 43200 and homework[4] <= 1:
                text += 'The residual time is less than 12 hours.\n\n'
                mail.send_to_email(title, text, user[2])
                homework[4] = 2
            elif residual_time <= 172800 and homework[4] == 0:
                text += 'The residual time is less than 48 hours.\n\n'
                mail.send_to_email(title, text, user[2])
                homework[4] = 1

            sql = "update Homework set alarm_state = '%d' \
                   where course_id = '%s' and homework_id = '%s' and user_id = '%s'" \
                   % (homework[4], self.course_id, key, user[0])
            db.update(sql)