在SpeedDialPlus中使用EarthViewfromGoogleEarth图片做背景

如何在Speed Dial Plus中Earth View from Google Earth图片

介绍

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

分析Earth View from Google Earth

原本是打算直接使用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多张图片还不够看 只能说明 该换风格了)

相关文章
相关标签/搜索