Last active
May 4, 2019 07:21
-
-
Save sakage24/0253c85b055b29cc28ca3de03e8b43c0 to your computer and use it in GitHub Desktop.
Chromeのダウンロード後に自動でシャットダウンするスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os, sys | |
| from time import sleep | |
| TARGET_PATH = os.path.expanduser("~") + "\\Desktop" # ダウンロード先のフォルダを指定 | |
| STAND_BY_INIT = 120 # 再実行までの待機時間 | |
| TARGET_EXEC = [".crdownload", ".mega"] | |
| MIN = 60 | |
| SEC = MIN - STAND_BY_INIT # 現在の待機秒数 | |
| def shutdown(): | |
| print("shutdown開始~") | |
| os.system("shutdown -s -t 0") # すぐにシャットダウン | |
| sys.exit(0) # 正常終了 | |
| def cr_not_exists(): | |
| """*.crdownloadファイルが存在しないかどうかを判定する。 | |
| 存在しない = True | |
| 存在する = False | |
| 存在した場合はダウンロード中なのでシャットダウンしない。 | |
| 存在しない場合はダウンロードが終了したと見做すことが出来るためTrueなのだ。 | |
| なぜか自分はこんがらがったのでメモ代わりに... | |
| """ | |
| for lists in os.listdir("."): | |
| li = os.path.splitext(lists)[1] | |
| for target in TARGET_EXEC: | |
| if li.count(target): | |
| print("ファイル名: " + lists + "をダウンロード中です...") | |
| return True | |
| else: | |
| print("ファイル名: " + lists + "をスキップします") | |
| return False | |
| os.chdir(TARGET_PATH) | |
| print(os.getcwd()) | |
| if not cr_not_exists(): | |
| shutdown() | |
| while(True): | |
| print(str(MIN - SEC) + "秒後に処理を再開します...") | |
| while(SEC != MIN): | |
| sleep(1) | |
| SEC += 1 | |
| print(str(MIN - SEC) + "秒後に処理を再開します...") | |
| if not cr_not_exists(): | |
| shutdown() | |
| SEC = MIN - STAND_BY_INIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment