34 Commits

Author SHA1 Message Date
星光-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
12 changed files with 42 additions and 1461 deletions

View File

@@ -1,79 +0,0 @@
from flask import Flask, render_template, request, send_from_directory, redirect, url_for, jsonify
import os
import re
import subprocess
app = Flask(__name__, template_folder='webui', static_url_path='', static_folder='webui')
FONT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'pic') # 字体文件夹路径
MAIN_PY_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'bin', 'main.py')
def list_font_files(font_dir):
try:
return os.listdir(font_dir)
except Exception as e:
print(f"Error listing font files: {e}")
return [] # 返回空列表以避免迭代错误
@app.route('/execute-shell')
def execute_shell():
# 替换以下命令为您想要执行的Shell命令
command = "sudo reboot now"
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.returncode == 0:
return jsonify({'status': 'success', 'output': result.stdout})
else:
return jsonify({'status': 'error', 'output': result.stderr})
@app.route('/edit_main_py')
def edit_main_py():
try:
with open(MAIN_PY_PATH, 'r') as file:
content = file.read()
except Exception as e:
return f"Error reading main.py: {e}", 500
return render_template('edit_main_py.html', content=content)
@app.route('/save_main_py', methods=['POST'])
def save_main_py():
new_content = request.form.get('content')
if new_content is None:
return "No content provided", 400
try:
with open(MAIN_PY_PATH, 'w') as file:
file.write(new_content)
except Exception as e:
return f"Error saving main.py: {e}", 500
return redirect(url_for('index'))
@app.route('/')
def index():
font_files = list_font_files(FONT_DIR)
return render_template('index.html', font_files=font_files)
@app.route('/upload', methods=['POST'])
def upload():
if 'font_file' not in request.files:
return '没有文件部分'
file = request.files['font_file']
if file.filename == '':
return '没有选择文件'
if file:
filename = os.path.join(FONT_DIR, file.filename)
file.save(filename)
return '文件已上传成功'
@app.route('/update_font_names')
def update_font_names():
font_files = list_font_files(FONT_DIR)
return render_template('update_font_names.html', font_files=font_files)
@app.route('/fonts/<filename>')
def fonts(filename):
return send_from_directory(FONT_DIR, filename)
if not os.path.exists(FONT_DIR):
os.makedirs(FONT_DIR)
if __name__ == '__main__':
# 绑定到0.0.0.0,允许远程访问
app.run(host='0.0.0.0', port=80, debug=False)

View File

@@ -1,9 +0,0 @@
/*!
Theme: Default
Description: Original highlight.js style
Author: (c) Ivan Sagalaev <maniac@softwaremaniacs.org>
Maintainer: @highlightjs/core-team
Website: https://highlightjs.org/
License: see project LICENSE
Touched: 2021
*/pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{background:#f3f3f3;color:#444}.hljs-comment{color:#697070}.hljs-punctuation,.hljs-tag{color:#444a}.hljs-tag .hljs-attr,.hljs-tag .hljs-name{color:#444}.hljs-attribute,.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-name,.hljs-selector-tag{font-weight:700}.hljs-deletion,.hljs-number,.hljs-quote,.hljs-selector-class,.hljs-selector-id,.hljs-string,.hljs-template-tag,.hljs-type{color:#800}.hljs-section,.hljs-title{color:#800;font-weight:700}.hljs-link,.hljs-operator,.hljs-regexp,.hljs-selector-attr,.hljs-selector-pseudo,.hljs-symbol,.hljs-template-variable,.hljs-variable{color:#ab5656}.hljs-literal{color:#695}.hljs-addition,.hljs-built_in,.hljs-bullet,.hljs-code{color:#397300}.hljs-meta{color:#1f7199}.hljs-meta .hljs-string{color:#38a}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}

View File

@@ -1,59 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>编辑 main.py</title>
<!-- 引用本地的highlight.js CSS -->
<link rel="stylesheet" href="{{ url_for('static', filename='default.min.css') }}">
</head>
<body>
<h1>编辑 main.py</h1>
<!-- 添加一个表单来提交编辑后的代码 -->
<form method="post" action="{{ url_for('save_main_py') }}">
<pre style="background-color: black !important;"><code class="python" id="code">{{ content }}</code></pre>
<input type="hidden" name="content" id="hidden-content">
<input type="submit" value="保存">
</form>
<!-- 引用本地的highlight.js JavaScript -->
<script src="{{ url_for('static', filename='highlight.min.js') }}"></script>
<script>
// 初始化highlight.js
document.addEventListener('DOMContentLoaded', (event) => {
hljs.highlightAll();
});
</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
var preElements = document.querySelectorAll('pre.code-editor');
preElements.forEach(function(pre) {
pre.style.backgroundColor = 'black';
});
});
</script>
<h2>重启</h2>
</head>
<body>
<button id="executeShellBtn">重启</button>
<script>
document.getElementById('executeShellBtn').addEventListener('click', function() {
fetch('/execute-shell')
.then(response => response.json())
.then(data => {
if (data.status === 'success') {
alert('Command executed successfully:\n' + data.output);
} else {
alert('Error executing command:\n' + data.output);
}
})
.catch(error => {
alert('Error: ' + error);
});
});
</script>
</body>
</html>
 

