-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
Konachan/ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import os | ||
import subprocess | ||
from pathlib import Path | ||
import nicegui | ||
|
||
cmd = ['PyInstaller', | ||
'nicegui_win.py', | ||
'--name', 'WallpaperChanger', | ||
'--onefile', | ||
'--clean', | ||
'--add-data', f'{Path(nicegui.__file__).parent}{os.pathsep}nicegui' | ||
] | ||
subprocess.call(cmd) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# 全局代理开关 | ||
proxy: | ||
enabled: true | ||
|
||
headers: | ||
User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0" | ||
Cookie: "vote=1;cf_clearance=lF_zfJ68LNv9iFmGK0gUKwRRmREKqcRFEpKArcJxVEU-1707538630-1-AQdUEHbmz/XqdYBoHD3ezNaRyTxpTyj2THFeZiSmBfVSzsbwAXGMLsPrhmnLFsGI4NeeLGaL2edcvrOR+qbOTmk=;country=--;blacklisted_tags=%5B%22%22%5D;konachan.net=BAh7B0kiD3Nlc3Npb25faWQGOgZFVEkiJThiM2JiNDI5NDhmM2Q3N2NkNTY1YWRiYTUyYzAyYmNlBjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMUhOSDNOUVUwOEZqbll5S0xIMjdUM05ON1JPOWp4YU1UWUMvcHJwZlVrQUU9BjsARg%3D%3D--a28166cfdacc73d6307dfd52817d7333e23452c0;reported_error=1;forum_post_last_read_at=%222024-02-10T07%3A38%3A23%2B01%3A00%22" | ||
|
||
#单独代理开关 | ||
proxies_v2ray: | ||
enabled: true | ||
http: "socks5://127.0.0.1:10808" | ||
https: "socks5://127.0.0.1:10808" | ||
|
||
proxies_ssr: | ||
enabled: false | ||
http: "socks5://127.0.0.1:10807" | ||
https: "socks5://127.0.0.1:10807" | ||
|
||
# Konachan相关配置(domain设置为net不需要代理,com需要代理) | ||
konachan: | ||
rating: s #Safe only Questionable only (Ecchi) Explicit only (Hentai) | ||
domain: com |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import os | ||
|
||
from ui.mainwindow import run_gui_app | ||
if __name__ == "__main__": | ||
final_folder = os.getcwd() + './Konachan/' | ||
os.makedirs(final_folder, exist_ok=True) | ||
run_gui_app() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from nicegui import ui | ||
|
||
ui.label("Hello World") | ||
ui.run(reload=False, native=True) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pyinstaller --onefile --clean --upx-dir=".\upx.exe" --add-data "config.yaml;." main.py | ||
python setup.py build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pyqt5~=5.15.9 | ||
yaml~=0.2.5 | ||
pyyaml~=6.0 | ||
pathlib~=1.0.1 | ||
requests~=2.26.0 | ||
beautifulsoup4~=4.12.2 | ||
nicegui~=1.4.14 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@echo off | ||
python main.py | ||
pause |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import sys | ||
from cx_Freeze import setup, Executable | ||
|
||
# 声明包含的模块及依赖项 | ||
includes = [] | ||
excludes = [] | ||
packages = ["utils", "ui"] | ||
|
||
# 设置主程序入口 | ||
base = None | ||
if sys.platform == "win32": | ||
base = "Win32GUI" | ||
|
||
setup( | ||
name="changeWallpaper", | ||
version="1.0.0", | ||
description="换壁纸", | ||
executables=[ | ||
Executable("main.py", base="Console") | ||
], | ||
options={ | ||
"build_exe": { | ||
"include_files": ["config.yaml"], # 如果有需要包含的数据文件 | ||
"includes": includes, | ||
"excludes": excludes, | ||
"packages": packages, | ||
} | ||
}, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import sys | ||
from PyQt5.QtCore import QThread | ||
from utils.log_util import logger | ||
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget | ||
from utils.wallpaper_change import change_wallpaper | ||
from utils.wallpaper_downloader import ImageDownloader | ||
|
||
|
||
class MainWindow(QMainWindow): | ||
def __init__(self): | ||
super().__init__() | ||
# 创建一个ImageDownloader实例 | ||
self.download_thread = None | ||
self.downloader = ImageDownloader() | ||
self.download_thread = QThread() | ||
self.downloader.moveToThread(self.download_thread) | ||
# 将finished信号连接到处理槽 | ||
self.downloader.finished.connect(self.download_finished) | ||
self.setWindowTitle("Wallpaper Changer") | ||
change_button = QPushButton("Change Wallpaper", self) | ||
download_button = QPushButton("Download Wallpaper", self) | ||
change_button.clicked.connect(change_wallpaper) | ||
download_button.clicked.connect(self.start_download) | ||
layout = QVBoxLayout() | ||
layout.addWidget(change_button) | ||
layout.addWidget(download_button) | ||
central_widget = QWidget() | ||
central_widget.setLayout(layout) | ||
self.setCentralWidget(central_widget) | ||
|
||
def start_download(self): | ||
if self.download_thread is not None and self.download_thread.isRunning(): | ||
logger.warning("下载线程已经在运行中...") | ||
return | ||
try: | ||
self.download_thread.started.connect(self.downloader.start_download) | ||
self.download_thread.start() | ||
except Exception as e: | ||
logger.error(f"An error occurred while starting download: {str(e)}") | ||
|
||
def download_finished(self): | ||
print("Download finished!") | ||
self.download_thread.quit() | ||
self.download_thread.wait() | ||
|
||
|
||
def run_gui_app(): | ||
logger.info('Starting the GUI application...') | ||
app = QApplication(sys.argv) | ||
main_win = MainWindow() | ||
# 设置窗口大小为宽度800像素,高度600像素 | ||
main_win.resize(400, 300) | ||
main_win.show() | ||
sys.exit(app.exec_()) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import yaml | ||
from .log_util import logger | ||
# 读取YAML配置文件 | ||
try: | ||
with open('./config.yaml', "r") as yaml_file: | ||
config_data = yaml.safe_load(yaml_file) | ||
except FileNotFoundError: | ||
logger.error("配置文件不存在,请检查路径。") | ||
except yaml.YAMLError as e: | ||
logger.error("YAML 文件格式错误:", e) | ||
|
||
|
||
# 访问配置数据 | ||
proxy_enabled = config_data.get("proxy", {}).get("enabled", False) | ||
headers = config_data.get("headers", {}) | ||
proxies_v2ray_enabled = config_data.get("proxies_v2ray", {}).get("enabled", False) | ||
proxies_v2ray = config_data.get("proxies_v2ray", {}) | ||
proxies_ssr_enabled = config_data.get("proxies_ssr", {}).get("enabled", False) | ||
proxies_ssr = config_data.get("proxies_ssr", {}) | ||
konachan_rating = config_data.get("konachan", {}).get("rating", "") | ||
konachan_domain = config_data.get("konachan", {}).get("domain", "") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
import pathlib | ||
from pathlib import Path | ||
# 获取当前模块的绝对路径 | ||
module_path = os.path.abspath(__file__) | ||
|
||
# 提取项目根目录路径 | ||
project_root = str(pathlib.Path(module_path).parent.parent) | ||
|
||
# 打印项目根目录路径 | ||
print(project_root) | ||
|
||
# if getattr(sys, 'frozen', False): | ||
# # 如果是PyInstaller打包的环境 | ||
# base_path = Path(sys._MEIPASS) | ||
# print(base_path) | ||
# else: | ||
# 开发环境或直接运行脚本时 | ||
base_path = Path(__file__).parent | ||
print(base_path) | ||
|
||
config_path = base_path / 'config.yaml' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import logging | ||
|
||
# 创建一个logger | ||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.DEBUG) # 设置日志级别,可选DEBUG, INFO, WARNING, ERROR, CRITICAL | ||
|
||
# 创建一个handler,用于写入日志文件 | ||
fh = logging.FileHandler('./app.log') | ||
fh.setLevel(logging.DEBUG) # 文件处理器也可以设置不同的日志级别 | ||
|
||
# 再创建一个handler,用于输出到控制台 | ||
ch = logging.StreamHandler() | ||
ch.setLevel(logging.INFO) | ||
|
||
# 定义handler的输出格式 | ||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | ||
fh.setFormatter(formatter) | ||
ch.setFormatter(formatter) | ||
|
||
# 给logger添加handler | ||
logger.addHandler(fh) | ||
logger.addHandler(ch) | ||
|
||
# 记录一条日志 | ||
# logger.info("This is an info message") | ||
# logger.debug("Debugging information") | ||
# logger.warning("Warning exists") | ||
# logger.error("An error occurred") | ||
# logger.critical("Critical error") | ||
|
||
# 当不再需要日志功能时,可以移除所有handler | ||
# logger.handlers.clear() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import requests | ||
from . import config_util as config | ||
from .log_util import logger | ||
|
||
|
||
def extract_cookies(cookie): | ||
""" | ||
从浏览器或者request headers中拿到cookie字符串,提取为字典格式的cookies | ||
""" | ||
cookies = dict([part.split("=", 1) for part in cookie.split("; ")]) | ||
return cookies | ||
|
||
|
||
def make_request(url, proxy_enabled=None, timeout=10): | ||
""" | ||
发起网络请求到指定的 URL,可选包含 headers 和 proxies 参数。 | ||
参数: | ||
url (str): 请求的 URL。 | ||
headers (dict, 可选): 请求中包含的头部信息。 | ||
proxies (dict, 可选): 请求中使用的代理。 | ||
proxy_enabled (bool): 是否启用代理,默认为 False。 | ||
返回值: | ||
bytes: 请求返回的内容。 | ||
""" | ||
if proxy_enabled is None: | ||
proxy_enabled = config.proxy_enabled | ||
try: | ||
if proxy_enabled: | ||
req = requests.get(url, headers=config.headers, | ||
proxies=config.proxies_v2ray if config.proxies_v2ray_enabled else config.proxies_ssr, | ||
timeout=timeout) | ||
else: | ||
req = requests.get(url, headers=config.headers, timeout=timeout) | ||
return req | ||
except requests.RequestException as e: | ||
logger.error(f'\n----请检查代理设置(检查config.yaml的代理配置)----\n{e}') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import ctypes | ||
from .wallpaper_downloader import select_pic | ||
|
||
|
||
def change_wallpaper(): | ||
SPI_SETDESKWALLPAPER = 0x0014 | ||
wallpaper_path = select_pic() | ||
# 更新壁纸 | ||
result = ctypes.windll.user32.SystemParametersInfoW( | ||
SPI_SETDESKWALLPAPER, 0, wallpaper_path, 3) | ||
if not wallpaper_path: | ||
print('无法更改壁纸。') | ||
elif result: | ||
print('壁纸已更改成功!') |