-
使用Python写了一个bing壁纸下载
这是第一个版本,算是1.0版本,实现了选择日期,然后自动批量下载4K的壁纸,图片全部来源必应。 这里我会将代码全部公开,然后包括软件的下载等,后续会更新,也会更新新版本的代码,你可以根据代码自行打包exe软件。 开箱即用的版本请看文末下载区域。 代码:(接口来源网络) import requests import os from datetime import datetime, timedelta import tkinter as tk from tkinter import messagebox from tkcalendar import DateEntry from requests.packages.urllib3.exceptions import InsecureRequestWarning import threading # 忽略不安全请求警告 requests.packages.urllib3.disable_warnings(InsecureRequestWarning) def download_bing_wallpapers(start_date, end_date): base_url = "https://bing.ee123.net/img/" size = "UHD" output_dir = "bing_wallpapers" # 创建保存壁纸的文件夹 if not os.path.exists(output_dir): os.makedirs(output_dir) session = requests.Session() session.verify = False current_date = start_date while current_date <= end_date: date_str = current_date.strftime('%Y%m%d') params = { 'date': date_str, 'size': size, 'type': 'json' } response = session.get(base_url, params=params) # 检查请求是否成功 if response.status_code == 200: try: data = response.json() image_url = data.get('imgurl') # 使用 'imgurl' 获取图片URL if image_url: image_name = f"{date_str}.jpg" image_path = os.path.join(output_dir, image_name) # 下载图片 img_response = session.get(image_url) if img_response.status_code == 200: with open(image_path, 'wb') as img_file: img_file.write(img_response.content) print(f"Downloaded: {image_name}") else: print(f"Failed to download image from {image_url}") else: print(f"No 'imgurl' found in the response for {date_str}") except ValueError: print(f"Failed to decode JSON response for {date_str}") else: print(f"Failed to retrieve data for {date_str}, status code: {response.status_code}") current_date += timedelta(days=1) messagebox.showinfo("完成", "壁纸下载完成!") def start_download(): start_date = start_date_entry.get_date() end_date = end_date_entry.get_date() if start_date > end_date: messagebox.showerror("错误", "开始日期不能晚于结束日期") return # 使用线程来运行下载任务,避免阻塞主线程 download_thread = threading.Thread(target=download_bing_wallpapers, args=(start_date, end_date)) download_thread.start() # 创建主窗口 root = tk.Tk() root.title("Bing 壁纸下载器") # 日期选择框 tk.Label(root, text="选择开始日期:").grid(row=0, column=0,…- 46
- 0