Beispiel #1
0
    if options.womens_distance is None:
        options.womens_distance = Distances.get(1).womens_distance
    return options, (race_name, date, venue)

@main_function(parse_arguments)
def main(options, (name, date, venue)):
    """Reads race results from a YAML file taken from stdin and saves them to
    the database based on the command-line arguments."""
    try:
        results = load(stdin.read())
    except KeyboardInterrupt:
        return 1
    except ScannerError, error:
        print >> stderr, error
        return 1
    Races.create(name, date, venue, options.mens_distance,
                 options.womens_distance, options.comments, results)

class Date(datetime.date):
    """Clone of datetime.date that can be instantiated by parsing a string of
    the form /YYYY-MM-DD/."""

    @classmethod
    def from_string(cls, string):
        """Construct a new datetime.date object from a string matching the
        pattern \d{4}[-/]\d{1,2}[-/]\d{1,2}."""
        try:
            if "-" in string:
                year, month, day = string.split("-")
            elif "/" in string:
                year, month, day = string.split("/")
            else: