コード例 #1
0
ファイル: views.py プロジェクト: topotal/alarm
def set(request):

    for key in request.POST:
        print key, request.POST[key]

    hour = int(request.POST["hour"])
    minute = int(request.POST["minute"])
    repeat_sunday = int(request.POST["repeat_sunday"])
    repeat_monday = int(request.POST["repeat_monday"])
    repeat_tuesday = int(request.POST["repeat_tuesday"])
    repeat_wednesday = int(request.POST["repeat_wednesday"])
    repeat_thursday = int(request.POST["repeat_thursday"])
    repeat_friday = int(request.POST["repeat_friday"])
    repeat_saturday = int(request.POST["repeat_saturday"])

    if Schedule.is_exists():
        Schedule.update_alarm(hour, minute, repeat_sunday, repeat_monday,
                              repeat_tuesday, repeat_wednesday, repeat_thursday,
                              repeat_friday, repeat_saturday)
        print hour, minute, repeat_sunday, repeat_monday
        return HttpResponse('[{"message": "OK"}]', content_type='application/json')
    else:
        Schedule.create_alarm(hour, minute, repeat_sunday, repeat_monday,
                              repeat_tuesday, repeat_wednesday, repeat_thursday,
                              repeat_friday, repeat_saturday)

        return HttpResponse('[{"message": "OK"}]', content_type='application/json')

    return HttpResponseNotFound('[{"message": "Page Not Found."}]', content_type='application/json')
コード例 #2
0
ファイル: views.py プロジェクト: topotal/alarm
def get_schedule(request):
    has_schdule = Schedule.is_exists()
    if has_schdule:
        schedule = Schedule.objects.all()
        _json = serializers.serialize('json', schedule, ensure_ascii=False)
        return HttpResponse(_json, content_type='application/json')
    else:
        return HttpResponse('[{"message": "None"}]', content_type='application/json')
コード例 #3
0
ファイル: tasks.py プロジェクト: topotal/alarm
def watch_schedule():
    now = datetime.datetime.now()
    weekday = now.weekday()
    has_schdule = Schedule.is_exists()
    if has_schdule:
        schedule = Schedule.objects.all().get()
        repeat_flg_list = []
        play_flg = False
#        target_schedule = None

        repeat_flg_list.append(schedule.repeat_monday)
        repeat_flg_list.append(schedule.repeat_tuesday)
        repeat_flg_list.append(schedule.repeat_wednesday)
        repeat_flg_list.append(schedule.repeat_thursday)
        repeat_flg_list.append(schedule.repeat_friday)
        repeat_flg_list.append(schedule.repeat_saturday)
        repeat_flg_list.append(schedule.repeat_sunday)

        has_repeat_flg = False
        for repeat_flg in repeat_flg_list:
            if repeat_flg:
                has_repeat_flg = True
                break

        if schedule.hour is now.hour and schedule.minute is now.minute:
            if has_repeat_flg:
                if repeat_flg_list[weekday]:
                    play_flg = True
            else:
                play_flg = True
#                target_schedule = schedule

        if play_flg:
            alarm_key = generate_alarm_key()
            pool = redis.ConnectionPool(host='localhost', port=6379, db=1)
            r = redis.Redis(connection_pool=pool)
            r.hmset('alarm_key', alarm_key)
            start_music.delay()

            if not has_repeat_flg:
                schedule.delete()