コード例 #1
0
def main():
    students = []
    with open('students.tsv') as students_csv:
        registrations = csv.reader(students_csv)
        for record in registrations:
            items = record[0].split('\t')

            student = Student()
            student.name = items[0]
            student.date_submitted = items[1]
            student.replit_profile = items[2]
            student.codecademy_profile = items[3]
            student.freecodecamp_profile = items[4]

            print(f'\nGathering data for {student.name}\n')

            print('Scanning repl.it...')
            student.replit_points = scrape_replit(student.name, student.replit_profile) or 0
            print('Scanning Codecademy...')
            student.codecademy_percent = scrape_codecademy(student.name, student.codecademy_profile) or 0
            print('Scanning FreeCodeCamp...')
            student.freecodecamp_percent = scrape_freecodecamp(student.name, student.freecodecamp_profile) or 0
            students.append(student)
            print(f'Results:\n{student}')

    with open('scores.csv', 'w', newline='') as csvfile:
        writer = csv.writer(csvfile)
        writer.writerow(["Student", "repl.it", "Codecademy %", "FreeCodeCamp %"])
        for student in students:
            writer.writerow([student.name, student.replit_points, student.codecademy_percent, student.freecodecamp_percent])