python实现动态壁纸_Python 实现macOS Catalina 动态壁纸定时设置
前言
很不幸,我的电脑只能装 macOS High Sierra ,但是看他们的 Catalina 和 Mojave 的壁纸好炫酷,据说还可以根据日出时间切换壁纸和暗黑模式?!尽管条件限制,我还是想体验一下动态壁纸。(想试试的戳这里,Github有相同的说明)本人刚学Python 2秒,大佬轻喷,Github也没啥项目
Windows 也能用啦:戳这里
Here we go
实现方法
计算日出时间
需要一点天文学知识,具体请看代码(文末有,百度来的)
定时任务
为了保持轻量化原则,使用自带的 sched
开机自启动
macOS 很贴心的加入了启动项功能,不用鼓捣命令行
设置壁纸
这里不太好弄,windows 下的方法不少,mac 上可以使用 appscript 模块(是在是没有办法轻量化了) from appscript import app, mactypes
def set_bg(path): #注意这里的 path 是相对于项目路径的
app('Finder').desktop_picture.set(mactypes.File(path)) # Windows version
import win32con, win32api, win32gui
import os
def set_bg(path):
path2 = ''
for c in path: #为了兼容上面的代码,采取相对路径path,再转换为绝对路径path2
if c=='/':
path2+='\\'
else:
path2+=c
# get file path
pic = os.getcwd()+'\\'+path2
# open register
regKey = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\\Desktop",0,win32con.KEY_SET_VALUE)
win32api.RegSetValueEx(regKey,"WallpaperStyle", 0, win32con.REG_SZ, "0")
win32api.RegSetValueEx(regKey, "TileWallpaper", 0, win32con.REG_SZ, "0")
# refresh screen
win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, pic, win32con.SPIF_SENDWININICHANGE)
安装方法
Github 仓库地址(mac OS)
Github 仓库地址(Windows)
安装说明 (mac)
保证拥有 Python3 运行环境
在终端执行(当然你也可以pip3 install appscript && python3 Main.py)
git clone https://github.com/HelloWorldZTR/py-background.git
cd py-background && sudo chmod +x install.sh start.sh
./install.sh
会要求输入经纬度用以计算日出日落时间(float 最好)
Ctrl + C 退出终端
将 start.sh 添加到开机启动项(方法在此)
配置说明
config.json
{
"SunSet": {
"-01:00": "BackgroundImage/evening.jpeg",
"+00:00": "BackgroundImage/night.jpg"
},
"SunRise": {
"-01:00": "BackgroundImage/evening.jpeg",
"+00:00": "BackgroundImage/day.jpg"
}
}
SunSet / SunRise 是日落日出; -01:00 是之前一小时,+01:00 是之后一小时
所以,
"SunSet": {
"-01:00": "BackgroundImage/evening.jpeg"
}
指的是在日落前1小时,将壁纸换成BackgroundImage/evening.jpeg(相对于项目路径)
config.json 同时也存储 longitude 和 latitude
后话
看完这篇文章,要不再看看这篇关于黑苹果的文章?
Github地址:
https://github.com/HelloWorldZTR/py-background
https://github.com/HelloWorldZTR/py-background-for-win
正在上传…重新上传取消
还会有windows 版的
计算日出日落时间的代码
import math
def getsunrise(year, month, day, latitude, longitude):
zenith = 90.83333333
N1 = math.floor(275 * month / 9)
N2 = math.floor((month + 9) / 12)
N3 = (1 + math.floor((year - 4 * math.floor(year / 4) + 2) / 3))
dayOfYear = N1 - (N2 * N3) + day - 30
localOffset = math.floor(-1 * longitude * 24/360)
lngHour = longitude / 15
t = dayOfYear + ((6 - lngHour) / 24)
M = (0.9856 * t) - 3.289
L = M + (1.916 * math.sin(M * 3.1415926 / 180)) + \
(0.020 * math.sin(2 * M * 3.1415926 / 180)) + 282.634
L = L - 360
RA = (180/3.1415926) * math.atan(0.91764 * math.tan(L * 3.1415926 / 180))
Lquadrant = (math.floor(L/90)) * 90
RAquadrant = (math.floor(RA/90)) * 90
RA = RA + (Lquadrant - RAquadrant)
RA = RA / 15
sinDec = 0.39782 * math.sin(L * 3.1415926 / 180)
cosDec = math.cos(math.asin(sinDec))
cosH = (math.cos(zenith * 3.1415926 / 180) - (sinDec * math.sin(latitude *
3.1415926 / 180))) / (cosDec * math.cos(latitude * 3.1415926 / 180))
if (cosH < -1):
sunsetT = 0
return sunsetT
if (cosH > 1):
sunriseT = 0
return sunriseT
H = 360 - 180/3.1415926 * math.acos(cosH)
H = H / 15
T = H + RA - (0.06571 * t) - 6.622
UT = T - lngHour
sunriseT = UT - localOffset
return sunriseT
def getsunset(year, month, day, latitude, longitude):
zenith = 90.83333333
N1 = math.floor(275 * month / 9)
N2 = math.floor((month + 9) / 12)
N3 = (1 + math.floor((year - 4 * math.floor(year / 4) + 2) / 3))
dayOfYear = N1 - (N2 * N3) + day - 30
localOffset = math.floor(-1 * longitude * 24/360)
lngHour = longitude / 15
t = dayOfYear + ((6 - lngHour) / 24)
M = (0.9856 * t) - 3.289
L = M + (1.916 * math.sin(M * 3.1415926 / 180)) + \
(0.020 * math.sin(2 * M * 3.1415926 / 180)) + 282.634
L = L - 360
RA = (180/3.1415926) * math.atan(0.91764 * math.tan(L * 3.1415926 / 180))
Lquadrant = (math.floor(L/90)) * 90
RAquadrant = (math.floor(RA/90)) * 90
RA = RA + (Lquadrant - RAquadrant)
RA = RA / 15
sinDec = 0.39782 * math.sin(L * 3.1415926 / 180)
cosDec = math.cos(math.asin(sinDec))
cosH = (math.cos(zenith * 3.1415926 / 180) - (sinDec * math.sin(latitude *
3.1415926 / 180))) / (cosDec * math.cos(latitude * 3.1415926 / 180))
if (cosH < -1):
sunsetT = 0
return sunsetT
if (cosH > 1):
sunriseT = 0
return sunriseT
H = 180/3.1415926 * math.acos(cosH)
H = H / 15
T = H + RA - (0.06571 * t) - 6.622
UT = T - lngHour
sunsetT = UT - localOffset
return sunsetT
def format_time(timeT):
if timeT > 0:
h = int(timeT)
m = int((timeT-int(timeT))*60)
else:
h = 24+int(timeT)-1
m = int(math.fabs(timeT-int(timeT))*60)
return {'hour': h, 'minute': m}
python实现动态壁纸_Python 实现macOS Catalina 动态壁纸定时设置相关推荐
- Python 实现macOS Catalina 动态壁纸定时设置
前言 很不幸,我的电脑只能装 macOS High Sierra ,但是看他们的 Catalina 和 Mojave 的壁纸好炫酷,据说还可以根据日出时间切换壁纸和暗黑模式?!尽管条件限制,我还是想体 ...
- 用python画动图_Python使用matplotlib画动态图
机器学习需要使用python实现相应的算法,因此学习了Matplotlib中的画图. 当然为了能显示机器学习中每次迭代的效果与收敛速度,需要画出动态图形. 下面给出两个例子,分别可以画出动态条形图和动 ...
- python爬取js动态网页_Python 从零开始爬虫(八)——动态爬取解决方案 之 selenium
selenium--自动化测试工具,专门为Web应用程序编写的一个验收测试工具,测试其兼容性,功能什么的.然而让虫师们垂涎的并不是以上的种种,而是其通过驱动浏览器获得的解析JavaScript的能力. ...
- python如何画动态海浪_python使用matplotlib画动态图
matplotlib是python的核心绘图库,是python的一个开源项目,旨在为python提供一个绘图库. matplotlib matplotlib与numpy组合是一种可行的matlab替代 ...
- python 生成动态库_Python 项目转.so动态库
最近, 作者遇到一个需求, 需要把Python的工程部署到别的集群, 但是又要保证Python代码的安全性. 于是上网搜索, 搜到几个解决方案, 但是都不是符合需求. 综合搜到的几个解决方案, 最终作 ...
- python log日志级别_python – 日志记录:如何为处理程序设置最大日志级别
您可以向文件处理程序添加过滤器.这样,您可以将特定级别重定向到不同的文件. import logging class LevelFilter(logging.Filter): def __init__ ...
- python图像加坐标_Python使用matplotlib模块绘制图像并设置标题与坐标轴等信息示例...
本文实例讲述了Python使用matplotlib模块绘制图像并设置标题与坐标轴等信息.分享给大家供大家参考,具体如下: 进行图像绘制有时候需要设定坐标轴以及图像标题等信息,示例代码如下: #-*- ...
- python画图marker显示_python画图(标记、marker、设置标记大小、marker符号大全)(图文详细入门教程五)...
初衷 本人由于平常写论文需要输出一些结果图,但是苦于在网上搜python画图时,详细的教程非常多,但是就是找不到能马上解决自己问题那一行代码,所以打算写一些适合需求简单的朋友应急用的教程,应急就必须方 ...
- python opencv 摄像头亮度_Python 下opencv 应用: 摄像头参数设置
为了取得好的图片效果,我们需要设置摄像头的参数. 假如摄像流为 cap, 那么设置参数是cap.set(参数编号,参数) 获取参数值的函数是 cap.get(参数编号) 看一段摄像头参数设置读取的例 ...
- python怎么打印图片_Python+OpenCV图像处理——打印图片属性、设置存储路径、调用摄像头...
一. 打印图片属性.设置图片存储路径 代码如下: #打印图片的属性.保存图片位置 import cv2 as cv import numpy as np #numpy是一个开源的python科学计算库 ...
最新文章
- docker 报错 /usr/bin/docker-current: Error response from daemon: driver failed programming external
- 从CVPR 2014看计算机视觉领域的最新热点
- Python——web.py模块错误【UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xab in position 285】解决方案
- 如何优雅地处理 EF Core 异常
- html5自动把某个层放在屏幕底部,告诉你一个将 footer 保持在底部的最好方法
- 区间dp——cf1025D二叉搜索树的中序遍历好题!
- 微软MVC对架构的一点思考
- Leetcode每日一题:100.same-tree(相同的树)
- 6Y叔的clusterProfiler-book阅读 Chapter 6 KEGG analysis
- python logisticregression_Python机器学习sklearn LogisticRegression用户流失预测模型初探
- 制作淘宝客微信公众号(一)
- 一文了解关于 CryptoPunks 的10个冷知识
- 经典 tcp粘包分析
- 算法导论第一,第二部分总结
- 【Java】奇偶数判断
- 编程之美之数独求解器的C++实现方法
- 登录和第三方授权(Cookie和Authorization)
- 百问网七天物联网课程学习笔记——单片机时钟
- 【SemiDrive源码分析】【MailBox核间通信】43 - 基于Mailbox IPCC RPC 实现核间通信(代码实现篇)
- UE4 获取目录下所有的图片转换成Texture2D并通过UMG显示出来