def helpsettings():
    global reminderlist
    if request.method == "GET":
        if session.has_key("user") and session["user"] != "":
            tmp = util.getCurrentTime(session["user"])
            time = tmp.split(":")
            if "am" in time[1]:
                amorpm = "am"
            else:
                amorpm = "pm"
            hour = time[0]
            minute = time[1][:-2]
            tmpone = util.getStatus(session["user"])
            return render_template(
                "helpsettings.html",
                minutes=minutelist,
                hourselected=int(hour),
                minuteselected=minute,
                ampm=amorpm,
                enabled=tmpone,
            )
    else:
        if request.form.has_key("Back"):
            return redirect(url_for("calendar", year=int(util.thisYear()), month=util.thisMonth()))
        if request.form.has_key("Submit"):
            hour = request.form["hourselector"]
            minute = request.form["minuteselector"]
            amorpm = request.form["ampmselect"]
            reminders = request.form["enabledselect"]
            hour = str(hour)
            if int(hour) < 10:
                hour = "0" + hour
            newtime = hour + ":" + minute + amorpm
            util.setTime(util.getUserNumber(session["user"]), newtime)
            currentEnabled = util.getStatus(session["user"])
            if currentEnabled == True and reminders == "dis":
                util.changeStatus(util.getUserNumber(session["user"]))
            if currentEnabled == False and reminders == "en":
                util.changeStatus(util.getUserNumber(session["user"]))
            reminderlist = util.getReminderTimes()
            if threading.activeCount() > 1:
                threading.enumerate()[1].cancel()
            remindersHandler(True, 0)
            return redirect(url_for("helpsettings"))
Example #2
0
def helpsettings():
    global reminderlist
    if request.method =='GET':
        if session.has_key('user') and session['user'] != '':
            tmp = util.getCurrentTime(session['user'])
            time = tmp.split(':')
            if 'am' in time[1]:
                amorpm = 'am'
            else:
                amorpm = 'pm'
            hour = time[0]
            minute = time[1][:-2]
            tmpone = util.getStatus(session['user'])
            return render_template('helpsettings.html',minutes=minutelist,hourselected=int(hour),minuteselected=minute,ampm=amorpm,enabled=tmpone)
    else:
        if request.form.has_key('Back'):
            return redirect(url_for('calendar',year=int(util.thisYear()),month=util.thisMonth()))
        if request.form.has_key('Submit'):
            hour = request.form['hourselector']
            minute = request.form['minuteselector']
            amorpm = request.form['ampmselect']
            reminders = request.form['enabledselect']
            hour = str(hour)
            if int(hour) < 10:
                hour = "0" + hour
            newtime = hour+":"+minute+amorpm
            util.setTime(util.getUserNumber(session['user']),newtime)
            currentEnabled = util.getStatus(session['user'])
            if currentEnabled == True and reminders == 'dis':
                util.changeStatus(util.getUserNumber(session['user']))
            if currentEnabled == False and reminders == 'en':
                util.changeStatus(util.getUserNumber(session['user']))
            reminderlist = util.getReminderTimes()
            if threading.activeCount() > 1:
                threading.enumerate()[1].cancel()
            remindersHandler(True,0)
            return redirect(url_for('helpsettings'))
Example #3
0
def remindersHandler(initial,waitTime):
    #threading.Event().wait(waitTime)
    global reminderlist
    os.environ['TZ'] = 'US/Eastern'
    time.tzset()
    timenow = time.strftime("%H:%M:%S",time.localtime())
    tmp = timenow.split(":")
    if (not initial):
        if tmp[0] == "00":
            tmp[0] = "0"
        for user in reminderlist[str(tmp[0])+":"+str(tmp[1])]:
            if util.remindersEnabled(user):
                message = util.eventsToMessage(util.getEventsToday(user))
                if message != "":
                    util.sendSomething(util.getUserNumber(user),message)
    times = reminderlist.keys()
    timeinsecsnow = 0
    timeinsecsnext = 0
    timeinsecsprev = 0
    nextTime = 0
    hournow = int(tmp[0])
    minutenow = int(tmp[1])
    secnow = int(tmp[2])
    found = False
    timeinsecsnextperm = 86000
    timeinsecsleast = 86000
    timeinsecsnow = hournow*3600 + minutenow*60 + secnow
    for item in times:
        itemhour = int(item.split(":")[0])
        itemminute = int(item.split(":")[1])
        timeinsecsnext = itemminute*60 + itemhour*3600
        if timeinsecsnext < timeinsecsleast:
            timeinsecsleast = timeinsecsnext
        if timeinsecsnow < timeinsecsnext:
            if timeinsecsnextperm > timeinsecsnext:
                found = True
                timeinsecsnextperm = timeinsecsnext
    if not found:
        timeinsecsnextperm = timeinsecsleast
    nextTime = timeinsecsnextperm - timeinsecsnow
    if nextTime < 0:
        nextTime = (timeinsecsnextperm+86400) - timeinsecsnow
    arguments = (False,nextTime)
    reminder = threading.Timer(nextTime,remindersHandler,args=arguments)
    reminder.setDaemon(True)
    reminder.start()