Skip to content

Instantly share code, notes, and snippets.

@armanbilge
Created August 30, 2013 02:48
Show Gist options
  • Save armanbilge/6385863 to your computer and use it in GitHub Desktop.
Save armanbilge/6385863 to your computer and use it in GitHub Desktop.
Extracts student names and homerooms from a FirstClass directory's HTML source.
#!/usr/bin/env python
import sys
try:
stream = open(sys.argv[1], 'r')
except:
stream = sys.stdin
students = []
class Student:
def __init__(self,str):
self.first, self.last, self.hr = str.split(',')
for l in stream:
l = l.split(';')
out = ''
for part in l:
if '7' in part[0]:
out += ','.join(part.split(':')[1][1:-1].split()) + ','
if '1252' in part and '17' in part:
students.append(Student(out + part.split(':')[1].split('`')[1][-3:]))
if stream is not sys.stdin:
stream.close()
print 'last\tfirst\thr'
for student in students:
print '\t'.join([student.last,student.first,student.hr])
print 'hr\tfirst\tlast'
for student in sorted(students, key=lambda student: student.hr):
print '\t'.join([student.hr,student.first,student.last])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment