Ran pylint

parent b1f78e22
#!/usr/bin/env python3
"""
This program writes 'main.lp'.
Pass in a transcript in the specified csv format.
Pass in a transcript in the specified csv format as a command line argument.
"""
import csv,sys,re
import csv
import re
import sys
if len(sys.argv) != 2:
print("Usage: python main_writer.py /path/to/transcript")
transcript = sys.argv[1]
def main():
"""
This program writes 'main.lp'.
Run as:
python3 main_writer.py <transcript>
"""
try:
transcript = open(transcript)
except IOError:
print("transcript not found")
sys.exit()
if len(sys.argv) != 2:
print("Usage: python main_writer.py /path/to/transcript")
sys.exit(1)
csvr = list(csv.reader(transcript))
student = csvr[0][0]
(degree,major,year,spec) = csvr[1]
transcript = sys.argv[1]
req = '%s/%s/%s/%s%sreq.lp' % (degree,major,year,major,year)
try:
req = open(req)
req = req.read()
except:
print('requirements file not found')
sys.exit()
with open('course.lp','r') as file:
valid_courses = re.findall('[a-z]+[0-9][0-9V][0-9]{2}',file.read())
with open('main.lp','w') as main:
main.write("student(%s,%s).\n"%(student,major))
courses = csvr[2] #list of courses student has taken
taken = '_taken(%s,[' % student
hasTaken = str()
for c in courses:
if not c in valid_courses:
print('Warning: %s is not in course.lp')
#include only those courses that could possibly
#counted as electives in the 'taken list' i.e.
#those that are not required.
if not ('_req(%s,required).' % c) in req:
taken += "%s," % c
hasTaken += '_hasTaken(%s,%s).\n' % (student, c)
main.write('\n')
taken = taken[:-1]
taken += ']).\n'
try:
transcript = open(transcript)
except IOError:
print("transcript not found")
sys.exit(1)
main.write(hasTaken+'\n')
main.write(taken+'\n')
#write the student's specialization as a fact if it is
#declared in the transcript
if spec != 'none':
main.write('_specialization(%s,%s).\n' %(student,spec))
csvr = list(csv.reader(transcript))
student = csvr[0][0]
(degree, major, year, spec) = csvr[1]
main.write("#include 'counting.lp'.\n")
main.write("#include '%s/%s/%s/%s%srules.lp'.\n" % (degree,major,year,major,year))
main.write('?- _main(%s).\n' % student)
req = '%s/%s/%s/%s%sreq.lp' % (degree, major, year, major, year)
try:
req = open(req)
req = req.read()
except IOError:
print('requirements file not found')
sys.exit(1)
# Get list of courses from course.lp
with open('course.lp', 'r') as file:
valid_courses = re.findall('[a-z]+[0-9][0-9V][0-9]{2}', file.read())
with open('main.lp', 'w') as main_file:
main_file.write("student(%s,%s).\n" % (student, major))
courses = csvr[2] # list of courses student has taken
taken = '_taken(%s,[' % student
has_taken = str()
for course in courses:
if not course in valid_courses:
print('Warning: %s is not in course.lp')
# include only those courses that could possibly
# counted as electives in the 'taken list' i.e.
# those that are not required.
if not '_req(%s,required).' % course in req:
taken += "%s," % course
has_taken += '_hasTaken(%s,%s).\n' % (student, course)
main_file.write('\n')
taken = taken[:-1]
taken += ']).\n'
main_file.write(has_taken + '\n')
main_file.write(taken + '\n')
# write the student's specialization as a fact if it is
# declared in the transcript
if spec != 'none':
main_file.write('_specialization(%s,%s).\n' % (student, spec))
main_file.write("#include 'counting.lp'.\n")
main_file.write("#include '%s/%s/%s/%s%srules.lp'.\n" %
(degree, major, year, major, year))
main_file.write('?- _main(%s).\n' % student)
if __name__ == '__main__':
main()
#!/usr/bin/env python3
"""
This program writes writes <bs/ba><major><year>req2.lp.
Pass in the degree major and year
ex: python req_writer.py bs cs 2015
Pass in the degree major and year as command line arguments.
"""
import re,sys
import re
import sys
def main():
"""
Run as:
python req_writer.py <degree_type> <major> <degree_year>
ex: python req_writer.py bs cs 2015
"""
if len(sys.argv) != 4:
print("Usage: python req_writer.py <bs/ba> <major> <year>")
sys.exit()
if len(sys.argv) != 4:
print("Usage: python req_writer.py <bs/ba> <major> <year>")
sys.exit()
(degree, major, year) = sys.argv[1:]
(degree, major, year) = sys.argv[1:]
directory = "%s/%s/%s/" % (degree, major, year)
prefix = "%s%s" % (major, year)
directory = "%s/%s/%s/" % (degree,major,year)
prefix = "%s%s" % (major,year)
# Get list of courses from course.lp
with open('course.lp', 'r') as file:
courses = re.findall('[a-z]+[0-9][0-9V][0-9]{2}', file.read())
with open('course.lp','r') as file:
courses = re.findall('[a-z]+[0-9][0-9V][0-9]{2}',file.read())
with open(directory + prefix + 'req.lp', 'r') as file:
req = file.read()
with open(directory+prefix+'req.lp','r') as file:
req = file.read()
with open(directory+prefix+'req2.lp','w') as file:
for c in courses:
if not (c in req):
file.write('_req(%s,none).\n' % c)
with open(directory + prefix + 'req2.lp', 'w') as file:
for course in courses:
if not course in req:
file.write('_req(%s,none).\n' % course)
if __name__ == '__main__':
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment