269 Commits

Author SHA1 Message Date
星光-k
1ac9ca91ef Update weather.py 2025-05-09 00:46:43 +08:00
星光-k
5c8d24f43c Update main.py 2025-05-09 00:46:14 +08:00
星光-k
13adf24df4 Update weather.py 2025-03-15 11:01:52 +08:00
星光-k
09c6c3c7ac Update README.md 2025-02-08 20:15:29 +08:00
星光-k
caf0228277 Update README.md 2025-02-08 19:17:44 +08:00
星光-k
54b76b4d26 Update install.sh 2025-02-08 18:56:22 +08:00
星光-k
f25f0d8dcf Update install.sh 2025-02-08 15:01:20 +08:00
星光-k
8f0fd2e6d6 Delete bin/vendor/1 2025-02-08 14:59:05 +08:00
星光-k
7350d120ad Add files via upload 2025-02-08 06:58:26 +00:00
星光-k
db8c4344ba Create 1 2025-02-08 14:57:23 +08:00
星光-k
7759cabcf0 Update install.sh 2025-02-08 13:56:42 +08:00
星光-k
a56b337975 Rename requirements.txt to bin/requirements.txt 2025-02-08 13:50:06 +08:00
星光-k
7cd6136696 Add files via upload 2025-02-08 05:49:03 +00:00
星光-k
569852a1dc 更新 weather.py 2025-02-08 01:17:52 +00:00
星光-k
7c48d92bc1 更新 main.py 2025-02-08 00:59:44 +00:00
星光-k
9b3afeb323 Update start.sh 2025-01-27 21:52:38 +08:00
星光-k
2d3459f3d0 更新 clock.py 2025-01-23 15:21:54 +00:00
星光-k
c05eb73fb6 更新 main.py1 2025-01-23 15:21:34 +00:00
星光-k
b9cd0bab9d 更新 main.py 2025-01-23 15:20:47 +00:00
星光-k
db174e366d Update main.py 2025-01-23 12:30:07 +08:00
星光-k
0c4f04e612 Update clock.py 2025-01-23 12:29:23 +08:00
星光-k
a0f636a8d5 Update main.py 2025-01-23 12:26:28 +08:00
星光-k
d0fe962c06 Update clock.py 2025-01-23 11:35:51 +08:00
星光-k
8d3bb91ed3 Update weather.py 2025-01-23 11:10:45 +08:00
星光-k
9d69de92f2 Update main.py 2025-01-23 08:30:19 +08:00
星光-k
77fef0187e Add files via upload 2025-01-22 05:41:51 +00:00
星光-k
19177a14ba 更新 main.py 2025-01-21 16:23:15 +00:00
星光-k
6d7fdab6e1 更新 main.py 2025-01-21 15:46:36 +00:00
星光-k
3842f61add 更新 main.py 2025-01-21 14:08:26 +00:00
星光-k
f1a2e59e4b 更新 main.py 2025-01-21 13:46:07 +00:00
星光-k
b8c1df3ee2 Update README.md 2025-01-21 13:46:38 +08:00
星光-k
da6b99e99c Add files via upload 2025-01-21 05:46:11 +00:00
星光-k
01ea753627 Add files via upload 2025-01-21 05:43:27 +00:00
星光-k
4c3fefa9ff Update README.md 2025-01-21 13:41:02 +08:00
星光-k
c7275aa400 Update README.md 2025-01-21 13:40:47 +08:00
星光-k
a1e9356c83 Update README.md 2025-01-21 13:40:27 +08:00
星光-k
914129a181 Update main.py 2025-01-21 13:38:15 +08:00
星光-k
c0d776da36 更新 clean.sh 2025-01-21 00:53:36 +00:00
星光-k
7a76aef402 更新 e-Paper_clean.servic 2025-01-20 23:19:27 +00:00
星光-k
c3666059ce 更新 clean.sh 2025-01-20 23:16:51 +00:00
星光-k
dfae4181cb 更新 e-Paper_clean.service 2025-01-20 23:16:32 +00:00
星光-k
0085656d20 更新 weather.py 2025-01-20 18:26:50 +00:00
星光-k
f8857cbd17 更新 weather.py 2025-01-20 18:20:54 +00:00
星光-k
90b6ae1403 更新 main.py 2025-01-20 17:19:47 +00:00
星光-k
e9b284a9b3 更新 main.py 2025-01-20 15:23:38 +00:00
星光-k
7405aabf2c 更新 raspi_e-Paper.service 2025-01-20 13:38:04 +00:00
星光-k
ca450afb14 更新 raspi_e-Paper.service 2025-01-20 13:28:20 +00:00
星光-k
c82aadd4e7 更新 raspi_e-Paper.service 2025-01-20 13:27:31 +00:00
星光-k
0a96f265f7 更新 raspi_e-Paper.service 2025-01-20 12:33:21 +00:00
星光-k
298a3f43f1 更新 main.py 2025-01-19 06:51:43 +00:00
星光-k
17544b607a 更新 main.py 2025-01-19 06:41:04 +00:00
星光-k
99780f1bf9 Update main.py 2025-01-19 10:35:23 +08:00
星光-k
118cc0a2ee Update main.py 2025-01-19 06:35:24 +08:00
星光-k
3155088921 Update weather.py 2025-01-19 06:11:12 +08:00
星光-k
28f0a9d37d Update main.py 2025-01-19 06:10:35 +08:00
星光-k
fc1678aa95 Update install.sh 2025-01-19 05:48:39 +08:00
星光-k
f0eb8dc53e Update start.sh 2025-01-19 05:47:35 +08:00
星光-k
9e5114b7bd Update start.sh 2025-01-19 05:47:17 +08:00
星光-k
bb44237caa Delete webui directory 2025-01-19 05:46:48 +08:00
星光-k
e82fd225f5 Update main.py 2025-01-19 05:44:46 +08:00
星光-k
c67ae6bd78 Update main.py 2025-01-19 04:11:49 +08:00
星光-k
72c2b23566 Update main.py 2025-01-19 04:02:43 +08:00
星光-k
590494d734 Update start.sh 2025-01-19 01:20:53 +08:00
星光-k
8a29bf9110 Update main.py 2025-01-19 01:20:15 +08:00
星光-k
ab6abaf2e3 Update weather.py 2025-01-19 01:19:21 +08:00
星光-k
5436cba3d0 Update install.sh 2025-01-18 09:38:47 +08:00
星光-k
70d1b3d710 Delete webui/1 2025-01-18 09:11:52 +08:00
星光-k
6fa3fe1407 Add files via upload 2025-01-18 01:11:29 +00:00
星光-k
cd6fc91cda Create 1 2025-01-18 09:10:49 +08:00
星光-k
60272f75ea Delete app directory 2025-01-18 09:09:51 +08:00
星光-k
faf0e2f505 Add files via upload 2025-01-18 01:09:34 +00:00
星光-k
863e9b2f5d Add files via upload 2025-01-17 02:40:52 +00:00
星光-k
d523a31006 Add files via upload 2025-01-17 02:40:26 +00:00
星光-k
9d4895fca4 Add files via upload 2025-01-17 02:02:59 +00:00
星光-k
e7f71c699e Add files via upload 2025-01-17 02:02:07 +00:00
星光-k
419f44be7e Add files via upload 2025-01-17 02:01:40 +00:00
星光-k
6c90e54728 Update clean.py 2025-01-17 07:08:49 +08:00
星光-k
e70b05a529 Update main.py 2025-01-17 07:08:17 +08:00
星光-k
d8c12f7ad3 Update weather.py 2025-01-17 07:07:49 +08:00
星光-k
8eb21afb19 更新 weather.py 2025-01-16 20:15:21 +00:00
星光-k
7bc892d06b 更新 weather.py 2025-01-16 20:06:11 +00:00
星光-k
ca67499854 更新 weather.py 2025-01-16 19:17:51 +00:00
星光-k
0b5623d5f6 更新 main.py 2025-01-16 19:17:20 +00:00
星光-k
7a71514224 Add files via upload 2025-01-16 12:09:19 +00:00
星光-k
fac4c591fb 更新 install.sh 2025-01-16 11:55:34 +00:00
星光-k
95e6bb12be Add files via upload 2025-01-16 11:54:01 +00:00
星光-k
57ea23a6fa Update app.py 2025-01-16 19:53:20 +08:00
星光-k
5262d729fb Add files via upload 2025-01-16 11:52:16 +00:00
星光-k
428d056e58 Create index.html 2025-01-16 19:51:13 +08:00
星光-k
066d9676f3 Add files via upload 2025-01-16 11:50:31 +00:00
星光-k
54bb2ccf21 Create app.py 2025-01-16 19:50:01 +08:00
星光-k
47e6ae681a Update weather.py 2025-01-16 09:53:18 +08:00
星光-k
7e15bf4172 Update weather.py 2025-01-16 09:52:03 +08:00
星光-k
7eeb7ceb12 Update README.md 2025-01-16 09:43:40 +08:00
星光-k
6a498cc04f Update weather.py 2025-01-16 09:38:10 +08:00
星光-k
7e302d0843 Update clean.py 2025-01-16 09:30:43 +08:00
星光-k
04930156b6 Update main.py 2025-01-16 09:30:21 +08:00
星光-k
5543bc6710 Update weather.py 2025-01-16 09:27:11 +08:00
星光-k
0fe27553f4 Update README.md 2025-01-16 08:45:27 +08:00
星光-k
9fe9e9f71a Update README.md 2025-01-16 08:44:09 +08:00
星光-k
3752c55b17 Update README.md 2025-01-16 08:42:42 +08:00
星光-k
620f363916 Update README.md 2025-01-16 08:38:21 +08:00
星光-k
b184f08914 Update main.py 2025-01-16 08:29:51 +08:00
星光-k
8efc57e655 Update weather.py 2025-01-16 08:28:19 +08:00
星光-k
a4e39c00fe Update weather.py 2025-01-16 08:13:41 +08:00
星光-k
62dc79de18 Update main.py 2025-01-16 06:54:45 +08:00
星光-k
d58d806da5 Update start.sh 2025-01-16 03:36:09 +08:00
星光-k
693595ef0f Rename wenter.py to weather.py 2025-01-16 03:35:17 +08:00
星光-k
08745ea6d4 Add files via upload 2025-01-15 18:19:47 +00:00
星光-k
742c46f4f2 Add files via upload 2025-01-15 14:14:36 +00:00
星光-k
256d2fd2cc 更新 main.py 2025-01-14 22:08:45 +00:00
星光-k
eca6a07273 更新 clean.py 2025-01-14 22:04:36 +00:00
星光-k
e37bdcc9bf 更新 clean.py 2025-01-14 22:02:57 +00:00
星光-k
4f3d04f357 更新 clean.sh 2025-01-14 17:14:01 +00:00
星光-k
d6715fa5d3 更新 clean.sh 2025-01-14 17:02:43 +00:00
星光-k
ff6995de24 更新 main.py 2025-01-14 16:44:33 +00:00
星光-k
4d675b55af Create info-clean.log 2025-01-15 00:29:41 +08:00
星光-k
f002a2fc9b Create info.log 2025-01-15 00:29:20 +08:00
星光-k
7597b2a35f 更新 start.sh 2025-01-14 16:27:45 +00:00
星光-k
533374daa3 Delete log directory 2025-01-14 19:17:26 +08:00
星光-k
531f5a443b Update clean.sh 2025-01-14 19:16:16 +08:00
星光-k
e1a0fdaa34 Update start.sh 2025-01-14 19:16:01 +08:00
星光-k
d5224e81cc Update main.py 2025-01-14 19:15:46 +08:00
星光-k
a9021dc262 Update start.sh 2025-01-14 16:50:31 +08:00
星光-k
2485a83f2c 更新 install.sh 2025-01-14 02:45:34 +00:00
星光-k
0b7f6c4dfc Update README.md 2025-01-14 09:14:02 +08:00
星光-k
bca24803a5 Update install.sh 2025-01-14 08:10:10 +08:00
星光-k
75528eba1c Update install.sh 2025-01-14 07:54:48 +08:00
星光-k
b159a7a402 Update install.sh 2025-01-14 07:36:03 +08:00
星光-k
c5c7b055e3 Update install.sh 2025-01-14 07:30:06 +08:00
星光-k
69d32309a7 Update install.sh 2025-01-14 07:28:03 +08:00
星光-k
cb89e6cd5c Update install.sh 2025-01-14 07:22:45 +08:00
星光-k
902c237010 Update install.sh 2025-01-14 07:06:03 +08:00
星光-k
20f8a5a181 Update install.sh 2025-01-14 07:03:34 +08:00
星光-k
fa4c0e5a9e Update install.sh 2025-01-14 06:57:24 +08:00
星光-k
c35ec31440 Update main.py 2025-01-14 06:37:01 +08:00
星光-k
9d76efe6ee 更新 clean.py 2025-01-13 21:44:19 +00:00
星光-k
f4752268e8 更新 main.py 2025-01-13 20:32:24 +00:00
星光-k
90ae8aab3d 更新 main.py 2025-01-13 19:51:19 +00:00
星光-k
3a3407c735 更新 main.py 2025-01-13 19:39:31 +00:00
星光-k
a4f140966a 更新 start.sh 2025-01-13 19:10:21 +00:00
星光-k
d0adc8b213 更新 start.sh 2025-01-13 19:04:01 +00:00
星光-k
21f637f1cf 更新 start.sh 2025-01-13 18:54:20 +00:00
星光-k
bebbbc554c 更新 start.sh 2025-01-13 18:46:44 +00:00
星光-k
c8419c2fe8 更新 start.sh 2025-01-13 18:45:30 +00:00
星光-k
9ec0b39b16 更新 start.sh 2025-01-13 18:40:33 +00:00
星光-k
6ec682cb1a 更新 start.sh 2025-01-13 18:40:06 +00:00
星光-k
a9809e68f1 更新 clean.sh 2025-01-13 18:05:33 +00:00
星光-k
67fd8f3c2d 更新 clean.sh 2025-01-13 18:05:03 +00:00
星光-k
e4802e0ee4 更新 clean.sh 2025-01-13 18:04:52 +00:00
星光-k
b3feb79540 更新 start.sh 2025-01-13 17:50:01 +00:00
星光-k
5aed29edac 更新 start.sh 2025-01-13 17:22:29 +00:00
星光-k
ac7c8b2378 更新 install.sh 2025-01-13 17:18:01 +00:00
星光-k
ee5d2bb1ba 更新 start.sh 2025-01-13 16:25:50 +00:00
星光-k
0d849f7a7e 更新 start.sh 2025-01-13 15:24:46 +00:00
星光-k
78f7f9b597 更新 clean.sh 2025-01-13 14:45:09 +00:00
星光-k
4baaf25d44 更新 start.sh 2025-01-13 14:43:04 +00:00
星光-k
a2df4e6162 Update clean.sh 2025-01-13 18:57:49 +08:00
星光-k
f0541b1ee0 更新 clean.sh 2025-01-13 09:16:40 +00:00
星光-k
b30d12742e Update README.md 2025-01-13 16:24:05 +08:00
星光-k
aae214de87 Update install.sh 2025-01-13 16:22:23 +08:00
星光-k
34d2ea6840 Update install.sh 2025-01-13 16:06:41 +08:00
星光-k
df98d198d0 Update install.sh 2025-01-13 16:04:12 +08:00
星光-k
d6d86a0424 Update install.sh 2025-01-13 16:01:10 +08:00
星光-k
d32459ce9d Update install.sh 2025-01-13 15:51:08 +08:00
星光-k
6b5b8a935a Update install.sh 2025-01-13 15:49:39 +08:00
星光-k
0db4d98671 Update install.sh 2025-01-13 15:48:42 +08:00
星光-k
6bf064e941 Update README.md 2025-01-13 15:42:03 +08:00
星光-k
1ae2f31142 Update install.sh 2025-01-13 15:40:15 +08:00
星光-k
380bea6607 Update install.sh 2025-01-13 15:36:55 +08:00
星光-k
964811eac8 Update install.sh 2025-01-13 15:32:18 +08:00
星光-k
e2fb9777b1 Update install.sh 2025-01-13 15:28:37 +08:00
星光-k
50fba1dde9 Update README.md 2025-01-13 15:25:33 +08:00
星光-k
1be53da061 Update install.sh 2025-01-13 15:23:19 +08:00
星光-k
8d40fcd1b4 Update install.sh 2025-01-13 15:10:51 +08:00
星光-k
b7fbbcfe8f Update install.sh 2025-01-13 15:07:49 +08:00
星光-k
ba8b4894a5 Update install.sh 2025-01-13 15:06:56 +08:00
星光-k
e34c22c1be Update README.md 2025-01-13 14:57:05 +08:00
星光-k
67799d0038 Update README.md 2025-01-13 14:56:29 +08:00
星光-k
0fbbaa5bef Update README.md 2025-01-13 14:39:26 +08:00
星光-k
0f91590755 Update main.py 2025-01-13 14:33:25 +08:00
星光-k
2a93811d2f Update README.md 2025-01-13 14:22:46 +08:00
星光-k
8a4cce18f1 Add files via upload 2025-01-13 06:22:04 +00:00
星光-k
9f31dd8677 Delete pic/1736672578025.jpg 2025-01-13 14:21:29 +08:00
星光-k
20743401ae Update README.md 2025-01-13 14:20:05 +08:00
星光-k
050d3ca8a6 Update README.md 2025-01-13 14:18:12 +08:00
星光-k
3be8e7e63a Update install.sh 2025-01-13 14:08:06 +08:00
星光-k
b688062ca4 Update main.py 2025-01-13 02:30:00 +08:00
星光-k
d63d12de38 Update README.md 2025-01-12 21:41:51 +08:00
星光-k
9ef97ab7a2 Update install.sh 2025-01-12 21:32:30 +08:00
星光-k
6651491941 Update install.sh 2025-01-12 21:24:22 +08:00
星光-k
d498dad18f Update install.sh 2025-01-12 21:07:11 +08:00
星光-k
2bd8dc0bc6 Update install.sh 2025-01-12 21:04:03 +08:00
星光-k
7873004d74 Update install.sh 2025-01-12 20:57:55 +08:00
星光-k
a5eec2e9a3 Update install.sh 2025-01-12 20:26:49 +08:00
星光-k
a8059bac56 Update README.md 2025-01-12 17:06:41 +08:00
星光-k
a80e3a2722 Update README.md 2025-01-12 17:06:05 +08:00
星光-k
c60fccb210 Update README.md 2025-01-12 17:05:24 +08:00
星光-k
53e1845ce4 Update README.md 2025-01-12 17:04:29 +08:00
星光-k
3844f71943 Add files via upload 2025-01-12 09:03:30 +00:00
星光-k
b2336dcbfb Update clean.sh 2025-01-12 16:52:01 +08:00
星光-k
5a976157c2 Rename clean-info.log to info-clean.log 2025-01-12 16:42:51 +08:00
星光-k
b6866ee2b9 Update clean.sh 2025-01-12 16:39:55 +08:00
星光-k
32565ef2f5 Update clean.sh 2025-01-12 16:36:58 +08:00
星光-k
0c4282ebc9 Update start.sh 2025-01-12 16:33:04 +08:00
星光-k
f8b2c1b332 Update install.sh 2025-01-12 16:25:59 +08:00
星光-k
5b5dace7d3 Update install.sh 2025-01-12 16:22:08 +08:00
星光-k
04ab97f5b6 Update clean.sh 2025-01-12 16:21:45 +08:00
星光-k
0565fd6cf5 Update start.sh 2025-01-12 16:18:33 +08:00
星光-k
173d7eba78 Update main.py 2025-01-12 15:51:00 +08:00
星光-k
28895e7188 Update clean.sh 2025-01-12 14:55:53 +08:00
星光-k
8a4ba07f5b Update e-Paper_clean.service 2025-01-12 14:55:35 +08:00
星光-k
ecaa4006ce Update e-Paper_clean.service 2025-01-12 14:55:24 +08:00
星光-k
c5a3ef0dcf Update main.py 2025-01-12 14:52:18 +08:00
星光-k
99c2bb3152 Update main.py 2025-01-12 14:45:24 +08:00
星光-k
533e76d536 Update main.py 2025-01-12 14:08:23 +08:00
星光-k
26ee5bf6e7 Update main.py 2025-01-12 14:07:17 +08:00
星光-k
a710b293b6 Update main.py 2025-01-12 13:53:03 +08:00
星光-k
3a90a36ffa 更新 main.py 2025-01-12 05:34:51 +00:00
星光-k
fdd3e6008a 更新 main.py 2025-01-12 05:31:35 +00:00
星光-k
e3fd070e3c 更新 install.sh 2025-01-12 04:51:02 +00:00
星光-k
5e353f68f6 更新 install.sh 2025-01-12 04:48:42 +00:00
星光-k
6e0646612b 更新 install.sh 2025-01-12 04:46:09 +00:00
星光-k
d2b4073c98 更新 install.sh 2025-01-12 04:42:44 +00:00
星光-k
9fb1ef0c6b 更新 install.sh 2025-01-12 04:42:03 +00:00
星光-k
7c39658cdf 更新 install.sh 2025-01-12 04:35:34 +00:00
星光-k
6628fc01e2 更新 install.sh 2025-01-12 04:31:59 +00:00
星光-k
b505f9a61d 更新 install.sh 2025-01-12 04:26:12 +00:00
星光-k
7db25e5136 更新 install.sh 2025-01-12 04:22:31 +00:00
星光-k
9e28156c65 更新 install.sh 2025-01-12 04:13:48 +00:00
星光-k
1be7856992 更新 install.sh 2025-01-12 04:06:31 +00:00
星光-k
368ed919dd 更新 install.sh 2025-01-12 03:59:40 +00:00
星光-k
7a9108134a 更新 install.sh 2025-01-12 03:50:32 +00:00
星光-k
1aa62fb894 更新 install.sh 2025-01-12 03:46:47 +00:00
星光-k
d5ff700884 更新 install.sh 2025-01-12 03:21:28 +00:00
星光-k
c56bd3784e 更新 install.sh 2025-01-12 03:19:48 +00:00
星光-k
597790d4ad 更新 install.sh 2025-01-12 03:17:07 +00:00
星光-k
e8011c7282 更新 install.sh 2025-01-12 03:14:12 +00:00
星光-k
29de2a7d77 Update install.sh 2025-01-12 01:47:10 +08:00
星光-k
b6422c9afa Update install.sh 2025-01-12 01:39:08 +08:00
星光-k
9be8d1ac22 Update e-Paper_clean.service 2025-01-12 01:12:08 +08:00
星光-k
3d724ac527 Update clean.sh 2025-01-12 01:01:16 +08:00
星光-k
35facc30f0 Update clean.sh 2025-01-12 01:00:55 +08:00
星光-k
af205dc591 Update clean.sh 2025-01-12 00:58:42 +08:00
星光-k
ef387ebf4b Update e-Paper_clean.service 2025-01-12 00:28:27 +08:00
星光-k
6ac8e7d4b7 Update raspi_e-Paper.service 2025-01-12 00:26:59 +08:00
星光-k
a869fc1911 Update e-Paper_clean.service 2025-01-12 00:03:53 +08:00
星光-k
a2e657a182 Update README.md 2025-01-11 23:47:42 +08:00
星光-k
a29377cfa7 Update README.md 2025-01-11 23:46:05 +08:00
星光-k
08111ca4fa Update e-Paper_clean.service 2025-01-11 23:19:42 +08:00
星光-k
b3c8a76fe4 Update install.sh 2025-01-11 22:53:59 +08:00
星光-k
8fb2b0f172 Update install.sh 2025-01-11 22:47:58 +08:00
星光-k
40c96f8ace Update install.sh 2025-01-11 22:31:18 +08:00
星光-k
815383483d Update install.sh 2025-01-11 22:20:30 +08:00
星光-k
3062abb70b Update install.sh 2025-01-11 22:15:10 +08:00
星光-k
f15da42496 Update install.sh 2025-01-11 22:05:56 +08:00
星光-k
85fdea4341 Update install.sh 2025-01-11 21:59:19 +08:00
星光-k
c759882f51 Update install.sh 2025-01-11 21:35:43 +08:00
星光-k
e81aeba0fe Update install.sh 2025-01-11 21:33:27 +08:00
星光-k
ad571d0125 更新 install.sh 2025-01-11 09:55:24 +00:00
星光-k
f457537872 更新 install.sh 2025-01-11 09:50:56 +00:00
星光-k
8c2ff1d533 更新 install.sh 2025-01-11 09:14:37 +00:00
星光-k
2cf1c085c3 更新 install.sh 2025-01-11 08:48:25 +00:00
星光-k
d6a7e5e725 更新 install.sh 2025-01-11 07:10:21 +00:00
星光-k
6313770d3f 更新 install.sh 2025-01-11 06:57:15 +00:00
星光-k
17f0215e9d 更新 install.sh 2025-01-11 06:37:41 +00:00
星光-k
f5b2ef3518 更新 install.sh 2025-01-11 06:34:54 +00:00
星光-k
febff6fe78 更新 install.sh 2025-01-11 06:26:28 +00:00
星光-k
58f6a8f48d 更新 install.sh 2025-01-11 04:15:51 +00:00
31 changed files with 1340 additions and 450 deletions

