コード例 #1
0
def gethours(weekday):  #Getting an ordered list of hours of a specific day
    jsoncontent = files.readdata(datafilepath)

    unordered_schedule = jsoncontent["saved_schedules"][
        weekday]  #Storing a copy of the unordered list of appointments

    unordered_hours = []

    ordered_hours = []

    for appointment in unordered_schedule:
        unordered_hours.append(
            int(unordered_schedule[appointment]["hour"].replace(":", "")))
        #stores the current hour in the ordered hours list as an integer
        #to be able to order the hours

    unordered_hours.sort()  #sorts the hours in unordered hours

    for hour in unordered_hours:  #appends each hour in unordered hours to ordered hours in the format: "hours:minutes" (as a string)
        hour = str(hour)
        if len(hour) == 3:
            hour = "0" + hour
        hour = hour[:2] + ":" + hour[2:]
        ordered_hours.append(hour)

    return ordered_hours
コード例 #2
0
def printday(weekday):
    jsoncontent = files.readdata(datafilepath)

    for hour in gethours(weekday):
        for appointment in jsoncontent["saved_schedules"][weekday]:
            if jsoncontent["saved_schedules"][weekday][appointment][
                    "hour"] == hour:
                printappointment(appointment, weekday)
コード例 #3
0
def printappointment(name, weekday):
    jsoncontent = files.readdata(datafilepath)

    #Locating Appointment and printing
    print("[{}] [{}]{} {}{}".format(
        jsoncontent["saved_schedules"][weekday][name]["day"],
        jsoncontent["saved_schedules"][weekday][name]["hour"],
        colours[jsoncontent["saved_schedules"][weekday][name]["colour"]], name,
        colours["DEFAULT"]))
コード例 #4
0
def nextapp():
    jsoncontent = files.readdata(datafilepath)
    currenthour = int(
        str(time.strftime("%H", time.localtime())) +
        str(time.strftime("%M", time.localtime())))
    nexthour = ""

    for hour in gethours(time.strftime("%A", time.gmtime()).lower()):
        if int(hour[:2] + hour[3:]) > currenthour:
            nexthour = hour
            break
    for appointment in jsoncontent["saved_schedules"][time.strftime(
            "%A", time.gmtime()).lower()]:
        if nexthour == jsoncontent["saved_schedules"][time.strftime(
                "%A", time.gmtime()).lower()][appointment]["hour"]:
            printappointment(appointment,
                             time.strftime("%A", time.gmtime()).lower())
コード例 #5
0
def delappointment(name):
    jsoncontent = files.readdata(datafilepath)  #getting jsonfile contents

    appointment_location = ""

    #Getting the appointment location

    for weekday in jsoncontent["saved_schedules"]:
        for appointment in jsoncontent["saved_schedules"][weekday]:
            if appointment == name:
                appointment_location = weekday  #Storing appointment location

        if appointment_location != "":  #Verifying if the appointment actually exists
            jsoncontent["saved_schedules"][appointment_location].pop(
                name)  #Deleting appointment
            print("[{}] deleted".format(name))

    if appointment_location == "":
        print("\033[91m[ERROR] Appointment does not exist;\033[0m")

    files.savedata(datafilepath, jsoncontent)  #Saving Changes
コード例 #6
0
def addappointment(name, day, hour, colour="DEFAULT"):
    jsoncontent = files.readdata(datafilepath)
    if colour not in colours:
        print("\033[91m[ERROR] Non supported color;\033[0m")
        print("\033[91m[ERROR] ", end="[")
        for colour in colours:
            print(colour, end=" ")
        print("]\033[0m")
    if day in [
            "monday", "tuesday", "wednesday", "thursday", "friday", "saturday",
            "sunday"
    ]:
        jsoncontent["saved_schedules"][day][name] = {
            "name": name,
            "day": day,
            "hour": hour,
            "colour": colour
        }  #changing json's file's dict contents
    else:
        print("\033[91m[ERROR] The day must be a week day;\033[0m")
        print(
            "\033[91m[ERROR] [\"monday\",\"tuesday\",\"wednesday\",\"thursday\",\"friday\",\"saturday\",\"sunday\"];\033[0m"
        )
    files.savedata(datafilepath, jsoncontent)  #Saving json file