猫史档案馆


【Python作品分享】下载壁纸

用户:爽快的树毛蛹pokV爽快的树毛蛹pokV查看:0 回复:2 评论:0 创建时间:2021-07-27T15:04:08


【作品展示】

center_image

 

【作品介绍】

下载bing每日的背景

www.喵

附带生成打乱密码(默认关闭)

 

【作品源代码】

#请安装 os,requests,random(非必须)


def Rand_Password(shout_password=36,range_password=8):
	import random
	num=random.randint(1*10**48,1*10**49-1)
	alphabet='abcdefjhigklmnopqrstuvwxyzABCDEFJHIGKLMNOPQRSTUVWXYZ'
	letters=''
	for i in range(shout_password):
		letters+=alphabet[random.randint(0,len(alphabet)-1)]
	password=list(str(num)+letters)
	random.shuffle(password)
	password=''.join(password)
	password_long=''
	for i in range(range_password):
		password_long+=password
	password_long=list(password_long)
	random.shuffle(password_long)
	password_long=''.join(password_long)

	return password_long

def get_image_list(API_URL):
	response=requests.get(API_URL)
	json_data=response.json()
	return json_data['images']

def get_images(image_list,BING_URL):
	images=[]
	for image_data in image_list:
		image_url=BING_URL+image_data['url']
		response=requests.get(image_url)
		image_content=response.content
		image={
			'content':image_content,
			'date':image_data['enddate']
		}
		images.append(image)
	return images

def save_images(images,path):
	import os
	path=path+'/壁纸'
	image_files=[]
	date_=''
	if not os.path.exists(path):
		os.makedirs(path)
	for image in images:
		image_path=path+'/%s.jpg'%image['date']
		date_+=image['date']+'//'

		with open(image_path,'wb') as f:
			f.write(image['content'])
		image_files.append(image_path)
	if not os.path.exists(path+'/date/'+'date.log'):
		if not os.path.exists(path+'/date'):
			os.makedirs(path+'/date/')
		with open(path+'/date/'+'date.log','w') as f:
			f.write('')
	date_='/--/'+date_
	with open(path+'/date/'+'date.log','a') as f:
		f.write(date_)
	return image_files

def download_bing_images(path):
	BING_URL='https://cn.喵'
	API_URL=BING_URL+'/HPImageArchive.aspx?format=js&idx=1&n=8'

	image_list=get_image_list(API_URL)
	images=get_images(image_list,BING_URL)
	print('download over')
	return save_images(images,path)



if __name__=='__main__':
	import requests
	# 默认位置为Utilly/壁纸
	path='Utilly'
	download_bing_images(path)
	# Rand_Password()
	pass


 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
爽快的树毛蛹pokV爽快的树毛蛹pokV

BING_URL='htt'+'ps://cn'+'.bing'+'.com'

点赞0


评论


Python-happyyyyPython-happyyyy

Sublime Text。。。

点赞0


评论