コード例 #1
0
ファイル: properties.py プロジェクト: adrianPascan/FP
def readActivitiesFromTextFile(fileName):
    activityList = []
    try:
        file0 = open(fileName, "r")
        line = file0.readline().strip().split(":")
        while not (len(line) == 1 and line[0] == ''):
            try:
                activity = Activity(None, None, None, None, None)
                activity.set_activity_id(int(line[0].strip()))
                line[1] = line[1].strip()
                line[1] = line[1][1:(len(line[1]) - 1)].split(",")
                personsIDs = []
                for ID in line[1]:
                    personsIDs.append(int(ID.strip()))
                activity.set_person_ids(personsIDs)
                activity.set_date(line[2].strip())
                activity.set_time(line[3].strip() + ":" + line[4].strip())
                activity.set_description(line[5].strip())
                activityList.append(activity)
            except ValueError as error:
                print("Could not validate person with id ", line[0].strip(),
                      ": ", error)
            line = file0.readline().strip().split(":")
        file0.close()
    except IOError as error:
        print("Input error: ", error)
    return activityList
コード例 #2
0
ファイル: menu.py プロジェクト: adrianPascan/FP
def readActivity(personList, message):
    activity = Activity(None, None, None, None, None)
    while True:
        try:
            print(message)
            activity.set_activity_id(readID(''))
            activity.set_person_ids(readPersonIDs(personList))
            activity.set_date(input('Date (day.month.year): '))
            activity.set_time(input('Time (hour:minute): '))
            activity.set_description(input('Description: '))
            return activity
        except ValueError as error:
            print(error)