View File

@@ -1,16 +1,17 @@
# 墨水屏展示当前时间及天气数据 # 墨水屏展示当前时间及天气数据
# 此分支专属于本人的个人设备实验分支以及备份
本项目复刻自[Seek-Huang](https://github.com/Seek-Huang)的[代码仓库](https://github.com/Seek-Huang/2.13-Ink-screen-clock)
并在此基础上进行改进
首先感谢上游https://github.com/Seek-Huang/2.13-Ink-screen-clock 的代码仓库 ## 本仓库已添加[一键安装部署脚本](https://github.com/kxgx/2.13-Ink-screen-clock#%E4%BD%BF%E7%94%A8%E8%84%9A%E6%9C%AC%E7%9B%B4%E6%8E%A5%E5%AE%89%E8%A3%85%E6%8E%A8%E8%8D%90)
## 本仓库已添加一键安装部署脚本
注意:请先配置完需要的硬件以及系统配置操作再运行脚本 注意:请先配置完需要的硬件以及系统配置操作再运行脚本
## API说明: ## API说明:
#### 一言API ~~#### 一言API~~
此网站可以获取指定长度指定类型的一个句子,可以限定返回长度及返回类型 ~~此网站可以获取指定长度指定类型的一个句子,可以限定返回长度及返回类型~~
https://international.v1.hitokoto.cn/?c=a&encode=text&max_length=20 ~~https://international.v1.hitokoto.cn/?c=a&encode=text&max_length=20~~
#### 天气API #### 天气API
获取的天气是通过网页的接口,获取的内容保存在当前目录下的json文件接口的地址是在这里抓取的 获取的天气是通过网页的接口,获取的内容保存在当前目录下的json文件接口的地址是在这里抓取的
@@ -25,11 +26,9 @@
https://github.com/PiSugar/PiSugar/wiki/PiSugar-3-Series#rtc-on-board https://github.com/PiSugar/PiSugar/wiki/PiSugar-3-Series#rtc-on-board
https://www.pisugar.com/ https://www.pisugar.com/
ps:如果没有使用此模块则需要更改代码内容,以避免运行出错。 ps:如果没有使用此模块则需要更改代码内容,以避免运行出错。
以上可能python脚本已解决
ps:代码里需要nc命令需要安装netcat安装内容已集成到“需要安装的软件和依赖https://github.com/kxgx/2.13-Ink-screen-clock#%E9%9C%80%E8%A6%81%E5%AE%89%E8%A3%85%E7%9A%84%E8%BD%AF%E4%BB%B6%E5%92%8C%E4%BE%9D%E8%B5%96 ps:代码里需要nc命令需要安装netcat安装内容已集成到“[需要安装的软件和依赖](https://github.com/kxgx/2.13-Ink-screen-clock#%E9%9C%80%E8%A6%81%E5%AE%89%E8%A3%85%E7%9A%84%E8%BD%AF%E4%BB%B6%E5%92%8C%E4%BE%9D%E8%B5%96)"
### 墨水屏2.13inch e-Paper HAT+硬件连接 ### 墨水屏2.13inch e-Paper HAT+硬件连接
连接树莓派的时候,可以直接将板子插到树莓派的 40PIN 排针上去,注意对好引脚。 连接树莓派的时候,可以直接将板子插到树莓派的 40PIN 排针上去,注意对好引脚。
@@ -58,57 +57,71 @@ sudo reboot
![image](https://www.waveshare.net/w/upload/a/a0/RPI_open_spi_2.jpg) ![image](https://www.waveshare.net/w/upload/a/a0/RPI_open_spi_2.jpg)
#### wifi连接管理
可以使用[PiSugar/sugar-wifi-conf:让树莓派提供蓝牙BLE服务使用小程序可以随时更改树莓派的wifi连接
](https://github.com/PiSugar/PiSugar/wiki/PiSugar-WiFi-config#sugar-wifi-conf)
## 使用脚本直接安装(推荐) ## 使用脚本直接安装(推荐)
### 参数定义 ### 参数定义
```Bash ```Bash
--zh 设置系统语言为zh_CN,UTF-8 --zh 设置系统语言为zh_CN,UTF-8
--cn 替换apt镜像源为中国镜像源 --cn 替换apt镜像源为中国镜像源
--debug 输出详细信息 --gitcn 克隆中国仓库
--pip-offline pip依赖离线安装
--pisugar-wifi-conf 安装pisugar-wifi-conf
--pisugar-power-manager 安装pisugar-power-manager
--version <tag> 版本号(使用方法 --version + 仓库标签,格式例如 v1.x.x ,可以是主仓库main)
--debug 输出详细信息
``` ```
###
```Bash ```Bash
#国源默认设置 #国源默认设置(不加参数)
curl -sSL https://gitee.com/xingguangk/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash curl -sSL https://gitee.com/xingguangk/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash
``` ```
```Bash ```Bash
#国内源--cn设置 #中国源参数设置(不使用--debug参数,替换cn镜像源,pip在线安装,不安装pisugar)
curl -sSL https://gitee.com/xingguangk/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --cn curl -sSL https://gitee.com/xingguangk/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --zh --cn --gitcn --version <tag>
``` ```
```Bash ```Bash
#默认源默认设置 #中国源参数设置(不使用--debug参数,替换cn镜像源,pip依赖离线安装,不安装pisugar)
curl -sSL https://gitee.com/xingguangk/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --zh --cn --gitcn --pip-offline --version <tag>
```
```Bash
#默认源默认设置(不加参数)
curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash
``` ```
```Bash ```Bash
#默认源--cn设置 #默认源默认设置(不使用--debug参数,替换cn镜像源,pip在线安装,不安装pisugar)
curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --cn curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --zh --cn --gitcn --version <tag>
```
```Bash
#默认源默认设置(不使用--debug参数,替换cn镜像源,pip依赖离线安装,不安装pisugar)
curl -sSL https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/bin/install.sh | sudo bash -s -- --zh --cn --gitcn --pip-offline --version <tag>
``` ```
## 需要安装的软件和依赖: ## 需要安装的软件和依赖:
参考 参考
微雪电子 https://www.waveshare.net/wiki/2.13inch_e-Paper_HAT+#Raspberry_Pi 微雪电子 https://www.waveshare.net/wiki/2.13inch_e-Paper_HAT+#Raspberry_Pi
PiSugar 3官方文档 https://github.com/PiSugar/PiSugar/wiki/PiSugar-3-Series#software-installation PiSugar 3官方文档 https://github.com/PiSugar/PiSugar/wiki/PiSugar-3-Series#software-installation
```Bash ```Bash
sudo apt-get update sudo apt-get update
sudo apt install -y git sudo apt-get install -y git pigpio i2c-tools netcat* gawk python3-dev python3-pip python3-pil python3-numpy python3-gpiozero python3-pigpio build-essential
sudo apt-get install -y netcat* sudo pip3 install spidev borax pillow requests
sudo apt-get install -y python3-pip
sudo apt-get install -y python3-pil
sudo apt-get install -y python3-numpy
sudo apt install -y python3-gpiozero
sudo pip3 install spidev borax pillow requests --break-system-packages
wget https://cdn.pisugar.com/release/pisugar-power-manager.sh wget https://cdn.pisugar.com/release/pisugar-power-manager.sh
bash pisugar-power-manager.sh -c release bash pisugar-power-manager.sh -c release
``` ```
#### 傻瓜式安装命令和执行启动文件: #### 安装命令和执行启动文件组合命令
```Bash ```Bash
sudo apt-get update && sudo apt install -y git && sudo apt-get install -y python3-pip && sudo apt-get install -y python3-pil && sudo apt-get install -y python3-numpy && sudo apt install -y python3-gpiozero && sudo apt-get install -y netcat* && sudo pip3 install spidev borax pillow requests --break-system-packages && wget https://cdn.pisugar.com/release/pisugar-power-manager.sh && bash pisugar-power-manager.sh -c release && cd ~/ && git clone https://github.com/kxgx/2.13-Ink-screen-clock.git && cd ~/2.13-Ink-screen-clock/bin/ && sudo chmod +x start.sh && sudo ./start.sh sudo apt-get update && sudo apt-get install -y git pigpio i2c-tools netcat* gawk python3-dev python3-pip python3-pil python3-numpy python3-gpiozero python3-pigpio build-essential && sudo pip3 install spidev borax pillow requests && wget https://cdn.pisugar.com/release/pisugar-power-manager.sh && bash pisugar-power-manager.sh -c release && cd ~/ && git clone https://github.com/kxgx/2.13-Ink-screen-clock.git && cd ~/2.13-Ink-screen-clock/bin/ && sudo chmod +x start.sh && sudo ./start.sh
``` ```
##### 使用国内仓库: ##### 使用国内仓库:
```Bash ```Bash
sudo apt-get update && sudo apt install -y git && sudo apt-get install -y python3-pip && sudo apt-get install -y python3-pil && sudo apt-get install -y python3-numpy && sudo apt install -y python3-gpiozero && sudo apt-get install -y netcat* && sudo pip3 install spidev borax pillow requests --break-system-packages && wget https://cdn.pisugar.com/release/pisugar-power-manager.sh && bash pisugar-power-manager.sh -c release && cd ~/ && git clone https://gitee.com/xingguangk/2.13-Ink-screen-clock.git && cd ~/2.13-Ink-screen-clock/bin/ && sudo chmod +x start.sh && sudo ./start.sh sudo apt-get update && sudo apt-get install -y git pigpio i2c-tools netcat* gawk python3-dev python3-pip python3-pil python3-numpy python3-gpiozero python3-pigpio build-essential && sudo pip3 install spidev borax pillow requests && sudo pip3 install spidev borax pillow requests --break-system-packages && wget https://cdn.pisugar.com/release/pisugar-power-manager.sh && bash pisugar-power-manager.sh -c release && cd ~/ && git clone https://gitee.com/xingguangk/2.13-Ink-screen-clock.git && cd ~/2.13-Ink-screen-clock/bin/ && sudo chmod +x start.sh && sudo ./start.sh
``` ```
###### 注意
```Bash
# 如果使用的是非lite系统请在pip3安装部分添加
--break-system-packages
```
在weanther.py文件第64行可以修改默认城市数据
# 效果展示
总体采用局刷方案,程序运行后一直处于程序的获取新数据的过程中,当发现数据变化后即开始自动局刷。 总体采用局刷方案,程序运行后一直处于程序的获取新数据的过程中,当发现数据变化后即开始自动局刷。
![image](https://github.com/kxgx/2.13-Ink-screen-clock/raw/main/pic/1736749257603.jpg)
特别注意:
在代码文件第三十三行,此次代码需要更改,否则将展示默认城市天气数据
![image](https://raw.githubusercontent.com/huanglinsd/2.13-Ink-screen-clock/main/pic/IMG_1245.JPG)

View File

@@ -16,37 +16,39 @@ if os.path.exists(libdir):
from waveshare_epd import epd2in13_V4 #引入墨水屏驱动文件 from waveshare_epd import epd2in13_V4 #引入墨水屏驱动文件
# 配置日志 # 配置日志
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s')
def clear_screen(): def clear_screen():
try: try:
logging.info("Starting e-Paper clear screen script") logging.info("启动电子纸清屏脚本")
# 初始化并创建一个 epd2in13_V4 对象 # 初始化并创建一个 epd2in13_V4 对象
epd = epd2in13_V4.EPD() epd = epd2in13_V4.EPD()
# 初始化屏幕 # 初始化屏幕
logging.info("Initializing e-Paper display") logging.info("初始化电子纸显示屏")
epd.init() epd.init()
# 清除屏幕 # 清除屏幕
logging.info("Clearing e-Paper display") logging.info("清除电子纸显示屏内容")
epd.Clear(0xFF) epd.Clear(0xFF)
# 等待一段时间,确保清除操作完成 # 等待一段时间,确保清除操作完成
time.sleep(1) #time.sleep(1)
# 将屏幕置于睡眠模式 # 将屏幕置于睡眠模式
logging.info("Putting e-Paper display to sleep") logging.info("将电子纸显示屏置入睡眠状态")
epd.sleep() epd.sleep()
epd2in13_V4.epdconfig.module_exit(cleanup=True)
exit()
logging.info("e-Paper display cleared successfully") logging.info("电子纸显示屏清屏成功")
except IOError as e: except IOError as e:
logging.info(e) logging.info(e)
except KeyboardInterrupt: except KeyboardInterrupt:
logging.info("Ctrl+C pressed, exiting") logging.info("检测到键盘中断,正在退出")
epd2in13_V4.epdconfig.module_exit(cleanup=True) epd2in13_V4.epdconfig.module_exit(cleanup=True)
exit() exit()

View File

@@ -1,20 +1,23 @@
#!/bin/bash #!/bin/bash
f_name=clean.py f_name="clean.py"
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
logdir=${dir%/*} logdir="${dir%/*}/log"
screen_name="clean_screen"
service_name="raspi_e-Paper.service" service_name="raspi_e-Paper.service"
# 停止raspi_e-Paper服务 # 停止raspi_e-Paper服务
echo "正在停止$service_name服务..." echo "正在停止$service_name服务..."
sudo systemctl stop $service_name sudo systemctl stop "$service_name"
# 查找并结束所有与指定screen_name相关的screen会话 # 确保日志目录存在
pids=$(screen -ls | grep $screen_name | awk -F '.' '{print $1}' | awk '{print $1}') mkdir -p "${logdir}"
for pid in $pids; do
screen -S $pid -X quit
done
# 创建一个新的screen会话并运行Python脚本 # 获取并终止所有与脚本相关的进程
screen -dmS $screen_name /usr/bin/python3 -u $dir/$f_name > $logdir/log/clean-info.log 2>&1 pids=$(pgrep -f "$dir/$f_name")
if [ -n "$pids" ]; then
kill -9 $pids
fi
echo "正在清除屏幕内容"
# 运行Python脚本并将输出重定向到日志文件
/usr/bin/python3 -u "$dir/$f_name" > "${logdir}/info-clean.log" 2>&1

222
bin/clock.py Normal file
View File

@@ -0,0 +1,222 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from PIL import Image,ImageDraw,ImageFont #引入图片处理库
import os,sys,re,json,time,datetime #引入系统相关库
from borax.calendars.lunardate import LunarDate #农历日期以及天干地支纪年法的 Python 库
import logging #日志库
import subprocess
import os
from threading import Timer
import requests
white = 255 #颜色
black = 0
logging.basicConfig(level=logging.DEBUG)
################################引入配置文件开始################################################
picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
if os.path.exists(libdir):
sys.path.append(libdir)#将引入文件添加到环境变量
from waveshare_epd import epd2in13_V4 #引入墨水屏驱动文件
logging.debug("Loading Fonts")
font01 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 20) #字体文件
font02 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 15) #字体文件
font03 = ImageFont.truetype(os.path.join(picdir, 'DSEG7Modern-Bold.ttf'), 66) #字体文件
font04 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 10) #字体文件
font05 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 12) #字体文件
font06 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 13) #字体文件
################################引入配置文件结束################################################
def Local_strong_brush(): #局部强制刷新显示
i = 0
while i < 5:
epd.displayPartial(epd.getbuffer(info_image.rotate(180)))#局刷开始
i = i + 1
def get_date():#返回当前年月日及星期几
date = datetime.datetime.now()
today=LunarDate.today()
week_day_dict = {0: '星期一',1: '星期二',2: '星期三',3: '星期四',4: '星期五',5: '星期六',6: '星期日',}
day = date.weekday()
return time.strftime('%Y年%m月%d')+''+week_day_dict[day]+''+today.strftime('农历%M月%D')
# 定义一个全局标志变量,用于检查是否已经设置了系统时间或尝试过设置
has_set_system_time = False
def set_system_time_from_hwclock(utc=True):
"""Set the system time from the hardware clock.
Args:
utc (bool): Whether the RTC is in UTC. Default is True.
"""
try:
# 记录调用 hwclock 前的时间
before_time = datetime.datetime.now()
logging.debug(f"System time before hwclock call: {before_time}")
# 构造 hwclock 命令及其参数
hwclock_args = ['sudo', 'hwclock', '--hctosys']
if not utc:
hwclock_args.append('--localtime')
logging.debug(f"Executing hwclock command: {' '.join(hwclock_args)}")
# 使用 subprocess.run 执行 hwclock --hctosys 并捕获输出
result = subprocess.run(hwclock_args,
check=True, # 如果命令失败,则抛出 CalledProcessError 异常
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True)
# 等待一小段时间以确保时间更新完成
time.sleep(0.1) # 根据需要调整
# 记录调用 hwclock 后的时间
after_time = datetime.datetime.now()
logging.debug("System time successfully set from hardware clock.")
logging.debug(f"System time after hwclock call: {after_time}")
# 检查时间是否发生了倒退
if after_time < before_time:
logging.warning(f"Time went backwards after hwclock call: before={before_time}, after={after_time}")
return True
except subprocess.CalledProcessError as e:
logging.error(f"Failed to set system time from hardware clock: {e.stderr}")
return False
except Exception as e:
logging.error(f"An unexpected error occurred: {str(e)}")
return False
def get_time():
global has_set_system_time
if not has_set_system_time:
# 尝试从硬件时钟设置系统时间,默认假设 RTC 是 UTC
success = set_system_time_from_hwclock(utc=True)
# 无论成功与否,都更新标志变量以避免重复尝试
has_set_system_time = True
# 获取并返回当前时间,格式为 HH:MM 大写
current_time = time.strftime('%H:%M').upper()
logging.debug(f"Returning current time: {current_time}")
return current_time
def Get_ipv4_address(): # 获取当前的IP地址
try:
ip_output = subprocess.check_output(
"hostname -I | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}'", shell=True).decode('utf-8').strip()
ip_list = ip_output.split()
filtered_ips = [ip for ip in ip_list if not ip.startswith("172.")]
return filtered_ips[0] if filtered_ips else "地址获取失败"
except subprocess.CalledProcessError:
return "获取失败"
def CPU_temperature():#CPU温度获取
temperatura = os.popen('vcgencmd measure_temp').readline()
temperatura = temperatura.replace('temp=','').strip()
return str(temperatura)
def Memory_footprint():#显示内存占用百分比
return(subprocess.check_output(u"free -m | awk -F '[ :]+' 'NR==2{printf \"%d\", ($3)/$2*100}'", shell = True ).decode('gbk'))
def CPU_usage(): #显示CPU占用百分比
return(str(int(float(os.popen("top -b -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip()))))
def power_battery():#获取当前电池电量
return(str(int(subprocess.check_output(u"echo \"get battery\" | nc -q 0 127.0.0.1 8423|awk -F':' '{print int($2)}'", shell = True ).decode('gbk')))+u'%')
# 打印电量信息
print(power_battery())
def Bottom_edge(): #在图片中添加底边内容
draw.rectangle((0, 105, 250, 122), 'black', 'black')
'''电池图标画图'''
draw.line((126,109,154,109),fill=255, width=1) #电池顶边
draw.line((126,110,126,119),fill=255, width=1) #电池左边
draw.line((127,119,154,119),fill=255, width=1) #电池下边
draw.line((154,110,154,118),fill=255, width=1)
draw.line((155,112,157,112),fill=255, width=1)
draw.line((155,116,157,116),fill=255, width=1)
draw.line((157,113,157,115),fill=255, width=1)
global power_str
power_str=power_battery()
draw.text((128,108),power_str,font = font04,fill =255) #显示当前电量百分比
'''电池图标画图'''
draw.ellipse((192, 107, 207, 120), 0, 255)# 时钟图标
draw.line((199,109,199,114),fill=255, width=1)
draw.line((200,114,204,114),fill=255, width=1)
global local_addr #获取当前IP地址
local_addr= Get_ipv4_address() #获取当前IP地址
draw.text((10,107),"IP:"+local_addr,font = font05,fill =255)#显示当前IP地址
def Basic_refresh(): #全刷函数
logging.info("Refresh and prepare the basic content before starting the canvas")#开始画布前刷新准备基础内容
global get_date_var
get_date_var=get_date() #记录开始数据
draw.text((2,2),get_date_var,font = font02,fill =0)#将日期及星期几显示到屏幕
global local_time
local_time=get_time()
draw.text((5,40),local_time,font = font03,fill =0)#显示当前时间
Bottom_edge() #添加底边内容
epd.display(epd.getbuffer(info_image.rotate(180)))
def Partial_full_brush(): #局部定时全刷函数
Basic_refresh() #全局刷新
logging.debug("局部定时全局刷新")
epd.init()
def Partial_refresh():#局刷函数
logging.info("Partial content update, this update is recommended to be synchronized with the minute to save the life of the ink screen")#局部内容更新,此更新建议与分钟同步,以节省墨水屏寿命
epd.displayPartBaseImage(epd.getbuffer(info_image.rotate(180)))
epd.init()
while (True):
global local_time
local_time1=get_time()
if (local_time1==local_time) ==False:
draw.rectangle((5, 17, 133, 95), fill = 255) #时间局刷区域
draw.text((5,17),local_time1,font = font03,fill =0)#刷新当前时间
local_time=local_time1
Local_strong_brush() #局部强刷
get_date_var1=get_date() #局刷判断,如果时间与前一次不一致说明内容变化,需要刷新显示
global get_date_var #再次声明这个是全局变量
if(get_date_var1==get_date_var) ==False:
draw.rectangle((2, 2, 250, 16), fill = 255) #设置头部刷新区域
draw.text((2,2),get_date_var1,font = font02,fill =0)#将日期及星期几刷新显示到屏幕
get_date_var=get_date_var1 #将更新的值保存到初始变量,直到下一次变化时执行该刷新操作
logging.debug("头部日期部位发生刷新变化.")
Local_strong_brush() #局部强刷
global local_addr #当前IP地址
local_addr1 = Get_ipv4_address()
if (local_addr1==local_addr) ==False:
draw.rectangle((1, 107, 94, 120), fill = 0) #设置头部刷新区域
draw.text((10,107),"IP:"+local_addr1,font = font05,fill =255)#显示当前IP地址
local_addr=local_addr1
Local_strong_brush() #局部强刷
#显示当前电量百分比
power_str=power_str1
Local_strong_brush() #局部强刷
logging.debug("电源电量局部刷新")
retry_interval = 180 # 设置重试间隔时间(秒)
while True:
try:
##################屏幕初始化#########################
epd = epd2in13_V4.EPD() #初始化
epd.init()#设定屏幕刷新模式
#epd.Clear(0xFF) #清除屏幕内容
##################屏幕初始化#########################
logging.info("Width = %s, Height = %s", format(epd.width), format(epd.height)) #打印屏幕高度及宽度
logging.info("初始化并清空显示屏")#屏幕开始准备相关展示
info_image = Image.new('1', (epd.height, epd.width), 255) #画布创建准备
draw = ImageDraw.Draw(info_image)
Basic_refresh() #全局刷新
Partial_refresh() #局部刷新
epd.init()
epd.Clear(0xFF)
epd.sleep()
time.sleep(300)
break # 如果脚本执行成功,则退出循环
except (OSError, Exception) as e: # 捕获你提到的异常
logging.error("发生了错误: %s", e)
time.sleep(retry_interval) # 等待一段时间后重试
except KeyboardInterrupt:
logging.info("检测到键盘中断,正在清理并退出")
epd.init()
epd.Clear(0xFF) # 清除屏幕内容
epd.sleep() # 使屏幕进入休眠状态
epd2in13_V4.epdconfig.module_exit() # 清理资源
exit()
# 脚本正常结束后的清理操作
epd.init()
epd.Clear(0xFF) # 清除屏幕内容
epd.sleep() # 使屏幕进入休眠状态
epd2in13_V4.epdconfig.module_exit() # 清理资源
exit()

View File

@@ -8,7 +8,6 @@ Before=reboot.target
Type=oneshot Type=oneshot
ExecStart=/bin/bash /root/2.13-Ink-screen-clock/bin/clean.sh ExecStart=/bin/bash /root/2.13-Ink-screen-clock/bin/clean.sh
RemainAfterExit=yes RemainAfterExit=yes
TimeoutSec=5s
[Install] [Install]
WantedBy=shutdown.target WantedBy=shutdown.target

View File

@@ -7,11 +7,19 @@ if [ "$EUID" -ne 0 ]; then
fi fi
# 默认语言环境 # 默认语言环境
DEFAULT_LANG="en_US.UTF-8" DEFAULT_LANG="en_GB.UTF-8"
# 检查是否使用中国镜像源 # 检查是否使用中国镜像源
USE_CN_MIRROR=false USE_CN_MIRROR=false
# 控制调试输出 # 控制调试输出
DEBUG=false DEBUG=false
# 检查是否使用中国git仓库
USE_CN_GIT=false
# 检查是否安装pisugar-wifi-conf
USE_PISUGAR_WIFI_CONF=false
# 检查是否安装pisugar-power-manager
USE_PISUGAR_POWER_MANAGER=false
# 检查是否使用离线安装pip依赖
USE_OFFLINE_PIP=false
# 解析命令行参数 # 解析命令行参数
while [ "$#" -gt 0 ]; do while [ "$#" -gt 0 ]; do
@@ -22,6 +30,26 @@ while [ "$#" -gt 0 ]; do
--cn) --cn)
USE_CN_MIRROR=true USE_CN_MIRROR=true
;; ;;
--gitcn)
USE_CN_GIT=true
;;
--pip-offline)
USE_OFFLINE_PIP=true
;;
--pisugar-wifi-conf)
USE_PISUGAR_WIFI_CONF=true
;;
--pisugar-power-manager)
USE_PISUGAR_POWER_MANAGER=true
;;
--version)
if [ -z "$2" ]; then
echo "错误: --version 参数后需要跟版本号"
exit 1
fi
VERSION="$2" # 将版本号赋值给变量 VERSION
shift 2 # 移动参数,跳过版本号参数及其值
;;
--debug) --debug)
DEBUG=true DEBUG=true
;; ;;
@@ -33,33 +61,58 @@ while [ "$#" -gt 0 ]; do
shift shift
done done
# 获取当前语言环境变量
CURRENT_LANG=$(locale | grep LANG | sed 's/.*=//')
# 打印当前语言环境变量
echo "当前语言环境: $CURRENT_LANG"
# 设置语言环境 # 设置语言环境
export LANG=$DEFAULT_LANG if [ "$CURRENT_LANG" != "$DEFAULT_LANG" ]; then
export LC_ALL=$DEFAULT_LANG echo "当前语言环境不是 $DEFAULT_LANG,将进行设置"
# 如果 locale.gen 中不存在,则添加到 locale.gen # 设置新的语言环境变量
if ! grep -q "^$DEFAULT_LANG UTF-8" /etc/locale.gen; then export LANG=$DEFAULT_LANG
echo "$DEFAULT_LANG UTF-8" | sudo tee -a /etc/locale.gen export LC_ALL=$DEFAULT_LANG
fi
# 生成 locale # 检查 locale.gen 中是否已存在 DEFAULT_LANG
if ! sudo locale-gen; then found=0
echo "生成 locale 失败" >&2 while read -r line; do
exit 1 if [[ "$line" == "$DEFAULT_LANG UTF-8" ]]; then
fi found=1
break
fi
done < /etc/locale.gen
# 重新配置 locales if [ $found -eq 0 ]; then
if ! sudo dpkg-reconfigure --frontend=noninteractive locales; then # 如果不存在,则添加到 locale.gen
echo "重新配置 locales 失败" >&2 echo "$DEFAULT_LANG UTF-8" | sudo tee -a /etc/locale.gen
exit 1 # 确保 locale.gen 被正确更新
fi if [ $? -ne 0 ]; then
echo "无法更新 locale.gen 文件" >&2
# 如果需要调试输出 exit 1
debug() { fi
if [ "$DEBUG" = true ]; then else
echo "$@" echo "语言环境 $DEFAULT_LANG 已在 locale.gen 中设置,跳过添加"
fi fi
}
# 生成 locale
if ! sudo locale-gen; then
# 如果生成失败,打印错误消息并退出
echo "生成 locale 失败" >&2
exit 1
fi
# 更新 locale 配置
if ! sudo update-locale LANG=$DEFAULT_LANG; then
echo "更新 locale 配置失败" >&2
exit 1
fi
echo "语言环境设置完成"
else
echo "当前语言环境已经是 $DEFAULT_LANG,跳过设置"
fi
# Debian版本相关命令 # Debian版本相关命令
DEBIAN_VERSION=$(cat /etc/debian_version) DEBIAN_VERSION=$(cat /etc/debian_version)
@@ -73,99 +126,193 @@ is_raspberry_pi() {
fi fi
} }
# 定义链接变量 # 使用中国镜像源
DEBIAN_MIRROR="http://deb.debian.org/debian/" DEBIAN_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/debian"
DEBIAN_SECURITY_MIRROR="http://security.debian.org/" DEBIAN_SECURITY_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/debian-security"
PI_SUGAR_POWER_MANAGER_URL="https://cdn.pisugar.com/release/pisugar-power-manager.sh"
INK_SCREEN_CLOCK_REPO_URL="https://github.com/kxgx/2.13-Ink-screen-clock.git"
PIPY_MIRROR="https://pypi.org/simple"
# 如果使用中国镜像源,则更新链接变量
if [ "$USE_CN_MIRROR" = true ]; then
DEBIAN_MIRROR="https://mirrors.cernet.edu.cn/debian/"
DEBIAN_SECURITY_MIRROR="https://mirrors.cernet.edu.cn/debian-security"
INK_SCREEN_CLOCK_REPO_URL="https://gitee.com/xingguangk/2.13-Ink-screen-clock.git"
PIPY_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple" PIPY_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
# 使用中国镜像源时Raspberry Pi 特定源链接保持不变
RASPBERRY_PI_SOURCE_DEBIAN11="https://mirrors.tuna.tsinghua.edu.cn/raspberrypi"
RASPBERRY_PI_SOURCE_DEBIAN12="https://mirrors.tuna.tsinghua.edu.cn/raspberrypi"
# 定义仓库链接变量
INK_SCREEN_CLOCK_REPO_URL="https://github.com/kxgx/2.13-Ink-screen-clock"
# 如果使用中国仓库,则更新链接变量
if [ "$USE_CN_GIT" = true ]; then
INK_SCREEN_CLOCK_REPO_URL="https://gitee.com/xingguangk/2.13-Ink-screen-clock"
fi fi
# 更新源列表函数 # 更新源列表函数
update_sources_list() { update_sources_list() {
local version=$1 local version=$1
debug "正在更新版本 $version 的源列表" local debian_mirror_in_use=$(grep -oP 'deb\s+\K.+' /etc/apt/sources.list | head -1)
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak local raspberry_pi_source_in_use=$(grep -oP 'deb\s+\K.+' /etc/apt/sources.list.d/raspi.list | head -1)
{
echo "deb $DEBIAN_MIRROR $version main contrib non-free" # 检查并替换 Debian 源
echo "# deb-src $DEBIAN_MIRROR $version main contrib non-free" if [ "$USE_CN_MIRROR" = true ]; then
} | sudo tee /etc/apt/sources.list > /dev/null if [ "$debian_mirror_in_use" != "$DEBIAN_MIRROR" ]; then
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
{
if [ "$version" = "bookworm" ]; then
echo "deb $DEBIAN_MIRROR $version main contrib non-free non-free-firmware"
echo "# deb-src $DEBIAN_MIRROR $version main contrib non-free non-free-firmware"
echo "deb $DEBIAN_MIRROR $version-updates main contrib non-free non-free-firmware"
echo "# deb-src $DEBIAN_MIRROR $version-updates main contrib non-free non-free-firmware"
echo "deb $DEBIAN_SECURITY_MIRROR $version-security main contrib non-free non-free-firmware"
echo "# deb-src $DEBIAN_SECURITY_MIRROR $version-security main contrib non-free non-free-firmware"
else
echo "deb $DEBIAN_MIRROR $version main contrib non-free"
echo "# deb-src $DEBIAN_MIRROR $version main contrib non-free"
echo "deb $DEBIAN_MIRROR $version-updates main contrib non-free"
echo "# deb-src $DEBIAN_MIRROR $version-updates main contrib non-free"
echo "deb $DEBIAN_SECURITY_MIRROR $version-security main contrib non-free"
echo "# deb-src $DEBIAN_SECURITY_MIRROR $version-security main contrib non-free"
fi
} | sudo tee /etc/apt/sources.list > /dev/null
else
echo "Debian 源链接已更新,跳过替换" >&2
fi
# 检查并替换 Raspberry Pi 特定源
if [ "$version" == "bullseye" ]; then
RASPBERRY_PI_SOURCE=$RASPBERRY_PI_SOURCE_DEBIAN11
elif [ "$version" == "bookworm" ]; then
RASPBERRY_PI_SOURCE=$RASPBERRY_PI_SOURCE_DEBIAN12
else
echo "未知的Debian版本: $version" >&2
exit 1
fi
if [ "$raspberry_pi_source_in_use" != "$RASPBERRY_PI_SOURCE$version" ]; then
if [ -f "/etc/apt/sources.list.d/raspi.list" ]; then
sudo cp /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.list.bak
fi
echo "deb $RASPBERRY_PI_SOURCE $version main" | sudo tee /etc/apt/sources.list.d/raspi.list > /dev/null
else
echo "Raspberry Pi 源链接已更新,跳过替换" >&2
fi
fi
} }
# 安装包函数 # 安装包函数
install_packages() { install_packages() {
debug "正在安装软件包..." echo "正在更新源列表"
if ! sudo apt-get update; then if ! sudo apt-get -q update; then
echo "更新源列表失败" >&2 echo "更新源列表失败" >&2
exit 1 exit 1
fi fi
if ! sudo apt-get upgrade -y; then echo "正在安装软件包"
echo "系统更新失败" >&2 if ! sudo apt-get -q -y install git pigpio i2c-tools netcat* gawk python3-dev python3-pip python3-pil python3-numpy python3-gpiozero python3-pigpio build-essential screen; then
exit 1
fi
if ! sudo apt-get install -y git pigpio raspi-config netcat gawk python3-dev python3-pip python3-pil python3-numpy python3-gpiozero python3-pigpio build-essential screen; then
echo "软件包安装失败" >&2 echo "软件包安装失败" >&2
exit 1 exit 1
fi fi
} }
install_Ink-screen-clock() {
# 检查墨水屏时钟仓库是否存在
if [ ! -d "$HOME/2.13-Ink-screen-clock" ]; then
echo "正在克隆仓库"
cd ~
if ! git clone -b $VERSION $INK_SCREEN_CLOCK_REPO_URL; then
echo "克隆仓库失败" >&2
exit 1
fi
# 设置start.sh和clean.sh脚本的执行权限
chmod +x "$HOME/2.13-Ink-screen-clock/bin/start.sh"
chmod +x "$HOME/2.13-Ink-screen-clock/bin/clean.sh"
else
echo "仓库文件夹已存在,跳过克隆"
fi
}
# 安装pip包函数 # 安装pip包函数
install_pip_packages() { install_oline_pip_packages() {
debug "正在安装pip软件包..." echo "正在安装pip软件包"
if ! sudo pip3 install -i $PIPY_MIRROR spidev borax pillow requests; then if ! sudo pip3 install -i "$PIPY_MIRROR" -r "$HOME/2.13-Ink-screen-clock/bin/requirements.txt"; then
echo "pip软件包安装失败" >&2 echo "pip软件包安装失败如果是最新版系统或是非lite系统" >&2
echo "请手动运行sudo pip3 install -i "$PIPY_MIRROR" -r "$HOME/2.13-Ink-screen-clock/bin/requirements.txt" --break-system-packages" >&2
exit 1 exit 1
fi fi
} }
install_offline_pip_packages() {
echo "正在安装pip软件包"
if ! sudo pip3 install --no-index --find-links="$HOME/2.13-Ink-screen-clock/bin/vendor" -r "$HOME/2.13-Ink-screen-clock/bin/requirements.txt"; then
echo "pip软件包安装失败如果是最新版系统或是非lite系统" >&2
echo "请手动运行sudo pip3 install --no-index --find-links="$HOME/2.13-Ink-screen-clock/bin/vendor" -r "$HOME/2.13-Ink-screen-clock/bin/requirements.txt" --break-system-packages" >&2
exit 1
fi
}
install_pip_packages() {
if [ "$USE_OFFLINE_PIP" = true ]; then
install_offline_pip_packages
else
install_oline_pip_packages
fi
}
# 复制服务文件并设置为开机启动 # 复制服务文件并设置为开机启动
setup_service() { setup_service() {
debug "正在设置墨水屏时钟服务..." local service_path="raspi_e-Paper.service"
if [ ! -d "$HOME/2.13-Ink-screen-clock" ]; then local service1_path="e-Paper_clean.service"
cd ~ local service_file_path="$HOME/2.13-Ink-screen-clock/bin/$service_path"
if ! git clone $INK_SCREEN_CLOCK_REPO_URL; then local service1_file_path="$HOME/2.13-Ink-screen-clock/bin/$service1_path"
echo "克隆墨水屏时钟仓库失败" >&2
exit 1
fi
# 设置start.sh和clean.sh脚本的执行权限
chmod +x "$HOME/2.13-Ink-screen-clock/bin/start.sh"
chmod +x "$HOME/2.13-Ink-screen-clock/bin/clean.sh"
fi
SERVICE_PATH="raspi_e-Paper.service" # 检查服务文件是否存在
SERVICE1_PATH="e-Paper_clean.service" if [ -f "$service_file_path" ] && [ -f "$service1_file_path" ]; then
SERVICE_FILE_PATH="$HOME/2.13-Ink-screen-clock/bin/$SERVICE_PATH" # 检查服务是否已经启用
SERVICE1_FILE_PATH="$HOME/2.13-Ink-screen-clock/bin/$SERVICE1_PATH" if ! systemctl is-enabled $service_path &>/dev/null && ! systemctl is-enabled $service1_path &>/dev/null; then
if [ -f "$SERVICE_FILE_PATH" ] && [ -f "$SERVICE1_FILE_PATH" ]; then echo "正在复制服务文件并启用服务"
# 复制服务文件到 systemd 目录 # 复制服务文件到 systemd 目录
if sudo cp "$SERVICE_FILE_PATH" /etc/systemd/system/ && sudo cp "$SERVICE1_FILE_PATH" /etc/systemd/system/; then if sudo cp "$service_file_path" /etc/systemd/system/ && sudo cp "$service1_file_path" /etc/systemd/system/; then
# 重载 systemd 管理器配置 # 重载 systemd 管理器配置
sudo systemctl daemon-reload sudo systemctl daemon-reload
# 启动服务 # 启动服务
sudo systemctl enable $SERVICE_PATH sudo systemctl enable $service_path
sudo systemctl enable $SERVICE1_PATH sudo systemctl enable $service1_path
sudo systemctl start $SERVICE_PATH sudo systemctl start $service_path
else
echo "复制服务文件失败" >&2
exit 1
fi
else
echo "服务文件已存在并启用,跳过复制"
fi
else else
echo "复制服务文件失败" >&2 echo "服务文件不存在于路径: $service_file_path$service1_file_path" >&2
exit 1 exit 1
fi fi
else }
echo "服务文件不存在于路径: $SERVICE_FILE_PATH$SERVICE1_FILE_PATH" >&2
exit 1 # 安装pisugar-power-manager函数
fi install_pisugar-power-manager() {
if [ "$USE_PISUGAR_POWER_MANAGER" = true ]; then
echo "正在安装pisugar-power-manager"
if ! curl -sSL "$PISUGAR_POWER_MANAGER_URL" | sudo bash -s - -c release; then
echo "pisugar-power-manager安装失败" >&2
echo "如需要请手动运行curl -sSL $PISUGAR_POWER_MANAGER_URL | sudo bash -s - -c release" >&2
exit 1
fi
fi
}
# 安装pisugar-wifi-conf函数
install_pisugar-wifi-conf() {
if [ "$USE_PISUGAR_WIFI_CONF" = true ]; then
echo "正在安装pisugar-wifi-conf"
if ! curl -sSL "$PISUGAR_WIFI_CONF_URL" | sudo bash; then
echo "pisugar-wifi-conf安装失败" >&2
echo "如需要请手动运行curl $PISUGAR_WIFI_CONF_URL | sudo bash" >&2
exit 1
fi
fi
} }
# 主逻辑 # 主逻辑
# 检测是否是Debian系统 # 检测是否是Debian系统
if [ -f /etc/debian_version ]; then if [ -f /etc/debian_version ]; then
debug "检测到Debian系统" echo "检测到Debian$DEBIAN_VERSION系统"
# 提取版本号的小数点前的部分 # 提取版本号的小数点前的部分
if ! MAJOR_VERSION=$(echo $DEBIAN_VERSION | cut -d '.' -f 1); then if ! MAJOR_VERSION=$(echo $DEBIAN_VERSION | cut -d '.' -f 1); then
@@ -175,23 +322,31 @@ if [ -f /etc/debian_version ]; then
# 检测是否是Raspberry Pi系统 # 检测是否是Raspberry Pi系统
if is_raspberry_pi; then if is_raspberry_pi; then
debug "检测到Raspberry Pi系统" echo "检测到Raspberry Pi系统"
# 根据版本号的小数点前的部分执行不同的命令 # 根据版本号的小数点前的部分执行不同的命令
case "$MAJOR_VERSION" in case "$MAJOR_VERSION" in
11) 11)
debug "执行Debian 11 (Bullseye) 相关操作" echo "执行Debian 11 (Bullseye) 相关操作"
update_sources_list "bullseye" update_sources_list "bullseye"
install_packages install_packages
install_Ink-screen-clock
install_pip_packages install_pip_packages
setup_service setup_service
#install_webui
install_pisugar-wifi-conf
install_pisugar-power-manager
;; ;;
12) 12)
debug "执行Debian 12 (Bookworm) 相关操作" echo "执行Debian 12 (Bookworm) 相关操作"
update_sources_list "bookworm" update_sources_list "bookworm"
install_packages install_packages
install_Ink-screen-clock
install_pip_packages install_pip_packages
setup_service setup_service
#install_webui
install_pisugar-wifi-conf
install_pisugar-power-manager
;; ;;
*) *)
echo "未知的Debian版本: $MAJOR_VERSION" >&2 echo "未知的Debian版本: $MAJOR_VERSION" >&2

View File

@@ -1,293 +1,333 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
from PIL import Image,ImageDraw,ImageFont #引入图片处理库 from PIL import Image,ImageDraw,ImageFont #引入图片处理库
import os,sys,re,json,time,datetime #引入系统相关库 import os,sys,re,json,time,datetime #引入系统相关库
from borax.calendars.lunardate import LunarDate #农历日期以及天干地支纪年法的 Python 库 from borax.calendars.lunardate import LunarDate #农历日期以及天干地支纪年法的 Python 库
import logging #日志库 import logging #日志库
import subprocess import subprocess
import os import os
from threading import Timer from threading import Timer
import requests import requests
white = 255 #颜色 import socket
black = 0
logging.basicConfig(level=logging.DEBUG) white = 255 #颜色
################################引入配置文件开始################################################ black = 0
picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic') logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s')
libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib') ################################引入配置文件开始################################################
if os.path.exists(libdir): picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
sys.path.append(libdir)#将引入文件添加到环境变量 libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
from waveshare_epd import epd2in13_V4 #引入墨水屏驱动文件 if os.path.exists(libdir):
logging.debug("Loading Fonts") sys.path.append(libdir)#将引入文件添加到环境变量
font01 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 20) #字体文件 from waveshare_epd import epd2in13_V4 #引入墨水屏驱动文件
font02 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 15) #字体文件 logging.debug("Loading Fonts")
font03 = ImageFont.truetype(os.path.join(picdir, 'DSEG7Modern-Bold.ttf'), 38) #字体文件 font01 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 20) #字体文件
font04 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 10) #字体文件 font02 = ImageFont.truetype(os.path.join(picdir, 'GB2312.ttf'), 15) #字体文件
font05 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 12) #字体文件 font03 = ImageFont.truetype(os.path.join(picdir, 'Fonttt.ttf'), 48) #字体文件
font06 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 13) #字体文件 font04 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 10) #字体文件
################################引入配置文件结束################################################ font05 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 12) #字体文件
def Local_strong_brush(): #局部强制刷新显示 font06 = ImageFont.truetype(os.path.join(picdir, '原神cn.ttf'), 13) #字体文件
i = 0 ################################引入配置文件结束################################################
while i < 5: def Local_strong_brush(): #局部强制刷新显示
epd.displayPartial(epd.getbuffer(info_image.rotate(180)))#局刷开始 i = 0
i = i + 1 while i < 5:
def getWeath(city='101060111'): #天气函数,下载json天气至本地 epd.displayPartial(epd.getbuffer(info_image.rotate(180)))#局刷开始
headers = { i = i + 1
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36 Edg/94.0.992.50', def get_date(): # 返回当前年月日及星期几
'Referer':'http://www.weather.com.cn/' date = datetime.datetime.now()
} today = LunarDate.today()
response = requests.get('http://d1.weather.com.cn/sk_2d/'+city+'.html',headers=headers) week_day_dict = {0: '星期一', 1: '星期二', 2: '星期三', 3: '星期四', 4: '星期五', 5: '星期六', 6: '星期日'}
response.encoding = 'utf-8' day = date.weekday()
Weath=response.text[11:] return f"{date.strftime('%Y年%m月%d')}{week_day_dict[day]}{today.strftime('农历%M月%D')}"
fileHandle=open('weather.json','w')
fileHandle.write(str(Weath)) # 定义一个全局标志变量,用于检查是否已经设置了系统时间或尝试过设置
fileHandle.close() has_set_system_time = False
Timer(1800, getWeath).start() #定时器函数,间隔三分钟下载文件至本地
print("天气文件更新") def set_system_time_from_hwclock(utc=True):
def gey_yiyan(): #一言API """Set the system time from the hardware clock.
response = requests.get("https://international.v1.hitokoto.cn/?c=k&c=f&c=d&c=a&encode=text&min_length=7&max_length=19")
response.encoding = 'utf-8' Args:
yiyan=response.text utc (bool): Whether the RTC is in UTC. Default is True.
return yiyan """
def get_date():#返回当前年月日及星期几 try:
date = datetime.datetime.now() # 记录调用 hwclock 前的时间
today=LunarDate.today() before_time = datetime.datetime.now()
week_day_dict = {0: '星期一',1: '星期二',2: '星期三',3: '星期四',4: '星期五',5: '星期六',6: '星期日',} logging.debug(f"System time before hwclock call: {before_time}")
day = date.weekday()
return time.strftime('%Y年%m月%d')+' '+week_day_dict[day]+' '+today.strftime('%M月%D') # 构造 hwclock 命令及其参数
def get_time():#返回当前时间,不到秒,大写 hwclock_args = ['sudo', 'hwclock', '--hctosys']
return time.strftime('%H:%M') if not utc:
def Get_address():#获取当前的IP地址 hwclock_args.append('--localtime')
return (subprocess.check_output(u"hostname -I | cut -d\' \' -f1 | head --bytes -1", shell = True ).decode('gbk'))
def CPU_temperature():#CPU温度获取 logging.debug(f"Executing hwclock command: {' '.join(hwclock_args)}")
temperatura = os.popen('vcgencmd measure_temp').readline()
temperatura = temperatura.replace('temp=','').strip() # 使用 subprocess.run 执行 hwclock --hctosys 并捕获输出
return str(temperatura) result = subprocess.run(hwclock_args,
def Memory_footprint():#显示内存占用百分比 check=True, # 如果命令失败,则抛出 CalledProcessError 异常
return(subprocess.check_output(u"free -m | awk -F '[ :]+' 'NR==2{printf \"%d\", ($3)/$2*100}'", shell = True ).decode('gbk')) stdout=subprocess.PIPE,
def CPU_usage(): #显示CPU占用百分比 stderr=subprocess.PIPE,
return(str(int(float(os.popen("top -b -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip())))) text=True)
def power_battery():
try: # 等待一小段时间以确保时间更新完成
# 获取电池电量 time.sleep(0.1) # 根据需要调整
battery_percentage = subprocess.check_output(
"echo \"get battery\" | nc -q 0 127.0.0.1 8423 | awk -F':' '{print $2}'", # 记录调用 hwclock 后的时间
shell=True, after_time = datetime.datetime.now()
text=True logging.debug("System time successfully set from hardware clock.")
).strip() logging.debug(f"System time after hwclock call: {after_time}")
# 检查电量信息 # 检查时间是否发生了倒退
if not battery_percentage: if after_time < before_time:
return "无效" logging.warning(f"Time went backwards after hwclock call: before={before_time}, after={after_time}")
# 返回电量百分比 return True
return f"{int(battery_percentage)}%" except subprocess.CalledProcessError as e:
except Exception as e: logging.error(f"Failed to set system time from hardware clock: {e.stderr}")
# 返回错误信息 return False
return "失败" except Exception as e:
logging.error(f"An unexpected error occurred: {str(e)}")
# 打印电量信息 return False
print(power_battery())
def Bottom_edge(): #在图片中添加底边内容 def get_time():
draw.rectangle((0, 105, 250, 122), 'black', 'black') global has_set_system_time
'''电池图标画图'''
draw.line((126,109,154,109),fill=255, width=1) #电池顶边 if not has_set_system_time:
draw.line((126,110,126,119),fill=255, width=1) #电池左边 # 尝试从硬件时钟设置系统时间,默认假设 RTC 是 UTC
draw.line((127,119,154,119),fill=255, width=1) #电池下边 success = set_system_time_from_hwclock(utc=True)
draw.line((154,110,154,118),fill=255, width=1) # 无论成功与否,都更新标志变量以避免重复尝试
draw.line((155,112,157,112),fill=255, width=1) has_set_system_time = True
draw.line((155,116,157,116),fill=255, width=1)
draw.line((157,113,157,115),fill=255, width=1) # 获取并返回当前时间,格式为 HH:MM 大写
global power_str current_time = time.strftime('%H:%M').upper()
power_str=power_battery() logging.debug(f"Returning current time: {current_time}")
draw.text((128,108),power_str,font = font04,fill =255) #显示当前电量百分比 return current_time
'''电池图标画图''' def Get_ipv4_address(): # 获取当前的IP地址
'''添加一言API''' try:
global Time_keeping ip_output = subprocess.check_output(
Time_keeping =0 "hostname -I | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}'", shell=True).decode('utf-8').strip()
draw.text((4,84),gey_yiyan(),font = font06,fill =0) ip_list = ip_output.split()
'''添加一言API end''' filtered_ips = [ip for ip in ip_list if not ip.startswith("172.")]
draw.ellipse((192, 107, 207, 120), 0, 255)# 时钟图标 return filtered_ips[0] if filtered_ips else "地址获取失败"
draw.line((199,109,199,114),fill=255, width=1) except subprocess.CalledProcessError:
draw.line((200,114,204,114),fill=255, width=1) return "获取失败"
global local_addr #获取当前IP地址 # 全局变量声明
local_addr= Get_address() #获取当前IP地址 last_power = None # 用于存储上一次获取的电量值
draw.text((10,107),"IP:"+local_addr,font = font05,fill =255)#显示当前IP地址 last_power_time = 0 # 用于存储上一次获取电量的时间戳
def Weather(): #在图片中添加天气内容
Weather_json = open('weather.json','r') def power_battery(): # 获取当前电池电量
Weather_data = Weather_json.read() global last_power, last_power_time
Weather_json.close() current_time = time.time() # 获取当前时间戳
Weather_text=json.loads(Weather_data)
global Weather_position # 每3分钟或首次获取时更新
global temperature if (current_time - last_power_time >= 180) or (last_power is None):
global weather try:
global wind_direction # 执行命令获取电池电量
global weather_update result = subprocess.check_output(
global weather_date u"echo \"get battery\" | nc -q 0 127.0.0.1 8423 | awk -F':' '{print int($2)}'",
global humidity shell=True, stderr=subprocess.STDOUT
Weather_position = Weather_text['cityname'] #定位位置 ).decode('gbk').strip()
temperature=Weather_text['temp']+u'°C' #温度 new_power = f"{int(result)}%" # 格式化电量值
weather = Weather_text['weather'] #天气情况
wind_direction = Weather_text['WD'] #风向 # 仅在电量变化或首次时更新显示
weather_update = Weather_text['time'] #天气更新时间 if new_power != last_power or last_power is None:
weather_date = Weather_text['date'] #日期 logging.info(f"电池电量更新: {new_power}")
humidity = Weather_text['SD'] #湿度 last_power = new_power # 更新缓存值
draw.text((150,25),"天气:",font = font06,fill =0)#显示当前天气前缀 last_power_time = current_time # 更新获取时间
draw.text((150,45),"温度:",font = font06,fill =0)#显示当前温度前缀 except Exception as e:
draw.text((150,65),"湿度:",font = font06,fill =0)#显示当前湿度前缀 logging.error(f"电量获取失败: {str(e)}")
draw.text((191,25),weather,font = font06,fill =0) new_power = last_power if last_power else "0%" # 失败时使用缓存值或默认值
draw.text((191,45),temperature,font = font06,fill =0) else:
draw.text((191,65),humidity,font = font06,fill =0) new_power = last_power # 未到更新时间,使用缓存值
draw.text((211,107),weather_update,font = font05,fill =255) #显示天气更新时间
return new_power
def Basic_refresh(): #全刷函数 # 打印电量信息
logging.info("Refresh and prepare the basic content before starting the canvas")#开始画布前刷新准备基础内容 print(power_battery())
epd.init() def Bottom_edge(): #在图片中添加底边内容
epd.Clear(0xFF) draw.rectangle((0, 105, 250, 122), 'black', 'black')
epd.init() '''电池图标画图'''
epd.Clear(0xFF) draw.line((126,109,154,109),fill=255, width=1) #电池顶边
global get_date_var draw.line((126,110,126,119),fill=255, width=1) #电池左边
get_date_var=get_date() #记录开始数据 draw.line((127,119,154,119),fill=255, width=1) #电池下边
draw.text((2,2),get_date_var,font = font02,fill =0)#将日期及星期几显示到屏幕 draw.line((154,110,154,118),fill=255, width=1)
global local_time draw.line((155,112,157,112),fill=255, width=1)
local_time=get_time() draw.line((155,116,157,116),fill=255, width=1)
draw.text((5,40),local_time,font = font03,fill =0)#显示当前时间 draw.line((157,113,157,115),fill=255, width=1)
Bottom_edge() #添加底边内容 global power_str
Weather() #天气内容 power_str=power_battery()
epd.display(epd.getbuffer(info_image.rotate(180))) draw.text((129,108),power_str,font = font04,fill =255) #显示当前电量百分比
def Partial_full_brush(): #局部定时全刷函数 '''电池图标画图'''
Basic_refresh() #全局刷新 draw.ellipse((192, 107, 207, 120), 0, 255)# 时钟图标
logging.debug("局部定时全局刷新") draw.line((199,109,199,114),fill=255, width=1)
epd.init() draw.line((200,114,204,114),fill=255, width=1)
def Partial_refresh():#局刷函数 global local_addr #获取当前IP地址
logging.info("Partial content update, this update is recommended to be synchronized with the minute to save the life of the ink screen")#局部内容更新,此更新建议与分钟同步,以节省墨水屏寿命 local_addr= Get_ipv4_address() #获取当前IP地址
epd.displayPartBaseImage(epd.getbuffer(info_image.rotate(180))) draw.text((10,107),"IP:"+local_addr,font = font05,fill =255)#显示当前IP地址
epd.init() def Weather():
while (True): try:
global local_time with open('/root/2.13-Ink-screen-clock/bin/weather.json', 'r') as Weather_json:
local_time1=get_time() Weather_data = Weather_json.read()
if (local_time1==local_time) ==False: if not Weather_data.strip(): # 检查文件是否为空
draw.rectangle((5, 40, 133, 82), fill = 255) #时间局刷区域 logging.error("天气数据文件为空")
draw.text((5,40),local_time1,font = font03,fill =0)#刷新当前时间 return
local_time=local_time1
Local_strong_brush() #局部强刷 Weather_text = json.loads(Weather_data)
get_date_var1=get_date() #局刷判断,如果时间与前一次不一致说明内容变化,需要刷新显示 global Weather_position, temperature, weather, wind_direction, weather_update, weather_date, humidity
global get_date_var #再次声明这个是全局变量
if(get_date_var1==get_date_var) ==False: Weather_position = Weather_text.get('cityname', '未知') # 使用get方法提供默认值
draw.rectangle((2, 2, 250, 16), fill = 255) #设置头部刷新区域 temperature = f"{Weather_text.get('temp', '--')}°C"
draw.text((2,2),get_date_var1,font = font02,fill =0)#将日期及星期几刷新显示到屏幕 weather = Weather_text.get('weather', '未知')
get_date_var=get_date_var1 #将更新的值保存到初始变量,直到下一次变化时执行该刷新操作 wind_direction = Weather_text.get('WD', '未知')
logging.debug("头部日期部位发生刷新变化.") weather_update = Weather_text.get('time', '未知')
Local_strong_brush() #局部强刷 weather_date = Weather_text.get('date', '未知')
global local_addr #当前IP地址 humidity = Weather_text.get('SD', '未知')
local_addr1 = Get_address() draw.text((150,25),"天气:",font = font06,fill =0)#显示当前天气前缀
if (local_addr1==local_addr) ==False: draw.text((150,45),"温度:",font = font06,fill =0)#显示当前温度前缀
draw.rectangle((1, 107, 94, 120), fill = 0) #设置头部刷新区域 draw.text((150,65),"湿度:",font = font06,fill =0)#显示当前湿度前缀
draw.text((10,107),"IP:"+local_addr1,font = font05,fill =255)#显示当前IP地址 draw.text((150,85),"城市:",font = font06,fill =0)#显示当前城市前缀
local_addr=local_addr1 draw.text((191,25),weather,font = font06,fill =0)
Local_strong_brush() #局部强刷 draw.text((191,45),temperature,font = font06,fill =0)
'''天气局部更新函数''' draw.text((191,65),humidity,font = font06,fill =0)
Weather_json = open('weather.json','r') draw.text((191,85),Weather_position,font = font06,fill =0)
Weather_data = Weather_json.read() draw.text((211,107),weather_update,font = font05,fill =255) #显示天气更新时间
Weather_json.close() except FileNotFoundError:
Weather_text=json.loads(Weather_data) logging.error("天气数据文件未找到")
global Weather_position except json.JSONDecodeError as e:
global temperature logging.error(f"天气数据解析失败: {str(e)}")
global weather except Exception as e:
global wind_direction logging.error(f"获取天气信息时发生错误: {str(e)}")
global weather_update def Basic_refresh(): #全刷函数
global weather_date logging.info("在启动画布之前,刷新并准备基本内容")#开始画布前刷新准备基础内容
global humidity global get_date_var
Weather_position1 = Weather_text['cityname'] #定位位置 get_date_var=get_date() #记录开始数据
temperature1=Weather_text['temp']+u'°C' #温度 draw.text((2,2),get_date_var,font = font02,fill =0)#将日期及星期几显示到屏幕
weather11 = Weather_text['weather'] #天气情况 global local_time
wind_direction1 = Weather_text['WD'] #风向 local_time=get_time()
weather_update1 = Weather_text['time'] #天气更新时间 draw.text((5,28),local_time,font = font03,fill =0)#显示当前时间
weather_date1 = Weather_text['date'] #日期 Bottom_edge() #添加底边内容
humidity1 = Weather_text['SD'] #湿度 Weather() #天气内容
if (weather11==weather) ==False: epd.display(epd.getbuffer(info_image.rotate(180)))
draw.rectangle((191, 25, 249, 38), fill = 255) #天气局刷区域 def Partial_full_brush(): #局部定时全刷函数
draw.text((191,25),weather11,font = font06,fill =0) Basic_refresh() #全局刷新
weather=weather11 logging.debug("局部定时全局刷新")
logging.info("天气局部刷新") epd.init()
Local_strong_brush() #局部强刷 def Partial_refresh():#局刷函数
if (temperature1==temperature) ==False: logging.info("部分内容更新,此更新建议与分钟同步,以节省墨水屏的使用寿命")#局部内容更新,此更新建议与分钟同步,以节省墨水屏寿命
draw.rectangle((191, 45, 249, 57), fill = 255) #局刷区域 epd.displayPartBaseImage(epd.getbuffer(info_image.rotate(180)))
draw.text((191,45),temperature1,font = font06,fill =0) epd.init()
temperature=temperature1 while (True):
logging.info("温度局部刷新") global local_time
Local_strong_brush() #局部强刷 local_time1=get_time()
if (humidity1==humidity) ==False: if (local_time1==local_time) ==False:
draw.rectangle((191, 65, 249, 77), fill = 255) #局刷区域 draw.rectangle((5, 28, 149, 82), fill = 255) #时间局刷区域
draw.text((191,65),humidity1,font = font06,fill =0) draw.text((5,28),local_time1,font = font03,fill =0)#刷新当前时间
humidity = humidity1 local_time=local_time1
logging.info("湿度局部刷新") Local_strong_brush() #局部强刷
Local_strong_brush() #局部强 get_date_var1=get_date() #局刷判断,如果时间与前一次不一致说明内容变化,需要刷新显示
if (weather_update1==weather_update) ==False: global get_date_var #再次声明这个是全局变量
draw.rectangle((211, 107, 248, 118), fill = 0) #设置更新时间刷新区域 if(get_date_var1==get_date_var) ==False:
draw.text((211,107),weather_update1,font = font05,fill =255) #显示天气更新时间 draw.rectangle((2, 2, 250, 16), fill = 255) #设置头部刷新区域
weather_update=weather_update1 draw.text((2,2),get_date_var1,font = font02,fill =0)#将日期及星期几刷新显示到屏幕
logging.info("天气更新时间局部刷新") get_date_var=get_date_var1 #将更新的值保存到初始变量,直到下一次变化时执行该刷新操作
Local_strong_brush() #局部强刷 logging.debug("头部日期部位发生刷新变化.")
'''天气局部更新函数''' Local_strong_brush() #局部强刷
global power_str global local_addr #当前IP地址
power_str1 =power_battery() local_addr1 = Get_ipv4_address()
if (power_str1==power_str) ==False: if (local_addr1==local_addr) ==False:
draw.rectangle((128, 110, 153, 117), fill = 0) #设置更新时间刷新区域 draw.rectangle((1, 107, 123, 120), fill = 0) #设置头部刷新区域
draw.text((127,108),power_battery(),font = font04,fill =255) #显示当前电量百分比 draw.text((10,107),"IP:"+local_addr1,font = font05,fill =255)#显示当前IP地址
power_str=power_str1 local_addr=local_addr1
Local_strong_brush() #局部强刷 Local_strong_brush() #局部强刷
logging.info("电源电量局部刷新") '''天气局部更新函数'''
'''一言API显示''' Weather_json = open('/root/2.13-Ink-screen-clock/bin/weather.json','r')
global Time_keeping Weather_data = Weather_json.read()
Time_keeping+=1 Weather_json.close()
if Time_keeping == 300 : #一言API局刷,当变量Time_keeping数据为10即开始执行 Weather_text=json.loads(Weather_data)
draw.rectangle((1, 82, 248, 101), fill = 255) global Weather_position
draw.text((4,84),gey_yiyan(),font = font06,fill =0) global temperature
Time_keeping=0 global weather
Local_strong_brush() #局部强刷 global wind_direction
logging.info("一言API局部刷新") global weather_update
'''一言API显示''' global weather_date
#epd.displayPartial(epd.getbuffer(info_image.rotate(180)))#局刷开始 global humidity
time.sleep(2) Weather_position1 = Weather_text['cityname'] #定位位置
#if time.strftime('%H%M%S')=='000000': #如果时间是晚上00点,执行全局刷新 temperature1=Weather_text['temp']+u'°C' #温度
#Partial_full_brush() #每天全局刷新一次 weather11 = Weather_text['weather'] #天气情况
try: wind_direction1 = Weather_text['WD'] #风向
##################屏幕初始化######################### weather_update1 = Weather_text['time'] #天气更新时间
getWeath()#天气获取函数开始运行 weather_date1 = Weather_text['date'] #日期
epd = epd2in13_V4.EPD() #初始化 humidity1 = Weather_text['SD'] #湿度
epd.init()#设定屏幕刷新模式 if (weather11==weather) ==False:
epd.Clear(0xFF) #清除屏幕内容 draw.rectangle((191, 25, 249, 38), fill = 255) #天气局刷区域
##################屏幕初始化######################### draw.text((191,25),weather11,font = font06,fill =0)
logging.info("Width = %s, Height = %s", format(epd.width), format(epd.height)) #打印屏幕高度及宽度 weather=weather11
logging.info("Initialize and clear the display")#屏幕开始准备相关展示 logging.info("天气局部刷新")
info_image = Image.new('1', (epd.height, epd.width), 255) #画布创建准备 Local_strong_brush() #局部强刷
draw = ImageDraw.Draw(info_image) if (temperature1==temperature) ==False:
Basic_refresh() #局刷 draw.rectangle((191, 45, 249, 57), fill = 255) #局刷区域
Partial_refresh() #局部刷新 draw.text((191,45),temperature1,font = font06,fill =0)
epd.init() temperature=temperature1
#epd.Clear(0xFF) logging.info("温度局部刷新")
epd.sleep() Local_strong_brush() #局部强刷
except IOError as e: if (humidity1==humidity) ==False:
logging.info(e) draw.rectangle((191, 65, 249, 77), fill = 255) #局刷区域
except KeyboardInterrupt: draw.text((191,65),humidity1,font = font06,fill =0)
logging.info("Keyboard interrupt detected, exiting gracefully.") humidity = humidity1
epd.init() logging.info("湿度局部刷新")
epd.Clear(0xFF) # 清除屏幕内容 Local_strong_brush() #局部强刷
epd.sleep() # 使屏幕进入休眠状态 if (Weather_position1==Weather_position) ==False:
epd2in13_V4.epdconfig.module_exit() # 清理资源 draw.rectangle((191, 85, 249, 98), fill = 255) #局刷区域
exit() draw.text((191,85),Weather_position1,font = font06,fill =0)
Weather_position = Weather_position1
except Exception as e: logging.info("城市局部刷新")
logging.error("An unexpected error occurred: %s", e) Local_strong_brush() #局部强刷
epd.init() if (weather_update1==weather_update) ==False:
epd.Clear(0xFF) # 清除屏幕内容 draw.rectangle((211, 107, 248, 118), fill = 0) #设置更新时间刷新区域
epd.sleep() # 使屏幕进入休眠状态 draw.text((211,107),weather_update1,font = font05,fill =255) #显示天气更新时间
epd2in13_V4.epdconfig.module_exit() # 清理资源 weather_update=weather_update1
exit() logging.info("天气更新时间局部刷新")
Local_strong_brush() #局部强刷
# 脚本正常结束后的清理操作 '''天气局部更新函数'''
epd.init() global power_str
epd.Clear(0xFF) # 清除屏幕内容 power_str1 =power_battery()
epd.sleep() # 使屏幕进入休眠状态 if (power_str1==power_str) ==False:
epd2in13_V4.epdconfig.module_exit() # 清理资源 draw.rectangle((128, 110, 153, 117), fill = 0) #设置更新时间刷新区域
exit() draw.text((129,108),power_battery(),font = font04,fill =255) #显示当前电量百分比
power_str=power_str1
Local_strong_brush() #局部强刷
# logging.info("电池电量局部刷新")
retry_interval = 180 # 设置重试间隔时间(秒)
while True:
try:
##################屏幕初始化#########################
epd = epd2in13_V4.EPD() #初始化
epd.init()#设定屏幕刷新模式
#epd.Clear(0xFF) #清除屏幕内容
##################屏幕初始化#########################
logging.info("Width = %s, Height = %s", format(epd.width), format(epd.height)) #打印屏幕高度及宽度
logging.info("初始化并清空显示屏")#屏幕开始准备相关展示
info_image = Image.new('1', (epd.height, epd.width), 255) #画布创建准备
draw = ImageDraw.Draw(info_image)
Basic_refresh() #全局刷新
Partial_refresh() #局部刷新
epd.init()
epd.Clear(0xFF)
epd.sleep()
time.sleep(300)
break # 如果脚本执行成功,则退出循环
except (OSError, Exception) as e: # 捕获你提到的异常
logging.error("发生了错误: %s", e)
time.sleep(retry_interval) # 等待一段时间后重试
except KeyboardInterrupt:
logging.info("检测到键盘中断,正在清理并退出")
epd.init()
epd.Clear(0xFF) # 清除屏幕内容
epd.sleep() # 使屏幕进入休眠状态
epd2in13_V4.epdconfig.module_exit() # 清理资源
exit()
# 脚本正常结束后的清理操作
epd.init()
epd.Clear(0xFF) # 清除屏幕内容
epd.sleep() # 使屏幕进入休眠状态
epd2in13_V4.epdconfig.module_exit() # 清理资源
exit()

258
bin/main.py1 Normal file
View File

@@ -0,0 +1,258 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from PIL import Image,ImageDraw,ImageFont #引入图片处理库
import os,sys,re,json,time,datetime #引入系统相关库
from borax.calendars.lunardate import LunarDate #农历日期以及天干地支纪年法的 Python 库
import logging #日志库
import subprocess
import os
from threading import Timer
import requests
import socket
white = 255 #颜色
black = 0
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s')
################################引入配置文件开始################################################
picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
if os.path.exists(libdir):
sys.path.append(libdir)#将引入文件添加到环境变量
from waveshare_epd import epd2in13_V4 #引入墨水屏驱动文件
logging.debug("Loading Fonts")
font01 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 20) #字体文件
font02 = ImageFont.truetype(os.path.join(picdir, 'GB2312.ttf'), 15) #字体文件
font03 = ImageFont.truetype(os.path.join(picdir, 'Fonttt.ttf'), 48) #字体文件
font04 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 10) #字体文件
font05 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 12) #字体文件
font06 = ImageFont.truetype(os.path.join(picdir, '原神cn.ttf'), 13) #字体文件
################################引入配置文件结束################################################
def Local_strong_brush(): #局部强制刷新显示
i = 0
while i < 5:
epd.displayPartial(epd.getbuffer(info_image.rotate(180)))#局刷开始
i = i + 1
def get_date():#返回当前年月日及星期几
date = datetime.datetime.now()
today=LunarDate.today()
week_day_dict = {0: '星期一',1: '星期二',2: '星期三',3: '星期四',4: '星期五',5: '星期六',6: '星期日',}
day = date.weekday()
return time.strftime('%Y年%m月%d日')+''+week_day_dict[day]+''+today.strftime('农历%M月%D')
def get_time():#返回当前时间,不到秒,大写
return time.strftime('%H:%M')
def Get_address():#获取当前的IP地址
return (subprocess.check_output(u"hostname -I | cut -d\' \' -f1 | head --bytes -1", shell = True ).decode('gbk'))
def Get_ipv4_address(): # 获取当前的IP地址
try:
# 执行命令获取IP地址并处理输出以仅返回IPv4地址
ip_output = subprocess.check_output("hostname -I | grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}'", shell=True).decode('utf-8').strip()
# 分割输出以获取单个IP地址列表
ip_list = ip_output.split()
# 过滤掉以172开头的IP地址
filtered_ips = [ip for ip in ip_list if not ip.startswith("172.")]
# 如果有有效的IP地址返回第一个否则返回获取失败
if filtered_ips:
return filtered_ips[0]
else:
return "地址获取失败"
except subprocess.CalledProcessError as e:
#logging.error("获取IPv4地址失败: %s", e)
return "获取失败"
def CPU_temperature():#CPU温度获取
temperatura = os.popen('vcgencmd measure_temp').readline()
temperatura = temperatura.replace('temp=','').strip()
return str(temperatura)
def Memory_footprint():#显示内存占用百分比
return(subprocess.check_output(u"free -m | awk -F '[ :]+' 'NR==2{printf \"%d\", ($3)/$2*100}'", shell = True ).decode('gbk'))
def CPU_usage(): #显示CPU占用百分比
return(str(int(float(os.popen("top -b -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip()))))
def power_battery():#获取当前电池电量
return(str(int(subprocess.check_output(u"echo \"get battery\" | nc -q 0 127.0.0.1 8423|awk -F':' '{print int($2)}'", shell = True ).decode('gbk')))+u'%')
# 打印电量信息
print(power_battery())
def Bottom_edge(): #在图片中添加底边内容
draw.rectangle((0, 105, 250, 122), 'black', 'black')
'''电池图标画图'''
draw.line((126,109,154,109),fill=255, width=1) #电池顶边
draw.line((126,110,126,119),fill=255, width=1) #电池左边
draw.line((127,119,154,119),fill=255, width=1) #电池下边
draw.line((154,110,154,118),fill=255, width=1)
draw.line((155,112,157,112),fill=255, width=1)
draw.line((155,116,157,116),fill=255, width=1)
draw.line((157,113,157,115),fill=255, width=1)
global power_str
power_str=power_battery()
draw.text((129,108),power_str,font = font04,fill =255) #显示当前电量百分比
'''电池图标画图'''
draw.ellipse((192, 107, 207, 120), 0, 255)# 时钟图标
draw.line((199,109,199,114),fill=255, width=1)
draw.line((200,114,204,114),fill=255, width=1)
global local_addr #获取当前IP地址
local_addr= Get_ipv4_address() #获取当前IP地址
draw.text((10,107),"IP:"+local_addr,font = font05,fill =255)#显示当前IP地址
def Weather(): #在图片中添加天气内容
Weather_json = open('/root/2.13-Ink-screen-clock/bin/weather.json','r')
Weather_data = Weather_json.read()
Weather_json.close()
Weather_text=json.loads(Weather_data)
global Weather_position
global temperature
global weather
global wind_direction
global weather_update
global weather_date
global humidity
Weather_position = Weather_text['cityname'] #定位位置
temperature=Weather_text['temp']+u'°C' #温度
weather = Weather_text['weather'] #天气情况
wind_direction = Weather_text['WD'] #风向
weather_update = Weather_text['time'] #天气更新时间
weather_date = Weather_text['date'] #日期
humidity = Weather_text['SD'] #湿度
draw.text((150,25),"天气:",font = font06,fill =0)#显示当前天气前缀
draw.text((150,45),"温度:",font = font06,fill =0)#显示当前温度前缀
draw.text((150,65),"湿度:",font = font06,fill =0)#显示当前湿度前缀
draw.text((150,85),"城市:",font = font06,fill =0)#显示当前城市前缀
draw.text((191,25),weather,font = font06,fill =0)
draw.text((191,45),temperature,font = font06,fill =0)
draw.text((191,65),humidity,font = font06,fill =0)
draw.text((191,85),Weather_position,font = font06,fill =0)
draw.text((211,107),weather_update,font = font05,fill =255) #显示天气更新时间
def Basic_refresh(): #全刷函数
logging.info("在启动画布之前,刷新并准备基本内容")#开始画布前刷新准备基础内容
global get_date_var
get_date_var=get_date() #记录开始数据
draw.text((2,2),get_date_var,font = font02,fill =0)#将日期及星期几显示到屏幕
global local_time
local_time=get_time()
draw.text((5,28),local_time,font = font03,fill =0)#显示当前时间
Bottom_edge() #添加底边内容
Weather() #天气内容
epd.display(epd.getbuffer(info_image.rotate(180)))
def Partial_full_brush(): #局部定时全刷函数
Basic_refresh() #全局刷新
logging.debug("局部定时全局刷新")
epd.init()
def Partial_refresh():#局刷函数
logging.info("部分内容更新,此更新建议与分钟同步,以节省墨水屏的使用寿命")#局部内容更新,此更新建议与分钟同步,以节省墨水屏寿命
epd.displayPartBaseImage(epd.getbuffer(info_image.rotate(180)))
epd.init()
while (True):
global local_time
local_time1=get_time()
if (local_time1==local_time) ==False:
draw.rectangle((5, 28, 149, 82), fill = 255) #时间局刷区域
draw.text((5,28),local_time1,font = font03,fill =0)#刷新当前时间
local_time=local_time1
Local_strong_brush() #局部强刷
get_date_var1=get_date() #局刷判断,如果时间与前一次不一致说明内容变化,需要刷新显示
global get_date_var #再次声明这个是全局变量
if(get_date_var1==get_date_var) ==False:
draw.rectangle((2, 2, 250, 16), fill = 255) #设置头部刷新区域
draw.text((2,2),get_date_var1,font = font02,fill =0)#将日期及星期几刷新显示到屏幕
get_date_var=get_date_var1 #将更新的值保存到初始变量,直到下一次变化时执行该刷新操作
logging.debug("头部日期部位发生刷新变化.")
Local_strong_brush() #局部强刷
global local_addr #当前IP地址
local_addr1 = Get_ipv4_address()
if (local_addr1==local_addr) ==False:
draw.rectangle((1, 107, 123, 120), fill = 0) #设置头部刷新区域
draw.text((10,107),"IP:"+local_addr1,font = font05,fill =255)#显示当前IP地址
local_addr=local_addr1
Local_strong_brush() #局部强刷
'''天气局部更新函数'''
Weather_json = open('/root/2.13-Ink-screen-clock/bin/weather.json','r')
Weather_data = Weather_json.read()
Weather_json.close()
Weather_text=json.loads(Weather_data)
global Weather_position
global temperature
global weather
global wind_direction
global weather_update
global weather_date
global humidity
Weather_position1 = Weather_text['cityname'] #定位位置
temperature1=Weather_text['temp']+u'°C' #温度
weather11 = Weather_text['weather'] #天气情况
wind_direction1 = Weather_text['WD'] #风向
weather_update1 = Weather_text['time'] #天气更新时间
weather_date1 = Weather_text['date'] #日期
humidity1 = Weather_text['SD'] #湿度
if (weather11==weather) ==False:
draw.rectangle((191, 25, 249, 38), fill = 255) #天气局刷区域
draw.text((191,25),weather11,font = font06,fill =0)
weather=weather11
logging.info("天气局部刷新")
Local_strong_brush() #局部强刷
if (temperature1==temperature) ==False:
draw.rectangle((191, 45, 249, 57), fill = 255) #局刷区域
draw.text((191,45),temperature1,font = font06,fill =0)
temperature=temperature1
logging.info("温度局部刷新")
Local_strong_brush() #局部强刷
if (humidity1==humidity) ==False:
draw.rectangle((191, 65, 249, 77), fill = 255) #局刷区域
draw.text((191,65),humidity1,font = font06,fill =0)
humidity = humidity1
logging.info("湿度局部刷新")
Local_strong_brush() #局部强刷
if (Weather_position1==Weather_position) ==False:
draw.rectangle((191, 85, 249, 98), fill = 255) #局刷区域
draw.text((191,85),Weather_position1,font = font06,fill =0)
Weather_position = Weather_position1
logging.info("城市局部刷新")
Local_strong_brush() #局部强刷
if (weather_update1==weather_update) ==False:
draw.rectangle((211, 107, 248, 118), fill = 0) #设置更新时间刷新区域
draw.text((211,107),weather_update1,font = font05,fill =255) #显示天气更新时间
weather_update=weather_update1
logging.info("天气更新时间局部刷新")
Local_strong_brush() #局部强刷
'''天气局部更新函数'''
global power_str
power_str1 =power_battery()
if (power_str1==power_str) ==False:
draw.rectangle((128, 110, 153, 117), fill = 0) #设置更新时间刷新区域
draw.text((129,108),power_battery(),font = font04,fill =255) #显示当前电量百分比
power_str=power_str1
Local_strong_brush() #局部强刷
# logging.info("电池电量局部刷新")
retry_interval = 180 # 设置重试间隔时间(秒)
while True:
try:
##################屏幕初始化#########################
epd = epd2in13_V4.EPD() #初始化
epd.init()#设定屏幕刷新模式
#epd.Clear(0xFF) #清除屏幕内容
##################屏幕初始化#########################
logging.info("Width = %s, Height = %s", format(epd.width), format(epd.height)) #打印屏幕高度及宽度
logging.info("初始化并清空显示屏")#屏幕开始准备相关展示
info_image = Image.new('1', (epd.height, epd.width), 255) #画布创建准备
draw = ImageDraw.Draw(info_image)
Basic_refresh() #全局刷新
Partial_refresh() #局部刷新
epd.init()
epd.Clear(0xFF)
epd.sleep()
time.sleep(300)
break # 如果脚本执行成功,则退出循环
except (OSError, Exception) as e: # 捕获你提到的异常
logging.error("发生了错误: %s", e)
time.sleep(retry_interval) # 等待一段时间后重试
except KeyboardInterrupt:
logging.info("检测到键盘中断,正在清理并退出")
epd.init()
epd.Clear(0xFF) # 清除屏幕内容
epd.sleep() # 使屏幕进入休眠状态
epd2in13_V4.epdconfig.module_exit() # 清理资源
exit()
# 脚本正常结束后的清理操作
epd.init()
epd.Clear(0xFF) # 清除屏幕内容
epd.sleep() # 使屏幕进入休眠状态
epd2in13_V4.epdconfig.module_exit() # 清理资源
exit()

View File

@@ -1,15 +1,14 @@
[Unit] [Unit]
Description=Raspi e-Paper Service Description=Raspi e-Paper Service
After=network-online.target After=network.target
[Service] [Service]
Type=forking Type=forking
# 等待网络完全启动
#ExecStartPre=systemd-networkd-wait-online --timeout=30
ExecStart=/root/2.13-Ink-screen-clock/bin/start.sh ExecStart=/root/2.13-Ink-screen-clock/bin/start.sh
ExecStop=/usr/bin/screen -S main_screen -X quit ExecStop=/bin/bash -c "pkill -f /root/2.13-Ink-screen-clock/bin/main.py; pkill -f /root/2.13-Ink-screen-clock/bin/weather.py"
Restart=on-failure WorkingDirectory=/root/2.13-Ink-screen-clock/bin
Restart=always
User=root User=root
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

8
bin/requirements.txt Normal file
View File

@@ -0,0 +1,8 @@
borax==4.1.2
certifi==2025.1.31
charset-normalizer==3.4.1
idna==3.10
pillow==11.1.0
requests==2.32.3
spidev==3.6
urllib3==2.3.0

View File

@@ -1,15 +1,14 @@
#!/bin/bash #!/bin/bash
f_name=main.py f_name=main.py
f1_name=weather.py
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
logdir=${dir%/*} logdir="${dir%/*}/log"
screen_name="main_screen" # 确保日志目录存在
mkdir -p "${logdir}"
# 查找并结束所有与指定screen_name相关的screen会话 pid=`ps -ef |grep $dir/$f_name | grep -v grep |awk '{print $2}'`
pids=$(screen -ls | grep $screen_name | awk -F '.' '{print $1}' | awk '{print $1}') for id in $pid
for pid in $pids; do do
screen -S $pid -X quit kill -9 $id
done done
nohup /usr/bin/python3 -u $dir/$f_name > $logdir/info.log 2>&1 &
# 创建一个新的screen会话并运行Python脚本 nohup /usr/bin/python3 -u $dir/$f1_name > $logdir/info-weather.log 2>&1 &
screen -dmS $screen_name /usr/bin/python3 -u $dir/$f_name > $logdir/log/info.log 2>&1

BIN
bin/vendor/borax-4.1.2-py3-none-any.whl vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
bin/vendor/idna-3.10-py3-none-any.whl vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
bin/vendor/spidev-3.6.tar.gz vendored Normal file

Binary file not shown.

Binary file not shown.

192
bin/weather.py Normal file
View File

@@ -0,0 +1,192 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
import json
import time
import logging
import requests
import random
import socket
from functools import wraps
from threading import Timer
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
def check_network_connection():
"""检查网络连接状态"""
try:
# 尝试连接一个可靠的公共DNS服务器
socket.create_connection(("223.5.5.5", 53), timeout=5)
return True
except OSError:
return False
def get_ip():
"""改进的IP获取函数"""
if not check_network_connection():
logging.warning("网络连接不可用")
return None
services = [
{"url": "https://api.ipify.org?format=json", "field": "ip"},
{"url": "https://ipinfo.io/json", "field": "ip"},
{"url": "https://ifconfig.me/all.json", "field": "ip_addr"}
]
for service in services:
try:
resp = requests.get(service["url"], timeout=10)
data = resp.json()
return data.get(service["field"])
except Exception:
continue
logging.error("所有IP服务尝试失败")
return None
def get_ip():
"""从ip.cn获取当前IP地址"""
url = "https://ip.cn/api/index?ip=&type=0"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}
try:
resp = requests.get(url, headers=headers, timeout=10)
resp.raise_for_status()
data = resp.json()
if data.get('code') == 'Success':
return data.get('ip', '')
logging.error("获取IP失败: %s", data.get('msg', '未知错误'))
except Exception as e:
logging.error("获取IP异常: %s", str(e))
return None
def get_current_city():
"""通过IP地址获取当前定位城市并去除''后缀"""
ip = get_ip()
if not ip:
return None
url = f"http://ip-api.com/json/{ip}?fields=city&lang=zh-CN"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}
while True:
try:
resp = requests.get(url, headers=headers, timeout=10)
data = resp.json()
if data.get('status') == 'success':
return data.get('city', '').replace('', '')
logging.error("定位失败: %s", data.get('message', '未知错误'))
except Exception as e:
logging.error("定位异常: %s", str(e))
time.sleep(180)
def schedule_getWeath():
"""改进的定时任务调度"""
retry_count = 0
max_retries = 3
while retry_count < max_retries:
try:
getWeath()
break
except Exception as e:
retry_count += 1
wait_time = min(300, retry_count * 60) # 指数退避
logging.error(f"天气更新失败({retry_count}/{max_retries}): {str(e)}")
time.sleep(wait_time)
# 无论成功与否,都安排下一次执行
Timer(1800, schedule_getWeath).start() # 30分钟间隔
def getWeath(default_city='101060101'):
"""改进的天气获取函数"""
# 1. 检查网络连接
if not check_network_connection():
logging.error("网络不可用,跳过天气更新")
return
# 2. 获取城市信息
city_name = None
try:
city_name = get_current_city()
except Exception as e:
logging.error(f"获取城市失败: {str(e)}")
# 3. 确定区域ID
area_id = default_city
if city_name:
try:
found_id = get_area_id(city_name)
if found_id:
area_id = found_id
logging.info(f"使用城市区域ID: {area_id} ({city_name})")
except Exception as e:
logging.error(f"获取区域ID失败: {str(e)}")
# 4. 获取天气数据
weather_apis = [
f'https://d1.weather.com.cn/sk_2d/{area_id}.html',
f'https://www.weather.com.cn/weather1d/{area_id}.shtml'
]
for api_url in weather_apis:
try:
resp = requests.get(
api_url,
headers={'User-Agent': 'Mozilla/5.0'},
timeout=15
)
resp.raise_for_status()
# 处理不同API的响应格式
if 'sk_2d' in api_url:
weather_data = resp.content[11:].decode('utf-8')
else:
weather_data = parse_html_weather(resp.text)
# 验证数据有效性
if validate_weather_data(weather_data):
with open('/root/2.13-Ink-screen-clock/bin/weather.json', 'w') as f:
json.dump(weather_data, f)
logging.info("天气数据更新成功")
return
except Exception as e:
logging.warning(f"天气API {api_url} 失败: {str(e)}")
continue
logging.error("所有天气API尝试失败")
def get_area_id(city_name):
"""从city.js中检索AREAID无限重试直到成功"""
url = "https://j.i8tq.com/weather2020/search/city.js"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}
while True:
try:
resp = requests.get(url, headers=headers, timeout=10)
resp.encoding = 'utf-8'
city_data = json.loads(resp.text.split('=', 1)[1].rstrip(';'))
for province in city_data.values():
for city in province.values():
for district, info in city.items():
if info['NAMECN'] == city_name:
return info['AREAID']
logging.error("未找到城市: %s", city_name)
except Exception as e:
logging.error("获取城市ID失败: %s", str(e))
time.sleep(180)
if __name__ == "__main__":
try:
schedule_getWeath()
while True:
time.sleep(1)
except KeyboardInterrupt:
logging.info("程序已终止")

BIN
pic/1736749257603.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 MiB

BIN
pic/Fonttt.ttf Normal file

Binary file not shown.

BIN
pic/GB2312.ttf Normal file

Binary file not shown.

BIN
pic/SmileySans-Oblique.otf Normal file

Binary file not shown.

Binary file not shown.

BIN
pic/SmileySans-Oblique.ttf Normal file

Binary file not shown.

Binary file not shown.

BIN
pic/原神cn.ttf Normal file

Binary file not shown.

BIN
pic/星穹铁道cn.ttf Normal file

Binary file not shown.