ubuntu 16.04LTS 開機啟動自動更換桌布
前言
上週電腦重灌,換了ubuntu 16.04,想起來之前上課老師也是ubuntu而且他還提到他桌面是他自己寫的個小指令碼實現的自動更換桌面桌布的,昨天晚上心血來潮自己網上搜了點資料實現了一下 = =
功能
功能的話,是從必應桌布爬取最新的那張桌布,然後本來因為我怕電腦又放了太多東西,就設定了個圖片最大的數目,到達這個閾值就刪除所有的圖片= =|| 通過python的os模組,設定桌布,這裡可以參考:how-to-change-desktop-background-from-command-line-in-unity , 還有就是考慮到剛開機時我不一定連得上網(辛酸 T_T),所以設定了一個爬取的間隔
程式碼
# -*- coding: utf-8 -*-
#!/usr/bin/python
#!/bin/bash
# ---------------------------------------------------------- #
# This is a script which can change background automatically #
# every time the system starts. #
# author: Huang Zhenyang #
# email: [email protected] #
# ---------------------------------------------------------- #
# ----- Import ----- #
import os
import re
import urllib
import time
import socket
# --- End Import --- #
class Spider(object):
"""
This is the spider to get the img from being
"""
def __init__( self, img_matched_pattern_para, url_para, file_name_para ):
"""
init function
:param img_matched_pattern_para: the pattern to match a img
:param url_para: url to crawler
:param file_name_para: file name
"""
self.img_matched_pattern = img_matched_pattern_para
self.url = url_para
self.file_name = file_name_para
def get_img(self):
"""
download the image
:return:
"""
html = self.get_html()
img_pos = re.search(self.img_matched_pattern, html)
img_page_href = self.url + img_pos.group()[6:-7] + "download"
urllib.urlretrieve(img_page_href, self.file_name)
def get_html(self):
"""
return the html
:return: page's html <type 'str'>
"""
page = urllib.urlopen(self.url)
html = page.read()
return html
class Controller(object):
"""
This is the controller to control the spider's parameters.
"""
def __init__(self, pattern_href_para, path_para, url_para, img_max_num_para):
"""
:param pattern_href_para: href's match pattern
:param path_para: path to save images
:param url_para: url
:param img_max_num_para: max number that the
"""
self.pattern_href = pattern_href_para
self.path = path_para
self.url = url_para
self.img_max_num = img_max_num_para
self.file_name = ""
self.init_file_name = "0.jpg"
self.file_extension_name = ".jpg"
def judge(self):
"""
judge if the number of images is grater than img_max_num.
if true, delete all of them and then run spider, else directly run spider.
Also, we should set the file name.
:return:
"""
root = None
_dirs = None
files = None
for root, _dirs, files in os.walk(self.path, True):
pass
files_len = len(files)
if files_len == 10:
for i in range(0, 10):
os.remove(root + files[i])
self.file_name = self.path + self.init_file_name
else:
self.file_name = self.path + str(files_len) + self.file_extension_name
def run_spider(self):
"""
run spider.
TODO: This function needs to be modified in the future which makes these two class coupling too much.
:return:
"""
# In case user's computer hasn't connect the internet.
for i in range(0, 60):
try:
spider = Spider(self.pattern_href, self.url, self.file_name)
spider.get_img()
break
except IOError as e:
print "Connection error: %s" % e
time.sleep(60)
continue
except Exception as e:
print "Connection error: %s" % e
time.sleep(60)
continue
c_path = '"file://' + self.file_name + '"' # absolute path
# call system command to change the gnome background
os.system('gsettings set org.gnome.desktop.background picture-uri ' + c_path)
print "gsettings set org.gnome.desktop.background picture-uri " + c_path
if __name__ == '__main__':
pattern_href = r'href="/photo/.*?"'
path = '/home/hzy/圖片/backgrounds/'
url = 'https://bing.ioliu.cn/'
img_max_num = 10
controller = Controller(pattern_href, path, url, img_max_num)
controller.judge()
controller.run_spider()
開機自啟動
在/home/hzy/.config/autostart
中,新建一個xxx.desktop
的檔案,內容如下:
[Desktop Entry]
Name=autoChangeBackgroundImg
Comment=Python Program
Exec=python /home/hzy/Script/autoChangeBackgroundImg/autoChangeBackgroundImg.py
Icon=/home/hzy/Script/autoChangeBackgroundImg/autoChangeBackgroundImg.png
Terminal=false
MultipleArgs=false
Type=Application
Categories=Application;Development;
StartupNotify=true
說明:
1. Exec 後面的路徑就是該指令碼的路徑
2. Icon的話可以自己隨便找個圖片,設定成該路徑即可
相關推薦
ubuntu 16.04LTS 開機啟動自動更換桌布
前言 上週電腦重灌,換了ubuntu 16.04,想起來之前上課老師也是ubuntu而且他還提到他桌面是他自己寫的個小指令碼實現的自動更換桌面桌布的,昨天晚上心血來潮自己網上搜了點資料實現了一下 = = 功能 功能的話,是從必應桌布爬取最新的那張桌布
Ubuntu 16.04 開機啟動和定時任務
1,crontab 格式:M H D m d cmd == 分 時 天 月 周幾 命令 引數 : crontab -e : 執行文字編輯器來設定時程表,內定的文字編輯器是 VI,如果你想用別的文字編輯器,則請先設定 VISUAL 環境變數 來指定使用那個文字編輯器(比如說
Ubuntu 16.04LTS修改開機啟動項
裝上Ubuntu16.04後,每次開機都得手選開機項,挺麻煩 sudo vi /etc/default/grub GRUB_DEFAULT=0 GRUB_HIDDEN_TIMEOUT=0 GRUB_HIDDEN_TIMEOUT_QUIET=true GRUB_TIMEOUT
Debian、Ubuntu系統中開機啟動設置
debian ubuntu rc.local Unix系統使用比較廣泛的便是Linux系統,而基於Linux內核下也有很多衍生的其他的系統,其中就有Debian、Ubuntu這類的系統,在Linux系統下平時使用習慣的開機啟動/etc/rc.local或/etc/rc.d/rc.local就
Ubuntu 16.04LTS安裝Nginx
exit sudo uri 指定 get body 許可證 cnblogs tar Nginx ("engine x") 是一個高性能的 HTTP 和 反向代理 服務器,也是一個 IMAP/POP3/SMTP 代理服務器。 Nginx 是由 Igor Sysoev 為俄羅斯
linux開機啟動自動執行某個指令碼
有時候我們需要在開機的拉起一個服務或程序。 比較方便的改法是在檔案/etc/rc.local,編輯這個檔案,在末尾新增 source 指令碼名稱.sh 指令碼run_httpd_server.sh的內容 #!/bin/bash export BASE_DIR=$(p
ubuntu 16.04 開機新增磁碟掛載
1.用命令確定掛載位置 sudo mkdir disk sudo mount -t ext4 /dev/sdb /media/upDiff/disk 2.在/etc/fstab中添加掛載 sudo gedit /etc/fstab #開啟檔案 /dev/sdb /media/u
Ubuntu下新增開機啟動項
方法:編輯rc.local指令碼 原理: Ubuntu開機之後會執行/etc/rc.local檔案中的指令碼, 所以我們可以直接在/etc/rc.local中新增啟動指令碼。 當然要新增到語句:exit 0 前面才行。 例:開機啟動wifi控制軟體nm-applet 1.開啟rc.l
ubuntu 16.04LTS 安裝pcl1.7
主要參考了兩篇文件 第一篇:https://www.cnblogs.com/gaoxiang12/p/4633316.html 第二篇:https://blog.csdn.net/e_small/article/details/79581484 新增安裝了libopen
ubuntu 16.04 boot 啟動報錯 dns-clean.service 、plymouth-quit.service
ubuntu 16.04 boot 啟動報錯 1,ubuntu系統版本 2,dns-clean.service 報錯 3,plymouth-quit.service報錯,待解決 1,ubuntu系統版本 # lsb_release
ubuntu 16.04開機只有桌面
晚上一開機電腦只有桌面,當時感覺就有點蒙。 還是網上面對這種問題都會有答案。 還好能進入命令列模式, 玩ubuntu的人都知道怎麼進吧? sudo apt install ubuntu-desktop --reinstall reboot 就好了。 原來是之前我下載了一個u
Ubuntu 16.04LTS +Anaconda3+Python3.6 安裝opencv
親測,如果你的環境跟我相同,那麼只需一行命令即可安裝opencv3.1.0 conda install -c menpo opencv3 問你 Proceed ([y]/n)? 輸入y 檢查op
ubuntu 16.04開機進入emergency mode的一種可能
今日開機後突然進入emergency mode,胡亂折騰一通,終於找到問題所在,查閱資料後終於解決了問題。 起因:電腦是win10+ubuntu雙系統,前一日在win10上執行虛擬機器做實驗時,突然系統重啟。重啟後,win10系統正常,但今天進入Ubuntu就直接到em
ubuntu 16.04LTS + cuda +caffe
首先進入terminal下 1.檢視顯示卡型號:lspci 00:00.0 Host bridge: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor DRAM Controller (rev 06) 00:01.0 PCI
Ubuntu 16.04開機自啟Nginx簡單指令碼
本文要記述的是最簡單的Ubuntu下開機自啟 nginx的指令碼 這裡將nginx裝在了/usr/local/nginx目錄下,nginx本身沒有註冊成服務,所以直接使用服務開機自啟是不行的,除非自己寫nginx.service指令碼,這不在本文範疇內。 建立指令碼檔案 $ sudo vim /etc/i
Android開機啟動自動播放視訊
最近客戶有個小需求:在一個android系統平臺上一開機就自動播放SD卡某檔案目錄下的視訊檔案。 需求比較簡單,不多說了,直接貼程式碼: 1 首先配置 AndroidManifest.xml 註冊一個開機服務廣播 主要程式碼如下: <receiver android:name=".Bo
安裝ubuntu後沒有開機啟動項解決方案
然後是坑爹的引導問題了。先說最常見的一個。在重灌系統之後,開機啟動介面的ubuntu引導不見了,直接進入新安裝的window系統中。下面是如何恢復ubuntu引導的方法: 1)準備一張ubuntu系統安裝盤; 2)將ubuntu系統安裝盤放入光碟機,重新啟動計算機,進入BI
ubuntu系統設定開機啟動進入文字模式
chmod +w /boot/grub/grub.cfg //新增可寫許可權 vi /boot/grub/grub.cfg //開啟grub配置檔案 在相對應的啟動選項中找到“quiet splash”,其中splash是設定啟動畫面,可留可不留。不留的話就直接把spl
已解決:mysql無法遠端訪問10061錯誤,各種方式授權後也無效(ubuntu 16.04LTS mysql 5.7.13)
先直接說解決方案 /etc/mysql/mysqld.conf.d/mysqld.cnf bind-address = 127.0.0.1 前面加# 變成 # bind-address = 127.0.0.1 sudo service mysql restart 5.5.7
ubuntu 自定義開機啟動服務
首先宣告,這裡說的 ubuntu 指的是 ubuntu16.04第一步:新建 service 檔案即 xxx.service 檔案。1、轉到指定目錄下$ cd /lib/systemd/system2、建立 xxx.service 檔案$ vi xxx.service按 i