Skip to content

Commit 3a2259d

Browse files
author
Ubuntu
committed
Fixed merge conflict in README.md
2 parents 18a3fa3 + ff137a7 commit 3a2259d

File tree

1,666 files changed

+306179
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,666 files changed

+306179
-0
lines changed

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM python:3.10
2+
WORKDIR /app
3+
COPY . /app
4+
RUN pip install -r requirements.txt
5+
CMD ["python", "app.py"]

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1+
HEAD
12
# alarm
3+
HEAD
4+
# Flask Alarm Clock - alarmaws
5+
6+
This is a simple alarm clock web app built with Flask.
7+
# Update
8+
88074e3 (Initial commit)
9+
ff137a72e62d74f512f362982816ccffadb6016a

app.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
from flask import Flask, render_template_string, request, redirect, url_for
2+
from threading import Thread
3+
import time
4+
from datetime import datetime
5+
6+
app = Flask(__name__)
7+
8+
alarms = []
9+
ring_alarm = False
10+
11+
html_template = """
12+
<!DOCTYPE html>
13+
<html>
14+
<head>
15+
<title>Flask Alarm Clock</title>
16+
<style>
17+
body { font-family: Arial, sans-serif; text-align: center; padding-top: 50px; }
18+
input[type=number] { width: 50px; }
19+
.alarm-time { margin: 10px 0; }
20+
#alarmPopup {
21+
display: none;
22+
position: fixed;
23+
top: 20%;
24+
left: 50%;
25+
transform: translateX(-50%);
26+
background: #ffdddd;
27+
padding: 20px;
28+
border: 2px solid red;
29+
border-radius: 10px;
30+
font-size: 24px;
31+
z-index: 1000;
32+
}
33+
</style>
34+
</head>
35+
<body>
36+
<h1>Flask Alarm Clock</h1>
37+
<h2 id="clock">{{ current_time }}</h2>
38+
39+
<form method="POST">
40+
<label>Set Alarm Time (24h format):</label><br>
41+
<input type="number" name="hour" min="0" max="23" required> :
42+
<input type="number" name="minute" min="0" max="59" required>
43+
<button type="submit">Set Alarm</button>
44+
</form>
45+
46+
{% if alarm_set %}
47+
<p>⏰ Alarm set for {{ alarm_hour }}:{{ alarm_minute }}</p>
48+
{% endif %}
49+
50+
<h3>Active Alarms:</h3>
51+
<ul>
52+
{% for alarm in alarms %}
53+
<li>{{ alarm }} <a href="/delete/{{ alarm }}">Delete</a></li>
54+
{% endfor %}
55+
</ul>
56+
57+
<audio id="alarmSound" src="{{ url_for('static', filename='alarm.mp3') }}"></audio>
58+
<div id="alarmPopup">⏰ Alarm Ringing!</div>
59+
60+
<script>
61+
// Live clock
62+
setInterval(() => {
63+
const now = new Date();
64+
const timeStr = now.toLocaleTimeString('en-GB');
65+
document.getElementById("clock").innerText = timeStr;
66+
}, 1000);
67+
68+
{% if ring_alarm %}
69+
document.getElementById("alarmPopup").style.display = "block";
70+
const sound = document.getElementById("alarmSound");
71+
sound.play();
72+
{% endif %}
73+
</script>
74+
</body>
75+
</html>
76+
"""
77+
78+
@app.route("/", methods=["GET", "POST"])
79+
def index():
80+
global ring_alarm
81+
alarm_set = False
82+
alarm_hour = alarm_minute = None
83+
84+
if request.method == "POST":
85+
hour = request.form.get("hour")
86+
minute = request.form.get("minute")
87+
if hour is not None and minute is not None:
88+
alarm_time = f"{hour.zfill(2)}:{minute.zfill(2)}"
89+
alarms.append(alarm_time)
90+
alarm_set = True
91+
alarm_hour = hour
92+
alarm_minute = minute
93+
94+
now = datetime.now()
95+
current_time = now.strftime("%H:%M:%S")
96+
97+
ring = ring_alarm
98+
ring_alarm = False # Reset flag
99+
100+
return render_template_string(html_template,
101+
current_time=current_time,
102+
alarm_set=alarm_set,
103+
alarm_hour=alarm_hour,
104+
alarm_minute=alarm_minute,
105+
alarms=alarms,
106+
ring_alarm=ring)
107+
108+
@app.route("/delete/<alarm>")
109+
def delete_alarm(alarm):
110+
if alarm in alarms:
111+
alarms.remove(alarm)
112+
return redirect(url_for("index"))
113+
114+
def alarm_checker():
115+
global ring_alarm
116+
while True:
117+
now = datetime.now()
118+
now_time = now.strftime("%H:%M")
119+
if now_time in alarms:
120+
print("⏰ Alarm ringing!")
121+
ring_alarm = True
122+
time.sleep(60)
123+
time.sleep(1)
124+
125+
# Background thread
126+
thread = Thread(target=alarm_checker)
127+
thread.daemon = True
128+
thread.start()
129+
130+
if __name__ == "__main__":
131+
app.run(host='0.0.0.0', port=5000, debug=True)
132+
133+

requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
blinker==1.9.0
2+
click==8.1.8
3+
Flask==3.1.0
4+
itsdangerous==2.2.0
5+
Jinja2==3.1.6
6+
MarkupSafe==3.0.2
7+
Werkzeug==3.1.3

static/alarm.mp3

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2+
"http://www.w3.org/TR/html4/strict.dtd">
3+
<html>
4+
<head>
5+
<meta http-equiv="Content-Type" content="text/html;
6+
charset=iso-8859-1">
7+
<title>Image Download</title>
8+
</head>
9+
<body>
10+
<h1>Download Failed</h1>
11+
<p>The error message is: Requested file is not available</p>
12+
</body>
13+
</html>

templates/alarm.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Flask Alarm Clock</title>
5+
</head>
6+
<body>
7+
<h1>Set Alarm Time</h1>
8+
<form method="post">
9+
<label>Alarm Time (24h format):</label>
10+
<input type="number" name="hour" min="0" max="23" required> :
11+
<input type="number" name="minute" min="0" max="59" required>
12+
<button type="submit">Set Alarm</button>
13+
</form>
14+
</body>
15+
</html>
16+

0 commit comments

Comments
 (0)