AVt天堂网 手机版,亚洲va久久久噜噜噜久久4399,天天综合亚洲色在线精品,亚洲一级Av无码毛片久久精品

當前位置:首頁 > 科技  > 軟件

用Python下載壁紙并自動更換桌面

來源: 責編: 時間:2023-11-07 17:17:11 320觀看
導讀今天我們繼續用Python寫一個小工具,一方面實現壁紙自由,另一方面實現桌面更換自由!壁紙 API我們這里使用一個開源在 GitHub 上的必應壁紙 API 作為壁紙的來源https://github.com/zenghongtu/bing-wallpaper圖片從 readme

今天我們繼續用Python寫一個小工具,一方面實現壁紙自由,另一方面實現桌面更換自由!pc928資訊網——每日最新資訊28at.com

壁紙 API

我們這里使用一個開源在 GitHub 上的必應壁紙 API 作為壁紙的來源pc928資訊網——每日最新資訊28at.com

https://github.com/zenghongtu/bing-wallpaperpc928資訊網——每日最新資訊28at.com

圖片圖片pc928資訊網——每日最新資訊28at.com

從 readme 當中我們可以知道,在 web 應用中我只需要使用如下引用即可pc928資訊網——每日最新資訊28at.com

<img src="https://bingw.jasonzeng.dev/?w=800"/>

實在是太方便了pc928資訊網——每日最新資訊28at.com

接口使用

下面我們來看下該 API 的具體調用規則pc928資訊網——每日最新資訊28at.com

  • 1、傳入 resolution 參數可以指定壁紙圖像的分辨率。默認為1920x1080,可選值如下:
UHD1920x12001920x10801366x7681280x7681024x768800x600800x480768x1280720x1280640x480480x800400x240320x240240x320

UHD 就是高清,圖片比較大。pc928資訊網——每日最新資訊28at.com

  • 2、傳入 index 可以獲取某一天的圖片,0 表示今天,1 表示昨天,以此類推,index=random 表示隨機一天。
  • 3、傳入 date 可以獲取從某一天到今天的圖片,比如 data=20210401。
  • 4、傳入 w 和 h 可以指定圖片的寬度和高度。
  • 5、傳入 qlt 可以指定圖片的質量,取值范圍是 0 到 100。

舉個例子

我們直接在瀏覽器輸入如下地址pc928資訊網——每日最新資訊28at.com

http://bingw.jasonzeng.dev?resolutinotallow=UHD&index=random&w=1000&format=json

Output:pc928資訊網——每日最新資訊28at.com

{ "startdate": "20220105", "copyright": "Plate-billed mountain toucan in Bellavista Cloud Forest Reserve, Ecuador (? Tui De Roy/Minden Pictures)", "urlbase": "/th?id=OHR.MountainToucan_EN-US7120632569", "title": "A plate-billed mountain toucan", "url": "https://www.bing.com/th?id=OHR.MountainToucan_EN-US7120632569_UHD.jpg&w=1000"}

可以說是相當方便了pc928資訊網——每日最新資訊28at.com

也可以直接在 css 當中使用pc928資訊網——每日最新資訊28at.com

background-image: url(https://bingw.jasonzeng.dev/?index=random);height: 100%;background-position: center;background-repeat: no-repeat;background-size: cover;

Python 調用

下面我們看一下如何通過 Python 進行調用,也很簡單pc928資訊網——每日最新資訊28at.com

import requestsdef get_wallpaper():    for i in range(30):        url = "https://bingw.jasonzeng.dev?resolutinotallow=UHD&index=%s" % str(i)        print(url)        res = requests.get(url)        with open("wallpaper/" + "%s.jpg" % str(i),"wb") as w:            w.write(res.content)if __name__ == "__main__":    get_wallpaper()

上面代碼就是獲取前30張壁紙,我們可以修改range的參數,來獲取不同數量的壁紙pc928資訊網——每日最新資訊28at.com

抓取效果如下pc928資訊網——每日最新資訊28at.com

圖片圖片pc928資訊網——每日最新資訊28at.com

更換桌面

壁紙有了,下面我們就來進行自動切換桌面壁紙,這里使用win32con和win32gui操作桌面壁紙pc928資訊網——每日最新資訊28at.com

def windows_img(paper_path):    k = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control panel//Desktop", 0, win32con.KEY_SET_VALUE) # 在注冊表中寫入屬性值    win32api.RegSetValueEx(k, "wapaperStyle", 0, win32con.REG_SZ,"2")  # 0 代表桌面居中 2 代表拉伸桌面    win32api.RegSetValueEx(k, "Tilewallpaper", 0, win32con.REG_SZ,"0")    win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER, paper_path, win32con.SPIF_SENDWININICHANGE) # 刷新桌面

然后就是從已經下載的壁紙當中選擇圖片pc928資訊網——每日最新資訊28at.com

def change_wallpaper():    pic_list = os.listdir("wallpaper")  # 得到文件路徑下的圖片,列表類型    i=0    print(pic_list)    while True:        pic = "wallpaper"+'/{}'.format(pic_list[i])        abspath_pic = os.path.abspath(pic)        windows_img(abspath_pic)        print(abspath_pic)        time.sleep(1000)  # 設置壁紙更換間隔        i += 1        if i==len(pic_list):  # 如果是最后一張圖片,則重新到第一張            i=0if __name__ == '__main__':    change_wallpaper()

這樣一個簡單的自動切換桌面壁紙的工具就完成了,快來嘗試一下吧!pc928資訊網——每日最新資訊28at.com

本文鏈接:http://www.tebozhan.com/showinfo-26-17559-0.html用Python下載壁紙并自動更換桌面

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。郵件:2376512515@qq.com

上一篇: 高可擴展性架構演進:Java與MySQL在微服務中的應用

下一篇: 輕松掌握Python正則表達式:高效處理文本數據的秘訣!

標簽:
  • 熱門焦點
Top