From 46206b9fe4ffe3ac92fecb199cd96f06ddb094fc Mon Sep 17 00:00:00 2001 From: ambition_echo Date: Tue, 9 Aug 2022 17:30:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(scripts/src):=20=E4=BF=AE=E6=94=B9=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E5=A3=81=E7=BA=B8=E4=BF=9D=E5=AD=98=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=E6=AD=A2=E9=87=8D=E5=90=AF=E5=90=8E=E5=A3=81?= =?UTF-8?q?=E7=BA=B8=E6=B6=88=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Author: ambition-echo --- scripts/24hourWallpaper.py | 6 +++++- scripts/Bing-rand.py | 11 ++++++++--- scripts/Bing-tody.py | 11 ++++++++--- scripts/FY-4.py | 9 ++++++++- scripts/Himawari-8.py | 9 ++++++++- scripts/checkWakkpaperDir.py | 7 ------- scripts/wifu.py | 12 +++++++++--- src/trayicon.cpp | 5 +++-- 8 files changed, 49 insertions(+), 21 deletions(-) delete mode 100644 scripts/checkWakkpaperDir.py diff --git a/scripts/24hourWallpaper.py b/scripts/24hourWallpaper.py index 6a4890e..2917759 100644 --- a/scripts/24hourWallpaper.py +++ b/scripts/24hourWallpaper.py @@ -9,10 +9,14 @@ import requests file = sys.argv[5] -unpackDir = "/tmp/" + file.split("/")[-1].split(".")[0] +home = os.getenv("HOME") +cache = home + "/.cache/earth-wallpaper/" +unpackDir = cache + file.split("/")[-1].split(".")[0] def check(): + if not os.path.exists(cache): + os.makedirs(cache) if not os.path.exists(unpackDir): unpack() diff --git a/scripts/Bing-rand.py b/scripts/Bing-rand.py index 87dd2d0..fcb7226 100644 --- a/scripts/Bing-rand.py +++ b/scripts/Bing-rand.py @@ -1,9 +1,10 @@ # source: 必应壁纸(随机) # updateTime from setWallpaper import set_wallpaper -from checkWakkpaperDir import check import requests import datetime +import os +import shutil api_url = "https://bing.ioliu.cn/v1/rand" @@ -20,9 +21,13 @@ def download(path): def main(): - check() today = datetime.datetime.utcnow() - name = "/tmp/earth-wallpaper/" + today.strftime("%Y%m%d%H%M%s") + ".png" + home = os.getenv("HOME") + wallpaper_dir = home + '/.cache/earth-wallpaper/wallpaper/' + if os.path.exists(wallpaper_dir): + shutil.rmtree(wallpaper_dir) + os.makedirs(wallpaper_dir) + name = wallpaper_dir + today.strftime("%Y%m%d%H%M%s") + ".png" download(name) set_wallpaper(name) diff --git a/scripts/Bing-tody.py b/scripts/Bing-tody.py index 131048e..779b526 100644 --- a/scripts/Bing-tody.py +++ b/scripts/Bing-tody.py @@ -1,9 +1,10 @@ # source: 必应壁纸(今日) # updateTime from setWallpaper import set_wallpaper -from checkWakkpaperDir import check import requests import datetime +import os +import shutil api_url = "https://bing.ioliu.cn/v1" @@ -20,9 +21,13 @@ def download(path): def main(): - check() today = datetime.datetime.utcnow() - name = "/tmp/earth-wallpaper/" + today.strftime("%Y%m%d%H%M%s") + ".png" + home = os.getenv("HOME") + wallpaper_dir = home + '/.cache/earth-wallpaper/wallpaper/' + if os.path.exists(wallpaper_dir): + shutil.rmtree(wallpaper_dir) + os.makedirs(wallpaper_dir) + name = wallpaper_dir + today.strftime("%Y%m%d%H%M%s") + ".png" download(name) set_wallpaper(name) diff --git a/scripts/FY-4.py b/scripts/FY-4.py index afe5515..9a69c22 100644 --- a/scripts/FY-4.py +++ b/scripts/FY-4.py @@ -6,13 +6,20 @@ import requests import datetime import sys +import os +import shutil # 屏幕分辨率 Y = int(sys.argv[1]) X = int(sys.argv[2]) SIZE = int(sys.argv[3]) -path = '/tmp/earth-wallpaper/' +home = os.getenv("HOME") +wallpaper_dir = home + '/.cache/earth-wallpaper/wallpaper/' +if os.path.exists(wallpaper_dir): + shutil.rmtree(wallpaper_dir) +os.makedirs(wallpaper_dir) +path = wallpaper_dir name = '1.png' diff --git a/scripts/Himawari-8.py b/scripts/Himawari-8.py index 0f5eab8..ee9ad10 100644 --- a/scripts/Himawari-8.py +++ b/scripts/Himawari-8.py @@ -7,6 +7,8 @@ import requests import datetime import sys +import os +import shutil # 屏幕分辨率 Y = int(sys.argv[1]) @@ -14,7 +16,12 @@ SIZE = int(sys.argv[3]) # 存储路径 -path = '/tmp/earth-wallpaper/' +home = os.getenv("HOME") +wallpaper_dir = home + '/.cache/earth-wallpaper/wallpaper/' +if os.path.exists(wallpaper_dir): + shutil.rmtree(wallpaper_dir) +os.makedirs(wallpaper_dir) +path = wallpaper_dir name = '0.png' diff --git a/scripts/checkWakkpaperDir.py b/scripts/checkWakkpaperDir.py deleted file mode 100644 index c2867c3..0000000 --- a/scripts/checkWakkpaperDir.py +++ /dev/null @@ -1,7 +0,0 @@ -import os - - -def check(): - dirs = '/tmp/earth-wallpaper/' - if not os.path.exists(dirs): - os.makedirs(dirs) diff --git a/scripts/wifu.py b/scripts/wifu.py index 7324036..442bdc9 100644 --- a/scripts/wifu.py +++ b/scripts/wifu.py @@ -1,10 +1,12 @@ # source: 动漫壁纸 # updateTime + from setWallpaper import set_wallpaper -from checkWakkpaperDir import check import requests import datetime import json +import os +import shutil request_url = "https://api.waifu.im/random?orientation=LANDSCAPE" global img_url @@ -22,14 +24,18 @@ def get_img_url(): def download(url, ext): img = requests.get(url) today = datetime.datetime.utcnow() - path = "/tmp/earth-wallpaper/" + today.strftime("%Y%m%d%H%M%s") + ext + home = os.getenv("HOME") + wallpaper_dir = home + '/.cache/earth-wallpaper/wallpaper/' + if os.path.exists(wallpaper_dir): + shutil.rmtree(wallpaper_dir) + os.makedirs(wallpaper_dir) + path = wallpaper_dir + today.strftime("%Y%m%d%H%M%s") + ext with open(path, "wb") as fwi: fwi.write(img.content) set_wallpaper(path) def main(): - check() res = get_img_url() download(res["img_url"], res["img_ext"]) diff --git a/src/trayicon.cpp b/src/trayicon.cpp index cff2ae3..5bc6b52 100644 --- a/src/trayicon.cpp +++ b/src/trayicon.cpp @@ -160,7 +160,8 @@ void TrayIcon::handle() } void TrayIcon::saveCurrentImg() { - QString dirPath = "/tmp/earth-wallpaper"; + QString dirPath = + QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.cache/earth-wallpaper/wallpaper/"; QDir dir(dirPath); QStringList nameFilters; nameFilters << "[1-9]*"; @@ -171,7 +172,7 @@ void TrayIcon::saveCurrentImg() { QDir(picturePath).mkpath(picturePath); } - QFile target = QFile("/tmp/earth-wallpaper/" + files[files.count() - 1]); + QFile target = QFile(dirPath + files[0]); if (target.copy(picturePath + "/" + files[files.count() - 1])) { QMessageBox::information(nullptr, "保存", "当前壁纸已保存到Picture目录", QMessageBox::Yes);