首页 > 编程语言 > 详细

Ubuntu使用Python脚本实现每日自动同步Bing壁纸

时间:2016-03-13 00:46:21      阅读:291      评论:0      收藏:0      [点我收藏+]

1
#!/usr/bin/python3 2 #-*-coding=utf-8-*- 3 4 import os # 利用os.system(command)实现设置壁纸 5 import re # 用来匹配必应首页图片地址 6 import time 7 import sys # for stopping this script in csae of any mistake 8 from urllib.request import urlopen # for fetching web pages 9 10 patten = rg_img={url:\‘(?P<h>.*)\‘,id # find where the picture is by its html patten 11 path = /home/legendlc/Desktop/Python/WallPapers/ # folder for storing pics 12 url = "https://cn.bing.com" # target url 13 refreshInterval = 10 * 60 # 单位为秒 14 15 _filename = none 16 filename = none 17 while True: 18 now = time.localtime() 19 _filename = filename 20 filename = str(now.tm_year) + _ + str(now.tm_mon) + _ + str(now.tm_mday) + .jpg 21 22 if _filename != filename: 23 try: 24 response = urlopen(url) 25 except Exception as e: 26 print(e) 27 html = response.read().decode(utf-8) # get html in form of string 28 29 pos = re.search(patten, html) 30 if pos == None: 31 print(Html Patten out-of-date) 32 sys.exit(0) 33 img_url = http://s.cn.bing.net + pos.group(h) # get image url 34 35 x = urlopen(img_url) 36 f = open(path + filename, wb) 37 f.write(x.read()) 38 f.close() # download the image into a local file named by date 39 40 c_path = "file:// + path + filename + " # absolute path 41 os.system(gsettings set org.gnome.desktop.background picture-uri + c_path) # call system command to change the gnome background 42 time.sleep(refreshInterval) 43 else: 44 time.sleep(refreshInterval)

Ubuntu使用Python脚本实现每日自动同步Bing壁纸

原文:http://www.cnblogs.com/legend1213/p/5270887.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!