Create grab.js
This commit is contained in:
		
							parent
							
								
									c944fe3c61
								
							
						
					
					
						commit
						c4f48cab53
					
				
					 4 changed files with 1008 additions and 25 deletions
				
			
		| 
						 | 
				
			
			@ -1,2 +1,6 @@
 | 
			
		|||
# schoolsoft-schema-parser
 | 
			
		||||
Parses schoolsoft schedules from 'right_student_schedule.jsp' file into readable json
 | 
			
		||||
 | 
			
		||||
CURRENTLY REWRITING ENTIRELY, DONT LOOK AT IT :)
 | 
			
		||||
 | 
			
		||||
document.createElement('script').src = 'http://example.com/file.js';
 | 
			
		||||
							
								
								
									
										0
									
								
								grab.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								grab.js
									
										
									
									
									
										Normal file
									
								
							
							
								
								
									
										990
									
								
								output.json
									
										
									
									
									
								
							
							
						
						
									
										990
									
								
								output.json
									
										
									
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										37
									
								
								parser.py
									
										
									
									
									
								
							
							
						
						
									
										37
									
								
								parser.py
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,27 +1,18 @@
 | 
			
		|||
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
 | 
			
		||||
    outputContent = {}
 | 
			
		||||
 | 
			
		||||
    # Set input and output file if not specified
 | 
			
		||||
    if inputFile == '': inputFile = 'right_student_schedule.jsp'
 | 
			
		||||
    if outputFile == '': outputFile = 'output.json'
 | 
			
		||||
    try:
 | 
			
		||||
        inputFile = sys.argv[0]
 | 
			
		||||
        outputFile = sys.argv[1]
 | 
			
		||||
    except:
 | 
			
		||||
        inputFile = 'right_student_schedule.jsp'
 | 
			
		||||
        outputFile = 'output.json'
 | 
			
		||||
    
 | 
			
		||||
    with open(inputFile,'r') as f:
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -59,6 +50,8 @@ def main():
 | 
			
		|||
                else: # If not a range, just add the week
 | 
			
		||||
                    weeks.append(int(y))
 | 
			
		||||
            
 | 
			
		||||
            weeks.sort()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            # Extract lesson ID
 | 
			
		||||
            lesson_id = 0
 | 
			
		||||
| 
						 | 
				
			
			@ -97,10 +90,13 @@ def main():
 | 
			
		|||
 | 
			
		||||
            room = x[sectionStartIndex:sectionEndIndex].strip('\n')
 | 
			
		||||
 | 
			
		||||
            if name == 'Lunch': room = '' # Prevent weird extraction of non-existent lunch room
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            # Add all extracted values to entry
 | 
			
		||||
            entry['name'] = name
 | 
			
		||||
            entry['room'] = room
 | 
			
		||||
            entry['day'] = "" # No idea how to do this
 | 
			
		||||
            entry['starts'] = classStart
 | 
			
		||||
            entry['ends'] = classEnd
 | 
			
		||||
            entry['weeks'] = weeks
 | 
			
		||||
| 
						 | 
				
			
			@ -110,16 +106,11 @@ def main():
 | 
			
		|||
        f.close()
 | 
			
		||||
 | 
			
		||||
    with open(outputFile, 'w') as file:
 | 
			
		||||
        json.dump(outputContent, file)
 | 
			
		||||
        json.dump(outputContent, file, indent=4)
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
        
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    getInput()
 | 
			
		||||
else:
 | 
			
		||||
    inputFile = sys.argv[0]
 | 
			
		||||
    outputFile = sys.argv[1]
 | 
			
		||||
 | 
			
		||||
main()
 | 
			
		||||
    main()
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue