Esempio n. 1
0
def pageBody():

    date = dateNow

    oldWeekNumber = 0

    i = 0

    while True:
        isWorkDay, isNotOnBreak, weekNumber, dayNumber, breakName = isRingDay(
            date, oldWeekNumber, cursor, verbose)

        if weekNumber != oldWeekNumber:
            print("<br>\n<br>Week number: %s" % weekNumber)
            oldWeekNumber = weekNumber

        if isNotOnBreak or isWorkDay:
            print("\n<br>&nbsp;&nbsp;&nbsp;&nbsp;%s, %s" % (
                date,
                getDayName(dayNumber, verbose),
            ))

        if breakName:
            print("\n<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%s" %
                  breakName)

        if isNotOnBreak:
            ringTimes = findRingTimes(date, dayNumber, cursor, verbose)
            if ringTimes:
                for ringTime in ringTimes:
                    print(
                        "\n<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
                    )
                    print(("%s, %s" % (
                        ringTime["ringTime"],
                        ringTime["ringTimeName"],
                    )))
                    print(
                        "\n<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
                    )
                    print(("%s, %s" % (
                        ringTime["ringPatternName"],
                        ringTime["ringPattern"],
                    )))

        i += 1
        if i >= 30:
            break
        else:
            date = datetime.strptime(date,
                                     "%Y-%m-%d")  # convert to time object
            date = date + timedelta(days=1)  # add one day
            date = datetime.strftime(date, "%Y-%m-%d")  # convert to string
Esempio n. 2
0
        cacheTime = parsedCalendar["cachetid"]

        day = 0

        while True:  # will keep on running as long as there is days in a month

            try:  # does this month have this day
                date = parsedCalendar["dagar"][day]["datum"]
            except:  # month finished
                break

            weekNumber = int(parsedCalendar["dagar"][day]["vecka"])
            dayNumber = int(parsedCalendar["dagar"][day]["dag i vecka"]) - 1
            svDayName = parsedCalendar["dagar"][day]["veckodag"]
            dayName = getDayName(dayNumber, verbose)
            workFreeDay = parsedCalendar["dagar"][day]["arbetsfri dag"]

            try:  # is this day an eve
                eve = parsedCalendar["dagar"][day]["helgdagsafton"]
            except:
                eve = ""

            try:  # is this day an eve
                holiday = parsedCalendar["dagar"][day]["helgdag"]
            except:
                holiday = ""

            if verbose:
                print "\n*** Date: %s, %s" % (date, dayName)
                if workFreeDay == "Nej":
