Speed Dial Plus和Earth View from Google Earth都是Chrome中的兩個十分好用的新標籤頁插件html
Speed Dial Plus能夠在你打開一個新的標籤頁的時候提供常常訪問的頁面的快捷方式 雖然還有不少擴展, 可是這個功能真心好用git
Earth View from Google Earth能夠在你打開一個新的標籤頁的時候展現一副google earth拍攝的圖片(雖然只有1500多個圖片 可是每幅圖都是十分別致的)github
這兩個都是十分優秀的標籤頁的工具,那麼問題就是 這兩個不能共同使用 雖然SDP提供了設置背景頁面的方法,可是每次只能設置成一個頁面web
經過分析Earth View from Google Earth來獲取全部圖片的地址 再在本地或者本身的服務器中部署一個服務器 能夠隨機返回有效圖片地址中的一個 再將SDP中設置背景爲本身的服務器設定的地址編程
最終實現打開新標籤頁(SDP) SDP訪問你的服務地址 服務隨機返回一個圖片地址 SDP最終訪問你設定的新的圖片地址json
原本是打算直接使用Chrome的開發者工具和charles直接分析網絡請求,可是每次返回的圖片地址都不同只能進一步查看GoogelEarth的頁面了 如g.co/ev/2131 這樣的短鏈,能夠看到後面的2131這樣的四位id 嘗試了幾回發現不是連續的。 原本打算寫個腳本 驗證下必定範圍內哪些數字是有效的 而後平常github 發現了這個好東西 提供了一個一個接口能夠獲得當前全部圖片的信息bash
能夠經過這個json數據解析出全部的圖片id 保存到本地做爲服務器的數據源服務器
import requests
import random, re , threading , time , socket
import tornado.web
import tornado.ioloop
allindex = 0
def getUrl():
#經過隨機獲得的位置來獲得對應位置的
id = randomid()
with open('date', 'r') as f:
_image = f.read()
_imagelist = _image.split(',')
_imagelist.pop()
return _imagelist[id]
def updateindex():
#更新全部圖片數量的數據
global allindex
with open('daterand', 'r') as f:
allindex = f.read()
def getAllDate():
#從提供的接口中獲取全部圖片的id並保存下來 同時設置延時天天更新下數據
print('getAllDate')
reponse = requests.get('https://raw.githubusercontent.com/limhenry/earthview/master/earthview.json')
html = reponse.text
with open('date', 'w') as f:
imageList = re.findall('"image":".*?"' , html)
for image in imageList:
imageurl = re.findall('[0-9]{4,5}' ,image)
f.write(imageurl[0] + ',')
with open('daterand', 'w') as f:
f.write(str(len(imageList)))
updateindex()
time.sleep(60 * 60 * 24)
getAllDate()
def randomid():
#隨機數什麼的
global allindex
_allindex = int(allindex)
id = random.randint(0, _allindex)
return id
class earthImage(tornado.web.RequestHandler):
def get(self, *args, **kwargs):
_id = getUrl()
imageurl = 'http://www.gstatic.com/prettyearth/assets/full/%s.jpg'%(_id)
print(imageurl)
#直接指向隨機圖片的地址
self.redirect(imageurl)
application = tornado.web.Application([
(r"/earthImage" , earthImage)
])
def runServer():
#trnado 服務器的配置 我這裏在運行以後會顯示當前的地址
port = 9011
application.listen(port)
localIP = socket.gethostbyname(socket.gethostname())
print("run in %s:%s"%(localIP,port))
tornado.ioloop.IOLoop.instance().start()
def startServer():
print('startServer')
runServer()
def main():
//這裏開了兩個線程 防止取得圖片數據的時候訪問阻塞
updateindex()
thread_getInfoDate = threading.Thread(target=getAllDate, name='getAllDate')
thread_startServer = threading.Thread(target=startServer, name='startServer')
thread_getInfoDate.start()
thread_startServer.start()
main()
複製代碼
最後打開SpeedDialPlus的設置 更改其中主題裏的自定義網址爲你服務器運行後的地址就行了 固然 也能夠部署在雲服務器中網絡
程序寫的很隨意 山頂洞人編程 性能的話自用還能夠的app
圖片的話只有google erath的圖片 能夠配置或加入更多的圖片 現階段基本沒有擴展性 只能看地球了(1500多張圖片還不夠看 只能說明 該換風格了)