24 Commits

Author SHA1 Message Date
星光-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
9 changed files with 28 additions and 1393 deletions

View File

@@ -18,8 +18,6 @@ USE_CN_GIT=false
USE_PISUGAR_WIFI_CONF=false
# 检查是否安装pisugar-power-manager
USE_PISUGAR_POWER_MANAGER=false
# 检查是否安装webui
#INSTALL_WEBUI=false
# 解析命令行参数
while [ "$#" -gt 0 ]; do
@@ -39,9 +37,6 @@ while [ "$#" -gt 0 ]; do
--pisugar-power-manager)
USE_PISUGAR_POWER_MANAGER=true
;;
# --webui)
# INSTALL_WEBUI=true
# ;;
--version)
if [ -z "$2" ]; then
echo "错误: --version 参数后需要跟版本号"
@@ -290,86 +285,6 @@ install_pisugar-wifi-conf() {
fi
}
# 如果指定了--webui参数则添加Nginx配置
install_webui() {
if [ "$INSTALL_WEBUI" = true ]; then
WEBUI_FILE="/root/2.13-Ink-screen-clock/webui"
NGINX_WEBUI_FILE="/var/www/html"
echo "正在安装并配置webui"
echo "正在安装软件包"
if ! sudo apt-get update && sudo apt-get -q -y install nginx php7.4-fpm; then
echo "软件包安装失败" >&2
exit 1
fi
echo "正在复制webui文件"
if ! sudo cp -r "$WEBUI_FILE" "$NGINX_WEBUI_FILE"; then
echo "webui文件复制失败" >&2
exit 1
fi
echo "正在修改nginx配置文件"
# 定义Nginx主配置文件的路径
NGINX_CONFIG_PATH="/etc/nginx/nginx.conf"
NGINX_CONFIG_BAK="$NGINX_CONFIG_PATH.bak"
# 备份现有的Nginx配置文件
cp "$NGINX_CONFIG_PATH" "$NGINX_CONFIG_BAK"
echo "已备份现有Nginx配置文件到 $NGINX_CONFIG_BAK"
# 定义文件路径变量
WEBROOT_PATH="$NGINX_WEBUI_FILE"
CGI_BIN_PATH="$WEBROOT_PATH/cgi-bin"
CGI_PASS="127.0.0.1:9000" # 根据您的CGI服务器配置
# 定义要添加的服务器配置
SERVER_CONFIG="
server {
listen 80;
server_name 0.0.0.0;
location / {
root $WEBROOT_PATH;
index index.html index.htm;
}
location /save.py {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据您的PHP版本进行调整
fastcgi_param SCRIPT_FILENAME \$document_root/save.py;
add_header X-Robots-Tag \"noindex,noarchive,nosnippet,nofollow\";
auth_basic \"Restricted Content\";
auth_basic_user_file /etc/nginx/.htpasswd; # 确保您有.htpasswd文件用于基本认证
}
}
"
# 检查是否已经存在类似的server配置
if ! grep -q 'server_name 0.0.0.0;' "$NGINX_CONFIG_PATH"; then
# 如果不存在将配置添加到http块中
awk -v config="$SERVER_CONFIG" '
/http {/ {
print
print config
next
}
1
' "$NGINX_CONFIG_PATH" > temp && mv temp "$NGINX_CONFIG_PATH"
else
echo "服务器配置已存在,未进行修改"
fi
# 测试Nginx配置
nginx -t
# 如果配置测试成功则重启Nginx
if [ $? -eq 0 ]; then
systemctl restart nginx
echo "Nginx配置已成功应用并重启"
else
echo "Nginx配置测试失败请检查配置文件"
fi
fi
}
# 主逻辑
# 检测是否是Debian系统
if [ -f /etc/debian_version ]; then

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()

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}

1213
webui/highlight.min.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,40 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ace-editor@1.4.12/css/ace.min.css">
<script src="https://cdn.jsdelivr.net/npm/ace-editor@1.4.12/js/ace.min.js"></script>
<meta charset="UTF-8">
<title>编辑 main.py</title>
<style>
#editor {
width: 100%;
height: 500px;
font-family: monospace;
font-size: 16px;
}
</style>
</head>
<body>
<h1>编辑 main.py</h1>
<form action="/save.py" method="post">
<div id="editor"><?php echo file_get_contents('/root/2.13-Ink-screen-clock/bin/main.py'); ?></div>
<input type="hidden" name="content" id="hidden-content">
<br>
<input type="submit" value="保存">
</form>
<script>
// 初始化 Ace Editor
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/python");
editor.setValue(<?php echo json_encode(file_get_contents($filePath)); ?>);
// 在表单提交前将编辑器内容赋值给隐藏的textarea
document.querySelector('form').addEventListener('submit', function() {
document.getElementById('hidden-content').value = editor.getValue();
});
</script>
</body>
</form>
</body>
</html>

View File

@@ -1,23 +0,0 @@
#!/usr/bin/env python3
import os
import sys
# 设置文件路径
file_path = '/root/2.13-Ink-screen-clock/bin/main.py'
# 读取POST数据
content_length = int(os.environ.get('CONTENT_LENGTH', 0))
content = sys.stdin.read(content_length)
# 保存文件
try:
with open(file_path, 'w') as file:
file.write(content)
response = "<h1>文件保存成功!</h1>"
except Exception as e:
response = "<h1>文件保存失败:{}</h1>".format(e)
# 返回响应
print("Content-Type: text/html")
print()
print(response)