zhanghaoran
文章 文章详情

每次开机设置每日最有缘壁纸(无限更换)

阅读:94 分类:Python 发布时间:2020-06-10

功能介绍:

运行此软件,随机获取并设置 必应 今日壁纸 或 360壁纸库随机分类下的随机壁纸。

exe文件下载地址:https://wwa.lanzous.com/iRHwYdj32re

必须要有D盘哦~

设置开机启动方法:

(win10) 把这个打包后的 exe文件直接放在 C:\Users\你当前登录的用户名\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup 目录下 就可以直接开机自启动了

代码:
import requests
import json
import ctypes
import random


def bying():
    r = requests.get('http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1')
    res = r.content.decode('utf-8')
    response = json.loads(res)
    url = response['images'][0]['url']
    url = 'http://cn.bing.com' + url
    write(url)


def write(url):
    a = requests.get(url)
    path = r'D:\pic.png'
    with open(path, 'wb') as f:
        f.write(a.content)
    ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 0)


def bz360():
    # 不要的壁纸分类
    donot = [12, 29, 7, 22, 16]
    # 1. 获取分类
    imgTypesres = requests.get("http://cdn.apc.360.cn/index.php?c=WallPaper&a=getAllCategoriesV2&from=360chrome").content.decode('utf-8')
    imgTypesres = json.loads(imgTypesres)
    typeList = imgTypesres['data']
    allTypeId = []
    for i in typeList:
        if int(i['id']) not in donot:
            allTypeId.append(i['id'])
    # 2. 随机取一个分类
    reqType = random.choice(allTypeId)
    # 3.随机取一个起始页(1-100)
    reqStart = random.randint(1, 100)
    # 获取图片数据
    imgData = requests.get("http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=getAppsByCategory&cid={0}&start={1}&count=1&from=360chrome".format(reqType, reqStart)).content.decode('utf-8')
    imgData = json.loads(imgData)
    url = imgData["data"][0]['url']
    write(url)


if __name__ == '__main__':
    # 随机选择必应或360
    chose = random.randint(1, 3)
    if chose == 1:
        bying()
    else:
        bz360()

see you.