mirror of
https://github.com/kxgx/2.13-Ink-screen-clock.git
synced 2026-05-06 00:05:51 +08:00
Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8059bac56 | ||
|
|
a80e3a2722 | ||
|
|
c60fccb210 | ||
|
|
53e1845ce4 | ||
|
|
3844f71943 | ||
|
|
b2336dcbfb | ||
|
|
5a976157c2 | ||
|
|
b6866ee2b9 | ||
|
|
32565ef2f5 | ||
|
|
0c4282ebc9 | ||
|
|
f8b2c1b332 | ||
|
|
5b5dace7d3 | ||
|
|
04ab97f5b6 | ||
|
|
0565fd6cf5 | ||
|
|
173d7eba78 | ||
|
|
28895e7188 | ||
|
|
8a4ba07f5b | ||
|
|
ecaa4006ce | ||
|
|
c5a3ef0dcf | ||
|
|
99c2bb3152 | ||
|
|
533e76d536 | ||
|
|
26ee5bf6e7 | ||
|
|
a710b293b6 | ||
|
|
3a90a36ffa | ||
|
|
fdd3e6008a | ||
|
|
e3fd070e3c | ||
|
|
5e353f68f6 | ||
|
|
6e0646612b | ||
|
|
d2b4073c98 | ||
|
|
9fb1ef0c6b | ||
|
|
7c39658cdf | ||
|
|
6628fc01e2 | ||
|
|
b505f9a61d | ||
|
|
7db25e5136 | ||
|
|
9e28156c65 | ||
|
|
1be7856992 | ||
|
|
368ed919dd | ||
|
|
7a9108134a | ||
|
|
1aa62fb894 | ||
|
|
d5ff700884 | ||
|
|
c56bd3784e | ||
|
|
597790d4ad | ||
|
|
e8011c7282 |
@@ -112,4 +112,5 @@ sudo apt-get update && sudo apt install -y git && sudo apt-get install -y python
|
|||||||
|
|
||||||
特别注意:
|
特别注意:
|
||||||
在代码文件第三十三行,此次代码需要更改,否则将展示默认城市天气数据
|
在代码文件第三十三行,此次代码需要更改,否则将展示默认城市天气数据
|
||||||

|
# 效果展示
|
||||||
|