File diff suppressed because one or more lines are too long

View File

@@ -1,27 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>字体上传和管理</title>
</head>
<body>
<h1>上传字体文件</h1>
<form method="post" action="/upload" enctype="multipart/form-data">
<input type="file" name="font_file">
<input type="submit" value="上传">
</form>
<h2>已上传的字体文件:</h2>
<ul>
{% for font_file in font_files %}
<li>{{ font_file }}</li>
{% else %}
<li>没有找到字体文件。</li>
{% endfor %}
</ul>
<!-- 添加跳转到edit_main_py的按钮 -->
<a href="/edit_main_py"><button>编辑main.py</button></a>
</body>
</html>

View File

@@ -1,26 +0,0 @@
<!-- update_font_names.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>更新字体文件名</title>
</head>
<body>
<h1>更新字体文件名</h1>
<form method="post" action="/save_font_names">
<label for="font01">字体文件名 01:</label>
<input type="text" id="font01" name="font01"><br>
<label for="font02">字体文件名 02:</label>
<input type="text" id="font02" name="font02"><br>
<label for="font03">字体文件名 03:</label>
<input type="text" id="font03" name="font03"><br>
<label for="font04">字体文件名 04:</label>
<input type="text" id="font04" name="font04"><br>
<label for="font05">字体文件名 05:</label>
<input type="text" id="font05" name="font05"><br>
<label for="font06">字体文件名 06:</label>
<input type="text" id="font06" name="font06"><br>
<input type="submit" value="保存">
</form>
</body>
</html>

View File

@@ -4,8 +4,7 @@ f_name="clean.py"
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
logdir="${dir%/*}/log"
service_name="raspi_e-Paper.service"
hold_time_seconds=5 # 设置维持时间例如300秒5分钟
# 停止raspi_e-Paper服务
echo "正在停止$service_name服务..."
sudo systemctl stop "$service_name"
@@ -19,9 +18,6 @@ if [ -n "$pids" ]; then
kill -9 $pids
fi
# 使用nohup在后台运行Python脚本并将输出重定向到日志文件
nohup /usr/bin/python3 -u "$dir/$f_name" > "${logdir}/info-clean.log" 2>&1 &
# 等待维持时间
echo "正在运行脚本,将在 ${hold_time_seconds} 秒后停止服务..."
sleep $hold_time_seconds
echo "正在清除屏幕内容"
# 运行Python脚本并将输出重定向到日志文件
/usr/bin/python3 -u "$dir/$f_name" > "${logdir}/info-clean.log" 2>&1

View File