Esempio n. 3
0
def pageBody():

    # get ring times
    query = (
        "SELECT ringTimeId, ringTimeName, weekDays, TIME_FORMAT(ringTime, '%H:%i') as ringTime, ringPatternId "
        "FROM ringTimes ORDER BY ringTime ASC"
    )
    result, rowCount = db_query(cursor, query, verbose)  # run query
    if rowCount:  # display ring times in a table
        print("\n<br>\n<br>")
        print('<table style="width:100%">')
        print("<tr>")
        print("<th>Id</th>")
        print("<th>Time name</th>")
        print("<th>Ring time</th>")
        print("<th>Ring pattern id</th>")
        print("<th>Ring pattern name</th>")
        print("<th>Ring pattern</th>")
        for dayNumber in range(0, 7):
            print("<th>%s</th>" % getDayName(dayNumber, verbose))

        print("<th></th>")
        print("<th></th>")
        print("</tr>")

        for row in result:
            ringTimeId = row[0]
            ringTimeName = row[1]
            weekDays = row[2]
            ringTime = row[3]
            ringPatternId = row[4]

            if editRingTimeId == str(
                ringTimeId
            ):  # this is the ringTime we are about to edit
                editRingTimeName = ringTimeName
                editWeekDays = weekDays
                editRingTime = ringTime
                editRingPatternId = ringPatternId

            print("<tr>")
            print("<th>%s</th>" % ringTimeId)
            print("<th>%s</th>" % ringTimeName)
            print("<th>%s</th>" % ringTime)
            print("<th>%s</th>" % ringPatternId)
            # get ring patterns
            query = (
                "SELECT ringPatternName, ringPattern FROM ringPatterns "
                "WHERE ringPatternID = '" + str(ringPatternId) + "'"
            )
            result, rowCount = db_query(cursor, query, verbose)  # run query
            if rowCount:
                for row in result:
                    ringPatternName = row[0]
                    ringPattern = row[1]
            print("<th>%s</th>" % ringPatternName)
            print("<th>%s</th>" % ringPattern)
            for dayNumber in range(0, 7):  # print day name
                if weekDays[dayNumber] == "1":
                    print("<th>On</th>")
                else:
                    print("<th>Off</th>")
            print('<th><a href="ringTimes.py?deleteRingTimeId=%s">Delete</a></th>' % ringTimeId)
            print('<th><a href="ringTimes.py?editRingTimeId=%s">Edit</a></th>' % ringTimeId)
            print("</tr>")

        print("</table")

    if editRingTimeId:
        print("\n<br><br>")
        print("<h3>Edit ring time</h3>")

        print('<form action="/ringTimes.py">')

        print("Time id:<br>")
        print('<input type="text" name="updateRingTimeId" value="%s">' % editRingTimeId)

        print("<br><br><br>")
        print("Ring time name:<br>")
        print('<input type="text" name="updateRingTimeName" value="%s">' % editRingTimeName)
        print ("State a name for your ring time. <br><br>" "\nMax 100 characters. <br>")

        print("<br><br>")
        print("Ring time:<br>")
        print('<input type="text" name="updateRingTime" value="%s">' % editRingTime)
        print ('State time in the form "hh:mm". <br>')

        print("<br><br>")
        print("Choose ring pattern:<br>")
        print('<select name="newRingPatternId">')
        # get ring patterns
        query = "SELECT ringPatternId, ringPatternName, ringPattern FROM ringPatterns"
        result, rowCount = db_query(cursor, query, verbose)  # run query
        if rowCount:
            for row in result:
                ringPatternId = row[0]
                ringPatternName = row[1]
                ringPattern = row[2]

                isSelected = ""
                if ringPatternId == editRingPatternId:
                    isSelected = 'selected="selected"'

                print((
                    '<option value="%s" %s>%s: %s, %s</option>'
                    % (
                        ringPatternId,
                        isSelected,
                        ringPatternId,
                        ringPatternName,
                        ringPattern,
                    )
                ))
        print("</select>")

        print("<br><br>")
        for dayNumber in range(0, 7):

            isChecked = ""
            if str(editWeekDays)[dayNumber] == "1":
                isChecked = 'checked="checked"'

            print((
                '<input type="checkbox" name="%s" value="1" %s> %s<br>'
                % (
                    getDayName(dayNumber, verbose),
                    isChecked,
                    getDayName(dayNumber, verbose),
                )
            ))

        print("<br><br>")
        print('<input type="submit" value="Submit">')
        print("</form>")

    if addRingTime:  # display form to add ring time
        print("\n<br><br>")
        print("<h3>Add ring time</h3>")

        print('<form action="/ringTimes.py">')

        print("Ring time name:<br>")
        print('<input type="text" name="newRingTimeName" value="Time name">')
        print ("State a name for your ring time. <br><br>" "\nMax 100 characters. <br>")

        dateTimeNow = datetime.now()
        timeNow = dateTimeNow.strftime("%H:%M")
        print("<br><br>")
        print("Ring time:<br>")
        print('<input type="text" name="newRingTime" value="%s">' % timeNow)
        print ('State time in the form "hh:mm". <br>')

        print("<br><br>")
        print("Choose ring pattern:<br>")
        print('<select name="newRingPatternId">')
        # get ring patterns
        query = "SELECT ringPatternId, ringPatternName, ringPattern FROM ringPatterns"
        result, rowCount = db_query(cursor, query, verbose)  # run query
        if rowCount:
            for row in result:
                ringPatternId = row[0]
                ringPatternName = row[1]
                ringPattern = row[2]
                print((
                    '<option value="%s">%s: %s, %s</option>'
                    % (ringPatternId, ringPatternId, ringPatternName, ringPattern)
                ))
        print("</select>")

        print("<br><br>")
        for dayNumber in range(0, 7):

            isChecked = ""
            if dayNumber >= 0 and dayNumber <= 4:
                isChecked = 'checked="checked"'

            print((
                '<input type="checkbox" name="%s" value="1" %s> %s<br>'
                % (
                    getDayName(dayNumber, verbose),
                    isChecked,
                    getDayName(dayNumber, verbose),
                )
            ))

        print("<br><br>")
        print('<input type="submit" value="Submit">')
        print("</form>")