每天换一个壁纸,每天好心情。

# -*- coding: UTF-8 -*-

from __future__ import unicode_literals

import Image

import datetime

import win32gui,win32con,win32api

import re

from HttpWrapper import SendRequest

StoreFolder = "c:\dayImage"

def setWallpaperFromBMP(imagepath):

k = win32api.RegOpenKeyEx(win32con.HKEY_CURRENT_USER,"Control Panel\Desktop",0,win32con.KEY_SET_VALUE)

win32api.RegSetValueEx(k, "WallpaperStyle", 0, win32con.REG_SZ, "2") #2拉伸适应桌面,0桌面居中

win32api.RegSetValueEx(k, "TileWallpaper", 0, win32con.REG_SZ, "0")

win32gui.SystemParametersInfo(win32con.SPI_SETDESKWALLPAPER,imagepath, 1+2)

def setWallPaper(imagePath):

"""

Given a path to an image, convert it to bmp and set it as wallpaper

"""

bmpImage = Image.open(imagePath)

newPath = StoreFolder + '\mywallpaper.bmp'

bmpImage.save(newPath, "BMP")

setWallpaperFromBMP(newPath)

def getPicture():

url = "http://photography.nationalgeographic.com/photography/photo-of-the-day/"

h = SendRequest(url)

if h.GetSource():