@@ -121,25 +121,14 @@ is_raspberry_pi() {
fi
}
# 定义链接变量
DEBIAN_MIRROR="http://deb.debian.org/debian/"
DEBIAN_SECURITY_MIRROR="http://security.debian.org/"
PISUGAR_WIFI_CONF_URL="https://cdn.pisugar.com/PiSugar-wificonfig/script/install.sh"
PISUGAR_POWER_MANAGER_URL="https://cdn.pisugar.com/release/pisugar-power-manager.sh"
PIPY_MIRROR="https://pypi.org/simple"
# 修改 Raspberry Pi 特定源链接
RASPBERRY_PI_SOURCE_DEBIAN11="https://archive.raspberrypi.org/debian/"
RASPBERRY_PI_SOURCE_DEBIAN12="https://archive.raspberrypi.com/debian/"
# 如果使用中国镜像源,则更新链接变量
if [ "$USE_CN_MIRROR" = true ]; then
DEBIAN_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/debian/"
# 使用中国镜像源
DEBIAN_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/debian"
DEBIAN_SECURITY_MIRROR="https://mirrors.tuna.tsinghua.edu.cn/debian-security"
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/"
fi
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"
@@ -155,6 +144,7 @@ update_sources_list() {
local raspberry_pi_source_in_use=$(grep -oP 'deb\s+\K.+' /etc/apt/sources.list.d/raspi.list | head -1)
# 检查并替换 Debian 源
if [ "$USE_CN_MIRROR" = true ]; then
if [ "$debian_mirror_in_use" != "$DEBIAN_MIRROR" ]; then
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
{
@@ -196,12 +186,13 @@ update_sources_list() {
else
echo "Raspberry Pi 源链接已更新,跳过替换" >&2
fi
fi
}
# 安装包函数
install_packages() {
echo "正在更新源列表"
if ! sudo apt-get -q -y update; then
if ! sudo apt-get -q update; then
echo "更新源列表失败" >&2
exit 1
fi
@@ -317,6 +308,7 @@ if [ -f /etc/debian_version ]; then
install_packages
install_pip_packages
setup_service
#install_webui
install_pisugar-wifi-conf
install_pisugar-power-manager
;;
@@ -326,6 +318,7 @@ if [ -f /etc/debian_version ]; then
install_packages
install_pip_packages
setup_service
#install_webui
install_pisugar-wifi-conf
install_pisugar-power-manager
;;

View File

@@ -37,7 +37,7 @@ def get_date():#返回当前年月日及星期几
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')
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地址
@@ -46,13 +46,18 @@ 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()
# 检查是否为IPv4地址
if ip_output and not ip_output.startswith("127."):
return ip_output
# 分割输出以获取单个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 "IPv4获取失败"
return "地址获取失败"
except subprocess.CalledProcessError as e:
return f"获取失败"
logging.error("获取IPv4地址失败: %s", e)
return "获取失败"
def CPU_temperature():#CPU温度获取
temperatura = os.popen('vcgencmd measure_temp').readline()
temperatura = temperatura.replace('temp=','').strip()
@@ -213,7 +218,7 @@ def Partial_refresh():#局刷函数
draw.text((129,108),power_battery(),font = font04,fill =255) #显示当前电量百分比
power_str=power_str1
Local_strong_brush() #局部强刷
logging.info("电源电量局部刷新")
# logging.info("电源电量局部刷新")
try:
##################屏幕初始化#########################
epd = epd2in13_V4.EPD() #初始化

View File

@@ -4,12 +4,11 @@ After=network.target
[Service]
Type=forking
# 等待网络完全启动
ExecStartPre=/bin/bash -c 'until ping -c1 baidu.com &>/dev/null; do sleep 1; done'
ExecStart=/root/2.13-Ink-screen-clock/bin/start.sh
ExecStop=/usr/bin/screen -S main_screen -X quit
Restart=on-failure
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"
WorkingDirectory=/root/2.13-Ink-screen-clock/bin
Restart=always
User=root
[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target

View File

@@ -1,10 +1,8 @@
#!/bin/bash
f_name=main.py
f1_name=weather.py
f2_name=app.py
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
logdir="${dir%/*}/log"
appdir="${dir%/*}/app"
# 确保日志目录存在
mkdir -p "${logdir}"
pid=`ps -ef |grep $dir/$f_name | grep -v grep |awk '{print $2}'`
@@ -14,4 +12,3 @@ do
done
nohup /usr/bin/python3 -u $dir/$f_name > $logdir/info.log 2>&1 &
nohup /usr/bin/python3 -u $dir/$f1_name > $logdir/info-wenter.log 2>&1 &
nohup /usr/bin/python3 -u $appdir/$f2_name > $logdir/info-app.log 2>&1 &

View File

@@ -41,7 +41,7 @@ def get_area_id(city_name):
logging.error("从city.js接收到的数据为空")
except (requests.RequestException, json.JSONDecodeError) as e:
logging.error("检索或解析城市数据时发生错误: %s", e)
time.sleep(5) # 重试前等待5秒
time.sleep(180) # 重试前等待
def get_current_city():
"""获取当前城市名称,无限重试直到成功"""
@@ -57,13 +57,18 @@ def get_current_city():
logging.error("获取当前城市失败: %s", data['message'])
except (requests.RequestException, json.JSONDecodeError) as e:
logging.error("检索或解析当前城市时出现错误: %s", e)
time.sleep(5) # 重试前等待5秒
time.sleep(180) # 重试前等待
# 注意:无限重试可能会在特定情况下导致程序无法终止,请确保在实际使用中考虑适当的退出条件或限制重试次数。
def schedule_getWeath():
"""调度 getWeath 函数每3分钟执行一次"""
getWeath()
Timer(180, schedule_getWeath).start() # 重新设置定时器
def getWeath(city='101060101'):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
'Referer': 'http://www.weather.com.cn/'
'Referer': 'https://www.weather.com.cn/'
}
current_city = get_current_city()
if current_city:
@@ -71,14 +76,13 @@ def getWeath(city='101060101'):
if area_id:
city = area_id
try:
response = requests.get('http://d1.weather.com.cn/sk_2d/'+city+'.html',headers=headers)
response = requests.get('https://d1.weather.com.cn/sk_2d/'+city+'.html',headers=headers)
response.raise_for_status() # 检查请求是否成功
response.encoding = 'utf-8'
Weath = response.text[11:]
fileHandle = open('/root/2.13-Ink-screen-clock/bin/weather.json', 'w')
fileHandle.write(str(Weath))
fileHandle.close()
Timer(180, getWeath).start() # 定时器函数,间隔三分钟下载文件至本地
print("天气文件更新")
except requests.RequestException as e:
logging.error("获取天气数据时出现网络错误: %s", e)
@@ -86,8 +90,8 @@ def getWeath(city='101060101'):
logging.error("发生了意外错误: %s", e)
try:
getWeath() # 天气获取函数开始运行
except IOError as e:
schedule_getWeath() # 开始调度天气获取函数
except OSError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("检测到键盘中断,正在退出")
@@ -96,4 +100,4 @@ except Exception as e:
exit()
# 脚本正常结束后的清理操作
exit()
exit()