-
Notifications
You must be signed in to change notification settings - Fork 0
/
alarm.py
57 lines (41 loc) · 1.91 KB
/
alarm.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Patrick Mogianesi
# Updated /Augest 24 2016/
# This stack overflow helped http://stackoverflow.com/questions/3277503/how-to-read-a-file-line-by-line-into-a-list-with-python
#Import libraries
import time
import webbrowser
import random
import os
#Check if the user has the YT.txt file in the same area as alarm.py
if os.path.isfile("YT.txt") == False:
print "ERROR: YT.txt file not present. Creating file..."
flags = os.O_CREAT | os.O_EXCL | os.O_WRONLY
filecreate = os.open("YT.txt", flags)
with os.fdopen(fisierCreat, 'w') as fileCreated:
fileCreated.write("https://youtu.be/BZg8BhBWyo8")
#The User can set the time they want to wake up. The String the user puts in must be the same as the example to work.
print "What time would you like to wake up?"
print "Use this form.\nExample: 08:30"
Alarm = raw_input("> ")
#I first need to state the Time variable so it's usable in the while-loop
Time = time.strftime("%H:%M")
#This opens the text file with the youtube links
with open("YT.txt") as f:
#the urls are stored in the content variable
content = f.readlines()
#When the Time does not equal the Alarm time string given above, print the time
while Time != Alarm:
print "The time is " + Time
#Restating the Time variable allows the time to refresh
#When I tried keeping the variable outside of the loop it just repeated the inital time
Time = time.strftime("%H:%M")
#This keeps the loop from flooding the command line with updates of the time :P
time.sleep(1)
#If the Time variable is equal to the Alarm string, this code activates
if Time == Alarm:
print "Time to Wake up!"
#from the variable content, a random link is chosen and then that link is stored in random_video variable
random_video = random.choice(content)
#Using the webbrowser library, it opens this youtube video link.
#The videos are varius aphex twin songs
webbrowser.open(random_video)