在SpeedDialPlus中使用EarthViewfromGoogleEarth圖片作背景
如何在Speed Dial Plus中Earth View from Google Earth圖片
介紹
Speed Dial Plus和Earth View from Google Earth都是Chrome中的兩個十分好用的新標籤頁外掛
Speed Dial Plus可以在你開啟一個新的標籤頁的時候提供經常訪問的頁面的快捷方式 雖然還有很多擴充套件, 但是這個功能真心好用

Earth View from Google Earth可以在你開啟一個新的標籤頁的時候展示一副google earth拍攝的圖片(雖然只有1500多個圖片 但是每幅圖都是十分別致的)

需求
這兩個都是十分優秀的標籤頁的工具,那麼問題就是 這兩個不能共同使用 雖然SDP提供了設定背景頁面的方法,但是每次只能設定成一個頁面
解決思路
通過分析Earth View from Google Earth來獲取所有圖片的地址 再在本地或者自己的伺服器中部署一個伺服器 可以隨機返回有效圖片地址中的一個 再將SDP中設定背景為自己的伺服器設定的地址
最終實現開啟新標籤頁(SDP) SDP訪問你的服務地址 服務隨機返回一個圖片地址 SDP最終訪問你設定的新的圖片地址
分析Earth View from Google Earth
本來是打算直接使用Chrome的開發者工具和charles直接分析網路請求,但是每次返回的圖片地址都不一樣只能進一步檢視GoogelEarth的頁面了
如https://g.co/ev/2131 這樣的短鏈,可以看到後面的2131這樣的四位id 嘗試了幾次發現不是連續的。 本來打算寫個指令碼 驗證下一定範圍內哪些數字是有效的
然後日常github 發現了 這個好東西 提供了一個一個介面可以得到當前所有圖片的資訊

可以通過這個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(): #更新所有圖片數量的資料 globalallindex 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的設定 更改其中主題裡的自定義網址為你伺服器執行後的地址就好了 當然 也可以部署在雲伺服器中
改進
程式寫的很隨意 山頂洞人程式設計 效能的話自用還可以的
圖片的話只有google erath的圖片 可以配置或加入更多的圖片 現階段基本沒有擴充套件性 只能看地球了(1500多張圖片還不夠看 只能說明 該換風格了)
【附錄】

資料圖
需要資料的朋友可以加入Android架構交流QQ群聊:513088520
點選連結加入群聊【Android移動架構總群】: 加入群聊
獲取免費學習視訊,學習大綱另外還有像高階UI、效能優化、架構師課程、NDK、混合式開發(ReactNative+Weex)等Android高階開發資料免費分享。