23
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Pythonで座りっぱなしと水分補給不足を解消する

Last updated at Posted at 2021-04-21

水分補給を忘れると頭の回転が悪くなるし体にも悪いらしいです。
長時間座り続けるのはさらに悪影響がありそうです。
現在ウェルネス・ウェルビーイング市場が良い感じらしいので健康になれるWindowsアプリを作りました。

だいたい1時間ごとに立つことを促して、その一分後に再度座ることを許可する旨の通知が来ます。
また同様に水分補給を促すメッセージも画面右下に表示します。
image.png
こんな感じ

#使い方とソース
pipで win10toastとschedule, configparserをinstallしてください。

Reminderchan.py
from win10toast import ToastNotifier
import time
import schedule
import random
import configparser

toaster = ToastNotifier()

def remind(msg):
    toaster.show_toast(msg)
    print("notification sent!")


def main():
    config_ini = configparser.ConfigParser()
    config_ini.read("config.ini", encoding="utf-8")
    wakeup = int(config_ini["DEFAULT"]["wakeup"])
    sleep = int(config_ini["DEFAULT"]["sleep"])
    lang = config_ini["DEFAULT"]["lang"]
    print("Your wakeup time is {} and you are scheduled to sleep at {}. your language is {}".format(wakeup,sleep,lang))
    if lang == "jp":
        for hour in range(wakeup,sleep):
            hour = str(hour).zfill(2)
            rdm = random.randint(-20,20)
            rdm2 = random.randint(-20,20)
            minute = 30-rdm
            print("{}:{}にスタンドのお知らせを出します".format(hour,minute))
            print("{}:{}に水分補給のお知らせを出します".format(hour,30-rdm2))
            schedule.every().day.at("{}:{}".format(hour,minute)).do(remind, "立ちましょう。1分程立ってストレッチしましょう")
            schedule.every().day.at("{}:{}".format(hour,minute+1)).do(remind, "もう座っても大丈夫です。")
            schedule.every().day.at("{}:{}".format(hour,30-rdm2)).do(remind, "水を80ml程度飲みましょう")
        ct = 0
        while True:
            schedule.run_pending()
            if ct%3600 == 0:
                print("機能チェック")
            ct += 1
            time.sleep(1)
    elif lang == "en":
        for hour in range(wakeup,sleep):
            hour = str(hour).zfill(2)
            rdm = random.randint(-20,20)
            rdm2 = random.randint(-20,20)
            minute = 30-rdm
            print("I will pop stand up notification at {}:{}".format(hour,minute))
            print("I will pop up hydration notification at {}:{}".format(hour,30-rdm2))
            schedule.every().day.at("{}:{}".format(hour,minute)).do(remind, "Time to Stand! Let's start stretching for 1 minute")
            schedule.every().day.at("{}:{}".format(hour,minute+1)).do(remind, "You may sit now.")
            schedule.every().day.at("{}:{}".format(hour,30-rdm2)).do(remind, "Please drink at least 80 ml of water to hydrate yourself!")
        ct = 0
        while True:
            schedule.run_pending()
            if ct%3600 == 0:
                print("Functionality check")
            ct += 1
            time.sleep(1)
    else:
        print("something is wrong with config reading process.")
#1時間に80ml
#スタンド1時間程度に一回 1分程
if __name__ == "__main__":
    #test
    remind("Remineder starts!")
    main()
"""
MIT License

Copyright (c) 2021 Lulu-Gustav der Große

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE."""

24時間ずっと通知が来るのもうざいので起きている時間だけ通知が来るように制限をかけます。
config.iniでいつもの起床時間と寝る時間を設定してください。
一応lang = en にすると英語でメッセージが来ます。

config.ini
[DEFAULT]
wakeup = 9
sleep = 23
lang = jp

気を抜くと24時間座ってしまうので個人的には便利です。

23
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?