|
||||||
|
|||||||
36
bin/clean.sh
36
bin/clean.sh
@@ -1,27 +1,27 @@
|
|||||||
#!/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"
|
||||||
hold_time_seconds=5 # 设置维持时间,例如300秒(5分钟)
|
hold_time_seconds=3 # 设置维持时间,例如300秒(5分钟)
|
||||||
|
|
||||||
# 创建一个新的screen会话并运行Python脚本
|
# 停止raspi_e-Paper服务
|
||||||
screen -dmS $screen_name /usr/bin/python3 -u $dir/$f_name > $logdir/log/clean-info.log 2>&1
|
echo "正在停止$service_name服务..."
|
||||||
|
sudo systemctl stop "$service_name"
|
||||||
|
|
||||||
|
# 确保日志目录存在
|
||||||
|
mkdir -p "${logdir}"
|
||||||
|
|
||||||
|
# 获取并终止所有与脚本相关的进程
|
||||||
|
pids=$(pgrep -f "$dir/$f_name")
|
||||||
|
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} 秒后停止服务..."
|
echo "正在运行脚本,将在 ${hold_time_seconds} 秒后停止服务..."
|
||||||
sleep $hold_time_seconds
|
sleep $hold_time_seconds
|
||||||
|
|
||||||
# 停止raspi_e-Paper服务
|
|
||||||
echo "正在停止$service_name服务..."
|
|
||||||
sudo systemctl stop $service_name
|
|
||||||
|
|
||||||
# 查找并结束所有与指定screen_name相关的screen会话
|
|
||||||
pids=$(screen -ls | grep $screen_name | awk -F '.' '{print $1}' | awk '{print $1}')
|
|
||||||
for pid in $pids; do
|
|
||||||
screen -S $pid -X quit
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "脚本运行完成,服务已停止,screen会话已结束。"
|
|
||||||
|
|||||||
@@ -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=5
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=shutdown.target
|
WantedBy=shutdown.target
|
||||||
|
|||||||
@@ -33,25 +33,57 @@ 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 被正确更新
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "无法更新 locale.gen 文件" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "语言环境 $DEFAULT_LANG 已在 locale.gen 中设置,跳过添加"
|
||||||
|
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
|
fi
|
||||||
|
|
||||||
# Debian版本相关命令
|
# Debian版本相关命令
|
||||||
@@ -147,7 +179,7 @@ install_packages() {
|
|||||||
echo "系统更新失败" >&2
|
echo "系统更新失败" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
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; then
|
||||||
echo "软件包安装失败" >&2
|
echo "软件包安装失败" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -210,7 +242,7 @@ setup_service() {
|
|||||||
# 主逻辑
|
# 主逻辑
|
||||||
# 检测是否是Debian系统
|
# 检测是否是Debian系统
|
||||||
if [ -f /etc/debian_version ]; then
|
if [ -f /etc/debian_version ]; then
|
||||||
echo "检测到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
|
||||||
|
|||||||
582
bin/main.py
582
bin/main.py
@@ -1,293 +1,289 @@
|
|||||||
#!/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 #颜色
|
white = 255 #颜色
|
||||||
black = 0
|
black = 0
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
################################引入配置文件开始################################################
|
################################引入配置文件开始################################################
|
||||||
picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
|
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')
|
libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
|
||||||
if os.path.exists(libdir):
|
if os.path.exists(libdir):
|
||||||
sys.path.append(libdir)#将引入文件添加到环境变量
|
sys.path.append(libdir)#将引入文件添加到环境变量
|
||||||
from waveshare_epd import epd2in13_V4 #引入墨水屏驱动文件
|
from waveshare_epd import epd2in13_V4 #引入墨水屏驱动文件
|
||||||
logging.debug("Loading Fonts")
|
logging.debug("Loading Fonts")
|
||||||
font01 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 20) #字体文件
|
font01 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 20) #字体文件
|
||||||
font02 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 15) #字体文件
|
font02 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 15) #字体文件
|
||||||
font03 = ImageFont.truetype(os.path.join(picdir, 'DSEG7Modern-Bold.ttf'), 38) #字体文件
|
font03 = ImageFont.truetype(os.path.join(picdir, 'DSEG7Modern-Bold.ttf'), 38) #字体文件
|
||||||
font04 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 10) #字体文件
|
font04 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 10) #字体文件
|
||||||
font05 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 12) #字体文件
|
font05 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 12) #字体文件
|
||||||
font06 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 13) #字体文件
|
font06 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 13) #字体文件
|
||||||
################################引入配置文件结束################################################
|
################################引入配置文件结束################################################
|
||||||
def Local_strong_brush(): #局部强制刷新显示
|
def Local_strong_brush(): #局部强制刷新显示
|
||||||
i = 0
|
i = 0
|
||||||
while i < 5:
|
while i < 5:
|
||||||
epd.displayPartial(epd.getbuffer(info_image.rotate(180)))#局刷开始
|
epd.displayPartial(epd.getbuffer(info_image.rotate(180)))#局刷开始
|
||||||
i = i + 1
|
i = i + 1
|
||||||
def getWeath(city='101060111'): #天气函数,下载json天气至本地
|
def getWeath(city='101060111'): #天气函数,下载json天气至本地
|
||||||
headers = {
|
headers = {
|
||||||
'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',
|
'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':'http://www.weather.com.cn/'
|
||||||
}
|
}
|
||||||
response = requests.get('http://d1.weather.com.cn/sk_2d/'+city+'.html',headers=headers)
|
response = requests.get('http://d1.weather.com.cn/sk_2d/'+city+'.html',headers=headers)
|
||||||
response.encoding = 'utf-8'
|
response.encoding = 'utf-8'
|
||||||
Weath=response.text[11:]
|
Weath=response.text[11:]
|
||||||
fileHandle=open('weather.json','w')
|
fileHandle=open('weather.json','w')
|
||||||
fileHandle.write(str(Weath))
|
fileHandle.write(str(Weath))
|
||||||
fileHandle.close()
|
fileHandle.close()
|
||||||
Timer(1800, getWeath).start() #定时器函数,间隔三分钟下载文件至本地
|
Timer(1800, getWeath).start() #定时器函数,间隔三分钟下载文件至本地
|
||||||
print("天气文件更新")
|
print("天气文件更新")
|
||||||
def gey_yiyan(): #一言API
|
def gey_yiyan(): #一言API
|
||||||
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 = 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'
|
response.encoding = 'utf-8'
|
||||||
yiyan=response.text
|
yiyan=response.text
|
||||||
return yiyan
|
return yiyan
|
||||||
def get_date():#返回当前年月日及星期几
|
def get_date():#返回当前年月日及星期几
|
||||||
date = datetime.datetime.now()
|
date = datetime.datetime.now()
|
||||||
today=LunarDate.today()
|
today=LunarDate.today()
|
||||||
week_day_dict = {0: '星期一',1: '星期二',2: '星期三',3: '星期四',4: '星期五',5: '星期六',6: '星期日',}
|
week_day_dict = {0: '星期一',1: '星期二',2: '星期三',3: '星期四',4: '星期五',5: '星期六',6: '星期日',}
|
||||||
day = date.weekday()
|
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():#返回当前时间,不到秒,大写
|
def get_time():#返回当前时间,不到秒,大写
|
||||||
return time.strftime('%H:%M')
|
return time.strftime('%H:%M')
|
||||||
def Get_address():#获取当前的IP地址
|
def Get_address():#获取当前的IP地址
|
||||||
return (subprocess.check_output(u"hostname -I | cut -d\' \' -f1 | head --bytes -1", shell = True ).decode('gbk'))
|
return (subprocess.check_output(u"hostname -I | cut -d\' \' -f1 | head --bytes -1", shell = True ).decode('gbk'))
|
||||||
def CPU_temperature():#CPU温度获取
|
def CPU_temperature():#CPU温度获取
|
||||||
temperatura = os.popen('vcgencmd measure_temp').readline()
|
temperatura = os.popen('vcgencmd measure_temp').readline()
|
||||||
temperatura = temperatura.replace('temp=','').strip()
|
temperatura = temperatura.replace('temp=','').strip()
|
||||||
return str(temperatura)
|
return str(temperatura)
|
||||||
def Memory_footprint():#显示内存占用百分比
|
def Memory_footprint():#显示内存占用百分比
|
||||||
return(subprocess.check_output(u"free -m | awk -F '[ :]+' 'NR==2{printf \"%d\", ($3)/$2*100}'", shell = True ).decode('gbk'))
|
return(subprocess.check_output(u"free -m | awk -F '[ :]+' 'NR==2{printf \"%d\", ($3)/$2*100}'", shell = True ).decode('gbk'))
|
||||||
def CPU_usage(): #显示CPU占用百分比
|
def CPU_usage(): #显示CPU占用百分比
|
||||||
return(str(int(float(os.popen("top -b -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip()))))
|
return(str(int(float(os.popen("top -b -n1 | awk '/Cpu\(s\):/ {print $2}'").readline().strip()))))
|
||||||
def power_battery():
|
def power_battery():
|
||||||
try:
|
try:
|
||||||
# 获取电池电量
|
# 获取电池电量
|
||||||
battery_percentage = subprocess.check_output(
|
battery_percentage = subprocess.check_output(
|
||||||
"echo \"get battery\" | nc -q 0 127.0.0.1 8423 | awk -F':' '{print $2}'",
|
"echo \"get battery\" | nc -q 0 127.0.0.1 8423 | awk -F':' '{print $2}'",
|
||||||
shell=True,
|
shell=True,
|
||||||
text=True
|
text=True
|
||||||
).strip()
|
).strip()
|
||||||
|
|
||||||
# 检查电量信息
|
# 检查电量信息
|
||||||
if not battery_percentage:
|
if not battery_percentage:
|
||||||
return "无效"
|
return "无效"
|
||||||
|
|
||||||
# 返回电量百分比
|
# 返回电量百分比
|
||||||
return f"{int(battery_percentage)}%"
|
return f"{int(battery_percentage)}%"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# 返回错误信息
|
# 返回错误信息
|
||||||
return "失败"
|
return "失败"
|
||||||
|
|
||||||
# 打印电量信息
|
# 打印电量信息
|
||||||
print(power_battery())
|
print(power_battery())
|
||||||
def Bottom_edge(): #在图片中添加底边内容
|
def Bottom_edge(): #在图片中添加底边内容
|
||||||
draw.rectangle((0, 105, 250, 122), 'black', 'black')
|
draw.rectangle((0, 105, 250, 122), 'black', 'black')
|
||||||
'''电池图标画图'''
|
'''电池图标画图'''
|
||||||
draw.line((126,109,154,109),fill=255, width=1) #电池顶边
|
draw.line((126,109,154,109),fill=255, width=1) #电池顶边
|
||||||
draw.line((126,110,126,119),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((127,119,154,119),fill=255, width=1) #电池下边
|
||||||
draw.line((154,110,154,118),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,112,157,112),fill=255, width=1)
|
||||||
draw.line((155,116,157,116),fill=255, width=1)
|
draw.line((155,116,157,116),fill=255, width=1)
|
||||||
draw.line((157,113,157,115),fill=255, width=1)
|
draw.line((157,113,157,115),fill=255, width=1)
|
||||||
global power_str
|
global power_str
|
||||||
power_str=power_battery()
|
power_str=power_battery()
|
||||||
draw.text((128,108),power_str,font = font04,fill =255) #显示当前电量百分比
|
draw.text((128,108),power_str,font = font04,fill =255) #显示当前电量百分比
|
||||||
'''电池图标画图'''
|
'''电池图标画图'''
|
||||||
'''添加一言API'''
|
'''添加一言API'''
|
||||||
global Time_keeping
|
global Time_keeping
|
||||||
Time_keeping =0
|
Time_keeping =0
|
||||||
draw.text((4,84),gey_yiyan(),font = font06,fill =0)
|
draw.text((4,84),gey_yiyan(),font = font06,fill =0)
|
||||||
'''添加一言API end'''
|
'''添加一言API end'''
|
||||||
draw.ellipse((192, 107, 207, 120), 0, 255)# 时钟图标
|
draw.ellipse((192, 107, 207, 120), 0, 255)# 时钟图标
|
||||||
draw.line((199,109,199,114),fill=255, width=1)
|
draw.line((199,109,199,114),fill=255, width=1)
|
||||||
draw.line((200,114,204,114),fill=255, width=1)
|
draw.line((200,114,204,114),fill=255, width=1)
|
||||||
global local_addr #获取当前IP地址
|
global local_addr #获取当前IP地址
|
||||||
local_addr= Get_address() #获取当前IP地址
|
local_addr= Get_address() #获取当前IP地址
|
||||||
draw.text((10,107),"IP:"+local_addr,font = font05,fill =255)#显示当前IP地址
|
draw.text((10,107),"IP:"+local_addr,font = font05,fill =255)#显示当前IP地址
|
||||||
def Weather(): #在图片中添加天气内容
|
def Weather(): #在图片中添加天气内容
|
||||||
Weather_json = open('weather.json','r')
|
Weather_json = open('weather.json','r')
|
||||||
Weather_data = Weather_json.read()
|
Weather_data = Weather_json.read()
|
||||||
Weather_json.close()
|
Weather_json.close()
|
||||||
Weather_text=json.loads(Weather_data)
|
Weather_text=json.loads(Weather_data)
|
||||||
global Weather_position
|
global Weather_position
|
||||||
global temperature
|
global temperature
|
||||||
global weather
|
global weather
|
||||||
global wind_direction
|
global wind_direction
|
||||||
global weather_update
|
global weather_update
|
||||||
global weather_date
|
global weather_date
|
||||||
global humidity
|
global humidity
|
||||||
Weather_position = Weather_text['cityname'] #定位位置
|
Weather_position = Weather_text['cityname'] #定位位置
|
||||||
temperature=Weather_text['temp']+u'°C' #温度
|
temperature=Weather_text['temp']+u'°C' #温度
|
||||||
weather = Weather_text['weather'] #天气情况
|
weather = Weather_text['weather'] #天气情况
|
||||||
wind_direction = Weather_text['WD'] #风向
|
wind_direction = Weather_text['WD'] #风向
|
||||||
weather_update = Weather_text['time'] #天气更新时间
|
weather_update = Weather_text['time'] #天气更新时间
|
||||||
weather_date = Weather_text['date'] #日期
|
weather_date = Weather_text['date'] #日期
|
||||||
humidity = Weather_text['SD'] #湿度
|
humidity = Weather_text['SD'] #湿度
|
||||||
draw.text((150,25),"天气:",font = font06,fill =0)#显示当前天气前缀
|
draw.text((150,25),"天气:",font = font06,fill =0)#显示当前天气前缀
|
||||||
draw.text((150,45),"温度:",font = font06,fill =0)#显示当前温度前缀
|
draw.text((150,45),"温度:",font = font06,fill =0)#显示当前温度前缀
|
||||||
draw.text((150,65),"湿度:",font = font06,fill =0)#显示当前湿度前缀
|
draw.text((150,65),"湿度:",font = font06,fill =0)#显示当前湿度前缀
|
||||||
draw.text((191,25),weather,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,45),temperature,font = font06,fill =0)
|
||||||
draw.text((191,65),humidity,font = font06,fill =0)
|
draw.text((191,65),humidity,font = font06,fill =0)
|
||||||
draw.text((211,107),weather_update,font = font05,fill =255) #显示天气更新时间
|
draw.text((211,107),weather_update,font = font05,fill =255) #显示天气更新时间
|
||||||
|
|
||||||
def Basic_refresh(): #全刷函数
|
def Basic_refresh(): #全刷函数
|
||||||
logging.info("Refresh and prepare the basic content before starting the canvas")#开始画布前刷新准备基础内容
|
logging.info("Refresh and prepare the basic content before starting the canvas")#开始画布前刷新准备基础内容
|
||||||
epd.init()
|
global get_date_var
|
||||||
epd.Clear(0xFF)
|
get_date_var=get_date() #记录开始数据
|
||||||
epd.init()
|
draw.text((2,2),get_date_var,font = font02,fill =0)#将日期及星期几显示到屏幕
|
||||||
epd.Clear(0xFF)
|
global local_time
|
||||||
global get_date_var
|
local_time=get_time()
|
||||||
get_date_var=get_date() #记录开始数据
|
draw.text((5,40),local_time,font = font03,fill =0)#显示当前时间
|
||||||
draw.text((2,2),get_date_var,font = font02,fill =0)#将日期及星期几显示到屏幕
|
Bottom_edge() #添加底边内容
|
||||||
global local_time
|
Weather() #天气内容
|
||||||
local_time=get_time()
|
epd.display(epd.getbuffer(info_image.rotate(180)))
|
||||||
draw.text((5,40),local_time,font = font03,fill =0)#显示当前时间
|
def Partial_full_brush(): #局部定时全刷函数
|
||||||
Bottom_edge() #添加底边内容
|
Basic_refresh() #全局刷新
|
||||||
Weather() #天气内容
|
logging.debug("局部定时全局刷新")
|
||||||
epd.display(epd.getbuffer(info_image.rotate(180)))
|
epd.init()
|
||||||
def Partial_full_brush(): #局部定时全刷函数
|
def Partial_refresh():#局刷函数
|
||||||
Basic_refresh() #全局刷新
|
logging.info("Partial content update, this update is recommended to be synchronized with the minute to save the life of the ink screen")#局部内容更新,此更新建议与分钟同步,以节省墨水屏寿命
|
||||||
logging.debug("局部定时全局刷新")
|
epd.displayPartBaseImage(epd.getbuffer(info_image.rotate(180)))
|
||||||
epd.init()
|
epd.init()
|
||||||
def Partial_refresh():#局刷函数
|
while (True):
|
||||||
logging.info("Partial content update, this update is recommended to be synchronized with the minute to save the life of the ink screen")#局部内容更新,此更新建议与分钟同步,以节省墨水屏寿命
|
global local_time
|
||||||
epd.displayPartBaseImage(epd.getbuffer(info_image.rotate(180)))
|
local_time1=get_time()
|
||||||
epd.init()
|
if (local_time1==local_time) ==False:
|
||||||
while (True):
|
draw.rectangle((5, 40, 133, 82), fill = 255) #时间局刷区域
|
||||||
global local_time
|
draw.text((5,40),local_time1,font = font03,fill =0)#刷新当前时间
|
||||||
local_time1=get_time()
|
local_time=local_time1
|
||||||
if (local_time1==local_time) ==False:
|
Local_strong_brush() #局部强刷
|
||||||
draw.rectangle((5, 40, 133, 82), fill = 255) #时间局刷区域
|
get_date_var1=get_date() #局刷判断,如果时间与前一次不一致说明内容变化,需要刷新显示
|
||||||
draw.text((5,40),local_time1,font = font03,fill =0)#刷新当前时间
|
global get_date_var #再次声明这个是全局变量
|
||||||
local_time=local_time1
|
if(get_date_var1==get_date_var) ==False:
|
||||||
Local_strong_brush() #局部强刷
|
draw.rectangle((2, 2, 250, 16), fill = 255) #设置头部刷新区域
|
||||||
get_date_var1=get_date() #局刷判断,如果时间与前一次不一致说明内容变化,需要刷新显示
|
draw.text((2,2),get_date_var1,font = font02,fill =0)#将日期及星期几刷新显示到屏幕
|
||||||
global get_date_var #再次声明这个是全局变量
|
get_date_var=get_date_var1 #将更新的值保存到初始变量,直到下一次变化时执行该刷新操作
|
||||||
if(get_date_var1==get_date_var) ==False:
|
logging.debug("头部日期部位发生刷新变化.")
|
||||||
draw.rectangle((2, 2, 250, 16), fill = 255) #设置头部刷新区域
|
Local_strong_brush() #局部强刷
|
||||||
draw.text((2,2),get_date_var1,font = font02,fill =0)#将日期及星期几刷新显示到屏幕
|
global local_addr #当前IP地址
|
||||||
get_date_var=get_date_var1 #将更新的值保存到初始变量,直到下一次变化时执行该刷新操作
|
local_addr1 = Get_address()
|
||||||
logging.debug("头部日期部位发生刷新变化.")
|
if (local_addr1==local_addr) ==False:
|
||||||
Local_strong_brush() #局部强刷
|
draw.rectangle((1, 107, 94, 120), fill = 0) #设置头部刷新区域
|
||||||
global local_addr #当前IP地址
|
draw.text((10,107),"IP:"+local_addr1,font = font05,fill =255)#显示当前IP地址
|
||||||
local_addr1 = Get_address()
|
local_addr=local_addr1
|
||||||
if (local_addr1==local_addr) ==False:
|
Local_strong_brush() #局部强刷
|
||||||
draw.rectangle((1, 107, 94, 120), fill = 0) #设置头部刷新区域
|
'''天气局部更新函数'''
|
||||||
draw.text((10,107),"IP:"+local_addr1,font = font05,fill =255)#显示当前IP地址
|
Weather_json = open('weather.json','r')
|
||||||
local_addr=local_addr1
|
Weather_data = Weather_json.read()
|
||||||
Local_strong_brush() #局部强刷
|
Weather_json.close()
|
||||||
'''天气局部更新函数'''
|
Weather_text=json.loads(Weather_data)
|
||||||
Weather_json = open('weather.json','r')
|
global Weather_position
|
||||||
Weather_data = Weather_json.read()
|
global temperature
|
||||||
Weather_json.close()
|
global weather
|
||||||
Weather_text=json.loads(Weather_data)
|
global wind_direction
|
||||||
global Weather_position
|
global weather_update
|
||||||
global temperature
|
global weather_date
|
||||||
global weather
|
global humidity
|
||||||
global wind_direction
|
Weather_position1 = Weather_text['cityname'] #定位位置
|
||||||
global weather_update
|
temperature1=Weather_text['temp']+u'°C' #温度
|
||||||
global weather_date
|
weather11 = Weather_text['weather'] #天气情况
|
||||||
global humidity
|
wind_direction1 = Weather_text['WD'] #风向
|
||||||
Weather_position1 = Weather_text['cityname'] #定位位置
|
weather_update1 = Weather_text['time'] #天气更新时间
|
||||||
temperature1=Weather_text['temp']+u'°C' #温度
|
weather_date1 = Weather_text['date'] #日期
|
||||||
weather11 = Weather_text['weather'] #天气情况
|
humidity1 = Weather_text['SD'] #湿度
|
||||||
wind_direction1 = Weather_text['WD'] #风向
|
if (weather11==weather) ==False:
|
||||||
weather_update1 = Weather_text['time'] #天气更新时间
|
draw.rectangle((191, 25, 249, 38), fill = 255) #天气局刷区域
|
||||||
weather_date1 = Weather_text['date'] #日期
|
draw.text((191,25),weather11,font = font06,fill =0)
|
||||||
humidity1 = Weather_text['SD'] #湿度
|
weather=weather11
|
||||||
if (weather11==weather) ==False:
|
logging.info("天气局部刷新")
|
||||||
draw.rectangle((191, 25, 249, 38), fill = 255) #天气局刷区域
|
Local_strong_brush() #局部强刷
|
||||||
draw.text((191,25),weather11,font = font06,fill =0)
|
if (temperature1==temperature) ==False:
|
||||||
weather=weather11
|
draw.rectangle((191, 45, 249, 57), fill = 255) #局刷区域
|
||||||
logging.info("天气局部刷新")
|
draw.text((191,45),temperature1,font = font06,fill =0)
|
||||||
Local_strong_brush() #局部强刷
|
temperature=temperature1
|
||||||
if (temperature1==temperature) ==False:
|
logging.info("温度局部刷新")
|
||||||
draw.rectangle((191, 45, 249, 57), fill = 255) #局刷区域
|
Local_strong_brush() #局部强刷
|
||||||
draw.text((191,45),temperature1,font = font06,fill =0)
|
if (humidity1==humidity) ==False:
|
||||||
temperature=temperature1
|
draw.rectangle((191, 65, 249, 77), fill = 255) #局刷区域
|
||||||
logging.info("温度局部刷新")
|
draw.text((191,65),humidity1,font = font06,fill =0)
|
||||||
Local_strong_brush() #局部强刷
|
humidity = humidity1
|
||||||
if (humidity1==humidity) ==False:
|
logging.info("湿度局部刷新")
|
||||||
draw.rectangle((191, 65, 249, 77), fill = 255) #局刷区域
|
Local_strong_brush() #局部强刷
|
||||||
draw.text((191,65),humidity1,font = font06,fill =0)
|
if (weather_update1==weather_update) ==False:
|
||||||
humidity = humidity1
|
draw.rectangle((211, 107, 248, 118), fill = 0) #设置更新时间刷新区域
|
||||||
logging.info("湿度局部刷新")
|
draw.text((211,107),weather_update1,font = font05,fill =255) #显示天气更新时间
|
||||||
Local_strong_brush() #局部强刷
|
weather_update=weather_update1
|
||||||
if (weather_update1==weather_update) ==False:
|
logging.info("天气更新时间局部刷新")
|
||||||
draw.rectangle((211, 107, 248, 118), fill = 0) #设置更新时间刷新区域
|
Local_strong_brush() #局部强刷
|
||||||
draw.text((211,107),weather_update1,font = font05,fill =255) #显示天气更新时间
|
'''天气局部更新函数'''
|
||||||
weather_update=weather_update1
|
global power_str
|
||||||
logging.info("天气更新时间局部刷新")
|
power_str1 =power_battery()
|
||||||
Local_strong_brush() #局部强刷
|
if (power_str1==power_str) ==False:
|
||||||
'''天气局部更新函数'''
|
draw.rectangle((128, 110, 153, 117), fill = 0) #设置更新时间刷新区域
|
||||||
global power_str
|
draw.text((127,108),power_battery(),font = font04,fill =255) #显示当前电量百分比
|
||||||
power_str1 =power_battery()
|
power_str=power_str1
|
||||||
if (power_str1==power_str) ==False:
|
Local_strong_brush() #局部强刷
|
||||||
draw.rectangle((128, 110, 153, 117), fill = 0) #设置更新时间刷新区域
|
logging.info("电源电量局部刷新")
|
||||||
draw.text((127,108),power_battery(),font = font04,fill =255) #显示当前电量百分比
|
'''一言API显示'''
|
||||||
power_str=power_str1
|
global Time_keeping
|
||||||
Local_strong_brush() #局部强刷
|
Time_keeping+=1
|
||||||
logging.info("电源电量局部刷新")
|
if Time_keeping == 300 : #一言API局刷,当变量Time_keeping数据为10即开始执行
|
||||||
'''一言API显示'''
|
draw.rectangle((1, 82, 248, 101), fill = 255)
|
||||||
global Time_keeping
|
draw.text((4,84),gey_yiyan(),font = font06,fill =0)
|
||||||
Time_keeping+=1
|
Time_keeping=0
|
||||||
if Time_keeping == 300 : #一言API局刷,当变量Time_keeping数据为10即开始执行
|
Local_strong_brush() #局部强刷
|
||||||
draw.rectangle((1, 82, 248, 101), fill = 255)
|
logging.info("一言API局部刷新")
|
||||||
draw.text((4,84),gey_yiyan(),font = font06,fill =0)
|
'''一言API显示'''
|
||||||
Time_keeping=0
|
#epd.displayPartial(epd.getbuffer(info_image.rotate(180)))#局刷开始
|
||||||
Local_strong_brush() #局部强刷
|
time.sleep(2)
|
||||||
logging.info("一言API局部刷新")
|
#if time.strftime('%H%M%S')=='000000': #如果时间是晚上00点,执行全局刷新
|
||||||
'''一言API显示'''
|
#Partial_full_brush() #每天全局刷新一次
|
||||||
#epd.displayPartial(epd.getbuffer(info_image.rotate(180)))#局刷开始
|
try:
|
||||||
time.sleep(2)
|
##################屏幕初始化#########################
|
||||||
#if time.strftime('%H%M%S')=='000000': #如果时间是晚上00点,执行全局刷新
|
getWeath()#天气获取函数开始运行
|
||||||
#Partial_full_brush() #每天全局刷新一次
|
epd = epd2in13_V4.EPD() #初始化
|
||||||
try:
|
epd.init()#设定屏幕刷新模式
|
||||||
##################屏幕初始化#########################
|
epd.Clear(0xFF) #清除屏幕内容
|
||||||
getWeath()#天气获取函数开始运行
|
##################屏幕初始化#########################
|
||||||
epd = epd2in13_V4.EPD() #初始化
|
logging.info("Width = %s, Height = %s", format(epd.width), format(epd.height)) #打印屏幕高度及宽度
|
||||||
epd.init()#设定屏幕刷新模式
|
logging.info("Initialize and clear the display")#屏幕开始准备相关展示
|
||||||
epd.Clear(0xFF) #清除屏幕内容
|
info_image = Image.new('1', (epd.height, epd.width), 255) #画布创建准备
|
||||||
##################屏幕初始化#########################
|
draw = ImageDraw.Draw(info_image)
|
||||||
logging.info("Width = %s, Height = %s", format(epd.width), format(epd.height)) #打印屏幕高度及宽度
|
Basic_refresh() #全局刷新
|
||||||
logging.info("Initialize and clear the display")#屏幕开始准备相关展示
|
Partial_refresh() #局部刷新
|
||||||
info_image = Image.new('1', (epd.height, epd.width), 255) #画布创建准备
|
epd.init()
|
||||||
draw = ImageDraw.Draw(info_image)
|
#epd.Clear(0xFF)
|
||||||
Basic_refresh() #全局刷新
|
epd.sleep()
|
||||||
Partial_refresh() #局部刷新
|
except IOError as e:
|
||||||
epd.init()
|
logging.info(e)
|
||||||
#epd.Clear(0xFF)
|
except KeyboardInterrupt:
|
||||||
epd.sleep()
|
logging.info("Keyboard interrupt detected, exiting gracefully.")
|
||||||
except IOError as e:
|
epd.init()
|
||||||
logging.info(e)
|
epd.Clear(0xFF) # 清除屏幕内容
|
||||||
except KeyboardInterrupt:
|
epd.sleep() # 使屏幕进入休眠状态
|
||||||
logging.info("Keyboard interrupt detected, exiting gracefully.")
|
epd2in13_V4.epdconfig.module_exit() # 清理资源
|
||||||
epd.init()
|
exit()
|
||||||
epd.Clear(0xFF) # 清除屏幕内容
|
|
||||||
epd.sleep() # 使屏幕进入休眠状态
|
except Exception as e:
|
||||||
epd2in13_V4.epdconfig.module_exit() # 清理资源
|
logging.error("An unexpected error occurred: %s", e)
|
||||||
exit()
|
epd.init()
|
||||||
|
epd.Clear(0xFF) # 清除屏幕内容
|
||||||
except Exception as e:
|
epd.sleep() # 使屏幕进入休眠状态
|
||||||
logging.error("An unexpected error occurred: %s", e)
|
epd2in13_V4.epdconfig.module_exit() # 清理资源
|
||||||
epd.init()
|
exit()
|
||||||
epd.Clear(0xFF) # 清除屏幕内容
|
|
||||||
epd.sleep() # 使屏幕进入休眠状态
|
# 脚本正常结束后的清理操作
|
||||||
epd2in13_V4.epdconfig.module_exit() # 清理资源
|
epd.init()
|
||||||
exit()
|
epd.Clear(0xFF) # 清除屏幕内容
|
||||||
|
epd.sleep() # 使屏幕进入休眠状态
|
||||||
# 脚本正常结束后的清理操作
|
epd2in13_V4.epdconfig.module_exit() # 清理资源
|
||||||
epd.init()
|
exit()
|
||||||
epd.Clear(0xFF) # 清除屏幕内容
|
|
||||||
epd.sleep() # 使屏幕进入休眠状态
|
|
||||||
epd2in13_V4.epdconfig.module_exit() # 清理资源
|
|
||||||
exit()
|
|
||||||
|
|||||||
15
bin/start.sh
15
bin/start.sh
@@ -1,15 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
f_name=main.py
|
f_name=main.py
|
||||||
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||||
logdir=${dir%/*}
|
logdir=${dir%/*}
|
||||||
screen_name="main_screen"
|
pid=`ps -ef |grep $dir/$f_name | grep -v grep |awk '{print $2}'`
|
||||||
|
for id in $pid
|
||||||
# 查找并结束所有与指定screen_name相关的screen会话
|
do
|
||||||
pids=$(screen -ls | grep $screen_name | awk -F '.' '{print $1}' | awk '{print $1}')
|
kill -9 $id
|
||||||
for pid in $pids; do
|
|
||||||
screen -S $pid -X quit
|
|
||||||
done
|
done
|
||||||
|
nohup /usr/bin/python3 -u $dir/$f_name > $logdir/log/info.log 2>&1 &
|
||||||
# 创建一个新的screen会话并运行Python脚本
|
|
||||||
screen -dmS $screen_name /usr/bin/python3 -u $dir/$f_name > $logdir/log/info.log 2>&1
|
|
||||||
|
|||||||
BIN
pic/1736672578025.jpg
Normal file
BIN
pic/1736672578025.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.0 MiB |
Reference in New Issue
Block a user