일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 라이브러리 #IT지식 #CS지식
- 백준 #알고리즘
- Java #객체지향 # 프로그래밍 # SOLID #OOP
- 알고리즘 #백준 #집합과맵
- 추상클래스 #인터페이스
- 문자열
- GPT #챗봇
- 스톱워치
- Anaconda #가상환경
- 맵핑
- Python
- 프로그래머스 #파이썬 #python #슬라이싱 #코딩
Archives
- Today
- Total
고통은 사라지고 결과는 남는다. Records of Chansolve
알람 맞추기, 컴퓨터종료, 퇴근하자! [파이썬] 본문
업무 중 심심해서 알람을 만들었다.
그냥 주파수로 알려주는 코드이다.
import time
import winsound
# 17시59분이 되면 알람 울리기
while True:
now = time.localtime()
if now.tm_hour == 17 and now.tm_min == 59:
print("알람 울립니다!")
winsound.Beep(440, 1000) # 440 Hz 주파수로 1초 동안 소리 울리기
break
else:
time.sleep(60) # 1분 대기 후 다시 검사 ctrl + c로 종료
심심해서 파이썬으로 알람을 맞춰보았다.
진짜로 되는지 궁금해서 켜봤다가 깜짝놀랐다.
다음은 url을 열어서 노래를 틀어준다. 주의사항!! 크롬으로 열어둔 사이트는 다 꺼져버린다... 마치 암살자?
import time
import webbrowser
import os
# 17시59분이 되면 알람 울리기
while True:
now = time.localtime()
if now.tm_hour == 17 and now.tm_min == 59:
print("알람 울립니다!")
url = "https://www.youtube.com/watch?v=lqFby1rSGyI"
webbrowser.open(url)
break
else:
time.sleep(100)
print("알람 다시 울립니다!")
위 코드는 url을 열어주기만해서 시끄러웠다.
이 코드는 url을 다시 닫아주는 코드이다. while문을 두번 알람이 울리게 바꿔 놓았다.
주석처리 한것은 컴퓨터까지 꺼주는 기능이니 필요할 때만 사용하도록 하자.
import time
import webbrowser
import os
while True:
now = time.localtime()
if now.tm_hour == 11 and now.tm_min == 53:
print("알람 울립니다!")
url = "https://www.youtube.com/watch?v=lqFby1rSGyI"
webbrowser.open(url)
time.sleep(30)
os.system("taskkill /im chrome.exe /f")
time.sleep(60) # 1분 대기
url = "https://www.youtube.com/watch?v=lqFby1rSGyI"
webbrowser.open(url)
time.sleep(30)
break
# os.system("shutdown /s /t 1" 컴퓨터 종료
이제 코드를 하나로 합쳐보겠습니다. 다들 퇴근하세요
import calendar
import datetime
import time
import webbrowser
import os
today = calendar.datetime.date.today()
print(calendar.month(today.year, today.month))
now = datetime.datetime.now()
print("현재 시간은 ", now.strftime('%Y-%m-%d %H:%M'))
while True:
now = time.localtime()
if now.tm_hour == 18 and now.tm_min == 00:
print("알람 울립니다!")
url = "https://youtu.be/xbO1CY1PXkE"
webbrowser.open(url)
time.sleep(30)
os.system("taskkill /im chrome.exe /f")
time.sleep(60) # 1분 대기
print("마지막 알람입니다!")
url = "https://youtu.be/xbO1CY1PXkE"
webbrowser.open(url)
now = datetime.datetime.now()
print("현재 시간은 ", now.strftime('%Y-%m-%d %H:%M'))
time.sleep(30)
print("컴퓨터 종료합니다!")
os.system("shutdown /s /t 1")
break
진짜 너무 아쉬워서 진짜최종 찐찐찐 막 으로 하나 더 수정했습니다.
종료 전 모든 프로세서를 종료하고 30초 카운트 하는 코드입니다.
어제 수정 안된거 켜놨더니 틱 꺼져버리네요,,
import calendar
import datetime
import time
import webbrowser
import os
today = calendar.datetime.date.today()
print(calendar.month(today.year, today.month))
now = datetime.datetime.now()
print("현재 시간은", now.strftime('%Y-%m-%d %H:%M'), '입니다.')
while True:
now = time.localtime()
if now.tm_hour == 18 and now.tm_min == 2:
print("알람 울립니다!")
url = "https://youtu.be/xbO1CY1PXkE"
webbrowser.open(url)
time.sleep(30)
os.system("taskkill /im chrome.exe /f")
time.sleep(60) # 1분 대기
print("마지막 알람입니다!")
url = "https://youtu.be/xbO1CY1PXkE"
webbrowser.open(url)
now = datetime.datetime.now()
print("현재 시간은", now.strftime('%Y-%m-%d %H:%M'), '입니다.')
time.sleep(30)
print("시스템 종료합니다!")
os.system('taskkill /f /im explorer.exe') # 시스템 종료
os.system('taskkill /f /im MicrosoftEdge.exe') # 시스템 종료
os.system('taskkill /f /im chrome.exe') # 시스템 종료
print("30초 후 컴퓨터 종료합니다!")
print("현재 시간은", now.strftime('%Y-%m-%d %H:%M'), "오늘도 고생하셨습니다.")
cnt = 30
while cnt >= 0:
cnt -= 1
time.sleep(1)
print(cnt,'초 후 컴퓨터를 종료합니다.')
if cnt == 0:
os.system('shutdown /s /t 0') # 컴퓨터 종료
설명은 주석을 달았습니다.
'Algorithms' 카테고리의 다른 글
백준 Python 문자와 문자열 27866번 (0) | 2023.03.28 |
---|---|
지금 날짜와 시간은 언제지.. (0) | 2023.03.08 |
백준 Python 코딩은 체육과목 입니다 25314번 (0) | 2023.03.03 |
백준 Python 꼬마정민 11382번 (0) | 2023.02.28 |
백준 Python 알고리즘 수업 - 알고리즘의 수행 시간 3 24264번 (0) | 2023.02.24 |
Comments