response.py 1.05 KB
Newer Older
1 2
import re
from tempfile import NamedTemporaryFile
Saikiran Srirangapalli's avatar
Saikiran Srirangapalli committed
3
import gradaudit.util as util
4 5 6
from subprocess import check_output

class Response:
Saikiran Srirangapalli's avatar
Saikiran Srirangapalli committed
7 8 9 10
    def __init__(self, transcript):
        self.transcript = transcript
        
        main_contents = util.gen_main(transcript)
11 12 13 14 15 16 17
        
        with NamedTemporaryFile() as fil:
            fil.write(main_contents)
            fil.flush()
            answer_set = check_output(['sasp',fil.name])

        self.missing_classes = re.findall('hasNotTaken\({},([a-z]+[1-4][0-9V][0-9][0-9])\)'
Saikiran Srirangapalli's avatar
Saikiran Srirangapalli committed
18 19 20 21
                                          .format(transcript.name),answer_set)
        self.missing_hours = re.findall('needsHours\({},([a-zA-Z]+),([0-9]+)\)'.format(transcript.name),answer_set)
        self.missing_electives = re.findall('needsElectiveHours\({},([0-9])\)'.format(transcript.name),answer_set)
        self.can_grad = 'ableToGraduate({0})'.format(transcript.name) in answer_set
22 23 24 25 26

        if self.missing_electives == []:
            self.missing_electives = 0
        else:
            self.missing_electives = self.missing_electives[0]