Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
fix(scripts/src): 修改当前壁纸保存路径,防止重启后壁纸消失
Browse files Browse the repository at this point in the history
Author: ambition-echo
  • Loading branch information
ambition_echo committed Aug 9, 2022
1 parent aaf187f commit 46206b9
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 21 deletions.
6 changes: 5 additions & 1 deletion scripts/24hourWallpaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
11 changes: 8 additions & 3 deletions scripts/Bing-rand.py
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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)

Expand Down
11 changes: 8 additions & 3 deletions scripts/Bing-tody.py
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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)

Expand Down
9 changes: 8 additions & 1 deletion scripts/FY-4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'


Expand Down
9 changes: 8 additions & 1 deletion scripts/Himawari-8.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@
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 = '0.png'


Expand Down
7 changes: 0 additions & 7 deletions scripts/checkWakkpaperDir.py

This file was deleted.

12 changes: 9 additions & 3 deletions scripts/wifu.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"])

Expand Down
5 changes: 3 additions & 2 deletions src/trayicon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]*";
Expand All @@ -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);
Expand Down

0 comments on commit 46206b9

Please sign in to comment.