Skip to content

Instantly share code, notes, and snippets.

@agmarrugo
Last active October 20, 2015 03:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save agmarrugo/5781fbf3d42f26cd2114 to your computer and use it in GitHub Desktop.
Reads a text file with grades and comments, and produces a csv file.
#! /usr/local/bin/python
# -*- coding: utf-8 -*-
import re
import csv
import argparse
class REMatcher(object):
""" A little class that returns the boolean result of calling match,
and retains the matched groups for subsequent retrieval.
Attributes
----------
matchstring : The string to match
match : Matching the regular expression, returns True/False
group : Returns the matched groups with index i
Modified from Paul McGuire,
http://stackoverflow.com/questions/2554185/match-groups-in-python
"""
def __init__(self, matchstring):
self.matchstring = matchstring
def match(self,regexp):
self.rematch = re.match(regexp, self.matchstring)
return bool(self.rematch)
def group(self,i):
return self.rematch.group(i)
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("input", help="path to the input text file")
# optional output csv file path
ap.add_argument("-o", "--output", help="path to the output csv file")
args = vars(ap.parse_args())
# Path to text file
filePath = args['input']
# Path to output file
if args['output']:
fileCSVPath = args['output']
else:
# If output file path is not provided
fileCSVPath = args['input'].split('.')[0] + ".csv"
fileCSV = open(fileCSVPath,'w')
wr = csv.writer(fileCSV,quoting=csv.QUOTE_ALL)
# Write titles in csv file
wr.writerow(["Nombre","Nota","Comentario"])
with open(filePath,'r') as f:
# Iterate through all lines in f
for line in f:
m = REMatcher(line)
if m.match(r"^-(.*$)"):
Name = m.group(1)
if m.match(r"^\t.*-.*Comentario:(.*$)"):
Comment = m.group(1)
if m.match(r"^\t.*-.*Nota:\s*(\d.*$)"):
Grade = m.group(1)
List = [Name,Grade,Comment]
wr.writerow(List)

tags:#vision

  • Pérez Ramos, Miguel A.

    • Comentario: El informe está completo y bien argumentado. Se demuestra que se realizó la práctica a cabalidad. Concluye adecuadamente y cita las referencias consultadas.
    • Nota: 5.0
  • Beleño Hernández, Liliana P.

    • Comentario: El informe comienza bien, pero termina abruptamente. No se mencionan los aspectos relacionados con la lectura y tampoco se evidencia adecuadamente los resultados de la práctica. No hay bibliografía.
    • Nota: 3.5
  • Carrascal Mendez, Martín S.

    • Comentario: El informe es adecuado y cumple con el objetivo de la práctica.
    • Nota: 5.0
  • Piñeres De La Rosa, Néstor N.

    • Comentario: El marco teórico apunta a lo necesario, pero con las citas correspondientes. Muy bien por utilizar otras imágenes. Los comentarios son oportunos. Una discusión un poco más extensa sobre los distintos tipos de filtros que se implementaron en la última parte es deseable, "prewitt", "sobel", etc.
    • Nota: 4.7
  • Daza Beltran, Juan A.

    • Comentario: El informe se ajusta a lo mínimo. Debería tener una discusión de resultados más extensa u observaciones del proceso de filtrado con diferentes filtros. Termina abruptamente. No hay bibliografía.
    • Nota: 3.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment