diff --git a/.gitignore b/.gitignore index 68bc17f..d8ae83d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Personal files used during development +right_student_schedule.jsp + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/README.md b/README.md index 443a106..2910960 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # schoolsoft-schema-parser -Parses schoolsoft schemas from 'right_student_schema.jsp' file into readable json +Parses schoolsoft schedules from 'right_student_schedule.jsp' file into readable json diff --git a/output.json b/output.json new file mode 100644 index 0000000..aea98b9 --- /dev/null +++ b/output.json @@ -0,0 +1 @@ +{"343148": {"name": "ELRELK0", "room": "Sal 14", "starts": "8:30", "ends": "9:45", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 20, 21, 22]}, "343234": {"name": "IDRIDR01", "room": "Sal 14", "starts": "8:45", "ends": "10:00", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 47, 48, 49, 50, 51]}, "343142": {"name": "MENTORSTID", "room": "Sal 14", "starts": "9:00", "ends": "9:45", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23]}, "343159": {"name": "PRRPRR01", "room": "Sal 13", "starts": "9:05", "ends": "10:20", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 23]}, "343120": {"name": "HISHIS01a1", "room": "Sal 3", "starts": "9:20", "ends": "10:35", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 15, 16, 17, 18, 20, 21, 22]}, "343146": {"name": "ENGENG05", "room": "Sal 14", "starts": "9:55", "ends": "11:10", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23]}, "343153": {"name": "ELRELK0", "room": "Sal 14", "starts": "9:55", "ends": "11:10", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 20, 21, 22]}, "343160": {"name": "SVESVE01", "room": "Sal 3", "starts": "10:40", "ends": "11:55", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 19, 20, 21, 22, 23]}, "343145": {"name": "MATMAT01a", "room": "Sal 3", "starts": "10:45", "ends": "12:00", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 23]}, "343139": {"name": "SVESVE01", "room": "Sal 3", "starts": "10:45", "ends": "12:00", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 15, 16, 17, 18, 20, 21, 22]}, "343144": {"name": "Lunch", "room": "\"\"", "starts": "11:10", "ends": "11:55", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23]}, "343158": {"name": "Lunch", "room": "", "starts": "11:20", "ends": "12:05", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 20, 21, 22]}, "343155": {"name": "PRRPRR01", "room": "Sal 8", "starts": "12:00", "ends": "13:15", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23]}, "343156": {"name": "Lunch", "room": "\"\"", "starts": "12:00", "ends": "12:45", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 23]}, "343147": {"name": "MATMAT01a", "room": "Sal 3", "starts": "12:10", "ends": "13:25", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 20, 21, 22]}, "343141": {"name": "Lunch", "room": "", "starts": "12:10", "ends": "12:55", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 15, 16, 17, 18, 20, 21, 22]}, "343157": {"name": "Lunch", "room": "", "starts": "12:15", "ends": "13:00", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 19, 20, 21, 22, 23]}, "343149": {"name": "ENEENE01", "room": "Sal 14", "starts": "12:45", "ends": "14:00", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 23]}, "343154": {"name": "DAODAT01a", "room": "Sal 2", "starts": "13:30", "ends": "14:45", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 19, 20, 21, 22, 23]}, "343138": {"name": "ENGENG05", "room": "Sal 3", "starts": "13:35", "ends": "14:50", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 20, 21, 22]}, "343294": {"name": "HISHIS01a1", "room": "Sal 3", "starts": "13:45", "ends": "15:00", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23]}, "343152": {"name": "ENEENE01", "room": "Sal 14", "starts": "14:10", "ends": "15:25", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 23]}, "343143": {"name": "DAODAT01a", "room": "Sal 2", "starts": "14:55", "ends": "16:10", "weeks": [35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 47, 48, 49, 50, 51, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 19, 20, 21, 22, 23]}} \ No newline at end of file diff --git a/parser.py b/parser.py new file mode 100644 index 0000000..1113e08 --- /dev/null +++ b/parser.py @@ -0,0 +1,125 @@ +import sys +import json + +inputFile = '' +outputFile = '' + +outputContent = {} + +# Super janky script to parse right_student_schedule.jsp and save as readable json + +def getInput(): + + global inputFile, outputFile + + inputFile = input("Input file: ") + outputFile = input("Output file: ") + +def main(): + + global inputFile, outputFile + + # Set input and output file if not specified + if inputFile == '': inputFile = 'right_student_schedule.jsp' + if outputFile == '': outputFile = 'output.json' + + with open(inputFile,'r') as f: + + line = 0 # Start at line 0 + + hitSchedules = False + + # Go through all lines of file + for x in f.readlines(): + + line += 1 # Increment line counter + + if 'class="tab' in x: # Skip all the unnecessary stuff + hitSchedules = True + continue + + # Skip other unnecessary stuff + if not hitSchedules or not 'href="right_student_schedule.jsp?lesson=' in x: continue + + # Prepare entry to add to dict + entry = {} + + # Extract weeks active + weeks = [] + + sectionStartIndex = x.find('Veckor') + 8 # Find start of week section + sectionEndIndex = x.find('<',sectionStartIndex) # Find end of week section + + for y in x[sectionStartIndex:sectionEndIndex].split(', '): # Split string of extracted weeks + + if '-' in y: # If processed week is a range, add all weeks in range + z = y.split('-') + for n in range(int(z[0]), int(z[1])+1): + weeks.append(n) + else: # If not a range, just add the week + weeks.append(int(y)) + + + # Extract lesson ID + lesson_id = 0 + + sectionStartIndex = x.find('lesson=') + 7 + sectionEndIndex = x.find('&',sectionStartIndex) + + lesson_id = x[sectionStartIndex:sectionEndIndex] + + + # Extract class name + name = '' + + sectionStartIndex = x.find('title="">') + 16 + sectionEndIndex = x.find('<',sectionStartIndex) + + name = x[sectionStartIndex:sectionEndIndex] + + + # Extract class times + classStart = '00:00' + classEnd = '00:00' + + sectionStartIndex = x.find('>',sectionEndIndex) + 1 + sectionEndIndex = x.find('<',sectionStartIndex) + + y = x[sectionStartIndex:sectionEndIndex].split('-') + classStart = y[0] + classEnd = y[1] + + # Extract room id + room = '0' + + sectionStartIndex = x.find('>',sectionEndIndex) + 1 + sectionEndIndex = len(x) + + room = x[sectionStartIndex:sectionEndIndex].strip('\n') + + + # Add all extracted values to entry + entry['name'] = name + entry['room'] = room + entry['starts'] = classStart + entry['ends'] = classEnd + entry['weeks'] = weeks + + outputContent[lesson_id] = entry + + f.close() + + with open(outputFile, 'w') as file: + json.dump(outputContent, file) + + + + + +if __name__ == '__main__': + getInput() +else: + inputFile = sys.argv[0] + outputFile = sys.argv[1] + +main() \ No newline at end of file