7 Commits

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

View File

@@ -8,10 +8,10 @@
## 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
获取的天气是通过网页的接口,获取的内容保存在当前目录下的json文件接口的地址是在这里抓取的

View File

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

View File

@@ -12,7 +12,7 @@ import socket
white = 255 #颜色
black = 0
logging.basicConfig(level=logging.INFO)
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')
@@ -115,7 +115,7 @@ def Weather(): #在图片中添加天气内容
draw.text((211,107),weather_update,font = font05,fill =255) #显示天气更新时间
def Basic_refresh(): #全刷函数
logging.info("Refresh and prepare the basic content before starting the canvas")#开始画布前刷新准备基础内容
logging.info("在启动画布之前,刷新并准备基本内容")#开始画布前刷新准备基础内容
global get_date_var
get_date_var=get_date() #记录开始数据
draw.text((2,2),get_date_var,font = font02,fill =0)#将日期及星期几显示到屏幕
@@ -130,7 +130,7 @@ def Partial_full_brush(): #局部定时全刷函数
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")#局部内容更新,此更新建议与分钟同步,以节省墨水屏寿命
logging.info("部分内容更新,此更新建议与分钟同步,以节省墨水屏的使用寿命")#局部内容更新,此更新建议与分钟同步,以节省墨水屏寿命
epd.displayPartBaseImage(epd.getbuffer(info_image.rotate(180)))
epd.init()
while (True):
@@ -221,7 +221,7 @@ try:
#epd.Clear(0xFF) #清除屏幕内容
##################屏幕初始化#########################
logging.info("Width = %s, Height = %s", format(epd.width), format(epd.height)) #打印屏幕高度及宽度
logging.info("Initialize and clear the display")#屏幕开始准备相关展示
logging.info("初始化并清空显示屏")#屏幕开始准备相关展示
info_image = Image.new('1', (epd.height, epd.width), 255) #画布创建准备
draw = ImageDraw.Draw(info_image)
Basic_refresh() #全局刷新
@@ -232,7 +232,7 @@ try:
except IOError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("Keyboard interrupt detected, exiting gracefully.")
logging.info("检测到键盘中断,正在优雅地退出")
epd.init()
epd.Clear(0xFF) # 清除屏幕内容
epd.sleep() # 使屏幕进入休眠状态
@@ -240,7 +240,7 @@ except KeyboardInterrupt:
exit()
except Exception as e:
logging.error("An unexpected error occurred: %s", e)
logging.error("发生了意外的错误: %s", e)
epd.init()
epd.Clear(0xFF) # 清除屏幕内容
epd.sleep() # 使屏幕进入休眠状态

View File

@@ -9,7 +9,7 @@ import requests
white = 255 # 颜色
black = 0
logging.basicConfig(level=logging.INFO) # 设置日志级别
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')
@@ -35,15 +35,15 @@ def get_area_id(city_name):
for district, info in districts.items():
if info['NAMECN'] == city_name:
return info['AREAID']
logging.error("City name '%s' not found in city data", city_name)
logging.error("城市名称 '%s' 在城市数据中未找到,将使用默认城市信息", city_name)
else:
logging.error("Empty data received from city.js")
logging.error("从city.js接收到的数据为空")
except requests.RequestException as e:
logging.error("Network error when retrieving city data: %s", e)
logging.error("检索城市数据时发生网络错误: %s", e)
except json.JSONDecodeError as e:
logging.error("JSON decode error when parsing city data: %s", e)
logging.error("解析城市数据时发生JSON解码错误: %s", e)
return None
def get_current_city():
"""获取当前城市名称"""
url = "http://ip-api.com/json/?lang=zh-CN"
@@ -54,14 +54,14 @@ def get_current_city():
if data['status'] == 'success':
return data['city']
else:
logging.error("Failed to get current city: %s", data['message'])
logging.error("获取当前城市失败: %s", data['message'])
except requests.RequestException as e:
logging.error("Network error when retrieving current city: %s", e)
logging.error("检索当前城市时出现网络错误: %s", e)
except json.JSONDecodeError as e:
logging.error("JSON decode error when parsing current city data: %s", e)
logging.error("解析当前城市数据时出现JSON解码错误: %s", e)
return None
def getWeath(city='101060111'):
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/'
@@ -82,18 +82,18 @@ def getWeath(city='101060111'):
Timer(180, getWeath).start() # 定时器函数,间隔三分钟下载文件至本地
print("天气文件更新")
except requests.RequestException as e:
logging.error("Network error when retrieving weather data: %s", e)
logging.error("获取天气数据时出现网络错误: %s", e)
except Exception as e:
logging.error("An unexpected error occurred: %s", e)
logging.error("发生了意外错误: %s", e)
try:
getWeath() # 天气获取函数开始运行
except IOError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("Keyboard interrupt detected, exiting gracefully.")
logging.info("检测到键盘中断,正在优雅地退出")
except Exception as e:
logging.error("An unexpected error occurred: %s", e)
logging.error("发生了意外错误: %s", e)
exit()
# 脚本正常结束后的清理操作