r = re.findall('

Download',h.GetSource())

if r:

return SendRequest(r[0]).GetSource()

else:

print "解析图片地址出错,请检查正则表达式是否正确"

return None

def setWallpaperOfToday():

img = getPicture()

if img:

path = StoreFolder + "\%s.jpg" % datetime.date.today()

f = open(path,"wb")

f.write(img)

f.close()

setWallPaper(path)

setWallpaperOfToday()

print 'Wallpaper set ok!'

其中的httpwrapper是我写的一个http访问的封装:

#!/usr/bin/env python

# -*- coding: UTF-8 -*-

#-------------------------------------------------------------------------------

# Name: 对http访问的封装

#

# Author: qianlifeng

#

# Created: 10-02-2012

#-------------------------------------------------------------------------------

import base64

import urllib

import urllib2

import time

import re

import sys

class SendRequest:

"""

网页请求增强类

SendRequest('http://xxx.com',data=dict, type='POST', auth='base',user='xxx', password='xxx')

"""

def __init__(self, url, data=None, method='GET', auth=None, user=None, password=None, cookie = None, **header):

"""

url: 请求的url,不能为空

date: 需要post的内容,必须是字典

method: Get 或者 Post,默认为Get

auth: 'base' 或者 'cookie'

user: 用于base认证的用户名

password: 用于base认证的密码

cookie: 请求附带的cookie,一般用于登录后的认证

其他头信息:

e.g. referer='www.sina.com.cn'

"""

self.url = url

self.data = data

self.method = method

self.auth = auth

self.user = user

self.password = password

self.cookie = cookie

if 'referer' in header:

self.referer = header[referer]

else:

self.referer = None

if 'user-agent' in header:

self.user_agent = header[user-agent]

else:

## self.user_agent = 'Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20100101 Firefox/8.0'

self.user_agent = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16'

self.__SetupRequest()

self.__SendRequest()

def __SetupRequest(self):

if self.url is None or self.url == '':

raise 'url 不能为空!'

#访问方式设置

if self.method.lower() == 'post':

self.Req = urllib2.Request(self.url, urllib.urlencode(self.data))

elif self.method.lower() == 'get':

if self.data == None:

self.Req = urllib2.Request(self.url)

else:

self.Req = urllib2.Request(self.url + '?' + urllib.urlencode(self.data))

#设置认证信息

if self.auth == 'base':

if self.user == None or self.password == None:

raise 'The user or password was not given!'

else:

auth_info = base64.encodestring(self.user + ':' + self.password).replace('n','')

auth_info = 'Basic ' + auth_info

self.Req.add_header("Authorization", auth_info)

elif self.auth == 'cookie':

if self.cookie == None:

raise 'The cookie was not given!'

else:

self.Req.add_header("Cookie", self.cookie)

if self.referer:

self.Req.add_header('referer', self.referer)

if self.user_agent:

self.Req.add_header('user-agent', self.user_agent)

def __SendRequest(self):

try:

self.Res = urllib2.urlopen(self.Req)

self.source = self.Res.read()

self.code = self.Res.getcode()

self.head_dict = self.Res.info().dict

self.Res.close()

except:

print "Error: HttpWrapper=>_SendRequest ", sys.exc_info()[1]

def GetResponseCode(self):

"""

得到服务器返回的状态码(200表示成功,404网页不存在)

"""

return self.code

def GetSource(self):

"""

得到网页源代码,需要解码后在使用

"""

if "source" in dir(self):

return self.source

return u''

def GetHeaderInfo(self):

"""

u'得到响应头信息'

"""

return self.head_dict

def GetCookie(self):

"""

得到服务器返回的Cookie,一般用于登录后续操作

"""

if 'set-cookie' in self.head_dict:

return self.head_dict['set-cookie']

else:

return None

def GetContentType(self):

"""

得到返回类型

"""

if 'content-type' in self.head_dict:

return self.head_dict['content-type']

else:

return None

def GetCharset(self):

"""

尝试得到网页的编码

如果得不到返回None

"""

contentType = self.GetContentType()

if contentType is not None:

index = contentType.find("charset")

if index > 0:

return contentType[index+8:]

return None

def GetExpiresTime(self):

"""

得到网页过期时间

"""

if 'expires' in self.head_dict:

return self.head_dict['expires']

else:

return None

def GetServerName(self):

"""

得到服务器名字

"""

if 'server' in self.head_dict:

return self.head_dict['server']

else:

return None

__all__ = [SendRequest,]

if __name__ == '__main__':

b = SendRequest("http://www.baidu.com")

print b.GetSource()

python实现定时播放mp3

程序很简单,主要是mp3play模块的应用importmp3play,timefilename="ShouldItMatter.mp3"clip=mp3play.load(filename)while1:iftime.localtime().tm_min%30==0:clip.play()print"nStarttoplay"time.sl

Python2.x中str与unicode相关问题的解决方法

python2.x中处理中文,是一件头疼的事情。网上写这方面的文章,测次不齐,而且都会有点错误,所以在这里打算自己总结一篇文章。我也会在以后学习

分享一个常用的Python模拟登陆类

代码非常简单,而且注释也很详细,这里就不多废话了tools.py#-*-coding:utf8-*-'''#=============================================================================#FileName:tools.py#De

python代码桌面壁纸_Python实现设置windows桌面壁纸代码分享相关推荐

  1. python代码桌面壁纸_Python实现设置windows桌面壁纸代码

    Python实现设置windows桌面壁纸代码 发布于 2015-04-07 16:59:42 | 122 次阅读 | 评论: 0 | 来源: 网友投递 Python编程语言Python 是一种面向对 ...

  2. python代码手机壁纸_Python实现设置windows桌面壁纸代码分享

    #!/usr/bin/env python # -*- coding: UTF-8 -*- #----------------------------------------------------- ...

  3. 批处理设置服务器BIOS序列号,批处理设置windows服务器的代码ThecSafe1.9.4第1/3页

    批处理设置windows服务器的代码ThecSafe1.9.4第1/3页 更新时间:2008年01月19日 20:41:21   作者: 一个既是服务器安全设置工具,也是一个学习批处理非常好的教程.虽 ...

  4. windows server 2012远程桌面服务激活及授权后本地组策略编辑器指定的远程桌面许可证服务器和设置远程桌面授权模式

    windows server 2012远程桌面服务激活及授权后本地组策略编辑器指定的远程桌面许可证服务器和设置远程桌面授权模式 本地组策略编辑器 右键开始-运行:gpedit.msc 进入本地组策略编 ...

  5. 设置Windows桌面壁纸

    最近发现一个API可以设置Windows系统的桌面壁纸,感觉挺好玩 代码: #include <stdio.h> #include <Windows.h>int main() ...

  6. java一键换壁纸_Java 版下载必应每日壁纸并自动设置 Windows 系统桌面(改编自 C# 版)...

    哈哈,好久没有写博客了,已经荒废了,前几天在某 IT 网站看到一个用 C# 写的设置必应每日壁纸为 Windows 系统桌面,看了看源码是通过调用 User32.dll 进行设置的,刚刚最近做的项目更 ...

  7. python实现将图片添加水印并设置为桌面背景

    代码可以直接使用的(所需的包都存在的情况下  python v 3.6+ ) 注意代码中的路径信息 # 给图片添加水印并设置为桌面壁纸 import PIL import time import os ...

  8. python代码变量作业_python - 是否可以在Jenkins的代码中注入变量,然后像往常一样运行作业? - SO中文参考 - www.soinside.com...

    我想使用Jenkins在多个平台浏览器配置上运行多个自动化作业.用python编写的自动化框架已经设置为使用Saucelabs实现此目的. 编写代码的人将其拆分为每个浏览器的单独文件夹,每个文件夹都有 ...

  9. C#如何设置Windows桌面分辨率

    在开发的过程中,有时候我们需要获取Windows桌面的分辨率.这时候.NET为我们提供了相关的类Screen,通过使用Screen类,我们可以获取桌面的相关信息.以下是实例代码: Screen scr ...

最新文章

  1. linux虚拟终端快捷键
  2. 【云计算】Docker删除名称为none的Image镜像
  3. SeekBar的使用(一):实现OnSeekBarChangListener
  4. QT实现3D多个视口渲染场景。
  5. java怎么导入图片_iPad Pro插U盘不能导入图片?技术宅教你怎么做
  6. No module named ‘skimage.metrics‘在Anaconda3中的解决方法
  7. php中的数组用什么统计,php数组元素统计与值汇总
  8. python足球投注_/usr/lib目录属性更改引发的蝴蝶效应
  9. c语言写一个用矩形法求,写一个用矩形法求定积分的通用函数
  10. Objective-c:NSString的常用方法
  11. WPS 二维表格匹配方式(利用VLOOKUP+IF/SWITCH多条件查询)
  12. 【项目管理】开发方法和生命周期绩效域管理
  13. 分类数据之列联表分析案例with sas
  14. HTML 中的 <abbr> 标签与 role 属性
  15. 我去图书馆微信公众号抢座【Python版本】
  16. Android N App分屏模式完全解析
  17. java 删除注册表_java – 如何从Windows注册表中删除JRE条目?
  18. 虚心接受别人善意的批评
  19. ABB机器人之安装备选软件包
  20. php 屏蔽curl访问,php curl指定ip,php curl请求忽略本地host文件,php curl请求跳过本地host文件...

热门文章

  1. Android 通过adb禁止某个应用上网
  2. 网络安全-CTF取证方法大汇总,建议收藏!
  3. HashMap 为什么是2倍扩容
  4. iPad----------教你如何查询ipad型号
  5. ipad怎么分屏方法
  6. ASP.NET搜索引擎
  7. Hadoop 命令操作大全
  8. 腾讯万字Code Review规范出炉!别再乱写代码了
  9. 数智经济转型下如何抢占文创发展新机遇?中国移动咪咕聚焦新一代年轻人需求
  10. 这世界就是,一些人总在昼夜不停地运转,而另外一些人,起床就发现世界已经变了。...