美文网首页
03 发送新库提醒到手机

03 发送新库提醒到手机

作者: 夏威夷的芒果 | 来源:发表于2018-07-15 16:22 被阅读50次

    这一个工作实际上分为两步,第一步:请求接口,第二步:使用Pushover软件来推送到手机上。总之就是,需要把api筛选的结果发送到服务器上。

    之前的是怎么做的?
    输入一个网址,得到网页。这是提交一个地址,得到了一个请求,请求到内容。
    比如http://abc.com?q=xxx 这种形式,带了一个钩子,这时候是GET请求,GET后面的钩子代表了一些私人信息,但是这时候这是不安全的,私人信息不能明文写,另外放在网页钩子里面也是不合适的,这时候就需要使用POST请求来证明自己是谁了,而且POST请求里面的信息主要就是私人信息。

    第一步使用GET,第二步使用POST。

    Pushover的API

    这个网址里面阐述了Pushover的API的使用方法 https://pushover.net/api

    Pushover Message API

    Pushover使用一个简单的、版本化的REST API来接收消息并将它们广播到运行我们设备客户端。为了简化用户注册过程和API的使用起见,这里无需的带外身份验证机制或每个调用签名库,比如OAuth。标准的HTTP库几乎每种语言都可以使用,甚至可以从命令行使用,而不需要任何定制模块或额外的依赖项。更多请看 FAQ

    为了简化向多个用户发送时收集用户密钥的过程,我们有一个新的订阅API可用。

    TL;DR

    1。注册您的应用程序,设置它的名称并上传一个图标,并获得一个相应的API令牌(通常在我们的文档和[代码示例]中称为APP_TOKEN (https://pushover.net/faq#library))。

    1. https://api.pushover.net/1/messages.json POST 一个 HTTPS 请求,请求中包含以下参数:
      • token (必填) - 您应用的 API token
      • user (必填) - 您的user/group的key (不是 e-mail address), 登录到 our dashboard时可见,(在我们的文档和代码演示里常记作USER_KEY)
      • message (必填) - your messageSome optional parameters may be included:
      • attachment - an image attachment to send with the message; see attachments for more information on how to upload files
      • device - your user's device name to send the message directly to that device, rather than all of the user's devices (multiple devices may be separated by a comma)
      • title - your message's title, otherwise your app's name is used
      • url - a supplementary URL to show with your message
      • url_title - a title for your supplementary URL, otherwise just the URL is shown
      • priority - send as -2 to generate no notification/alert, -1 to always send as a quiet notification, 1 to display as high-priority and bypass the user's quiet hours, or 2 to also require confirmation from the user
      • sound - the name of one of the sounds supported by device clients to override the user's default sound choice
      • timestamp - a Unix timestamp of your message's date and time to display to the user, rather than the time your message is received by our API

    That's it. Make sure your application is friendly to our API servers and you're all set. For more information on each parameter, keep reading or jump to a section at the left.

    Need help using our API or found an error in the documentation? Drop us a line.

    使用这个库的时候应该注意几点:

    # 两部分:第一部分:get_info_list  第二部分: push it
    from datetime import datetime
    import requests
    
    def get_info_list():     #解析消息列表
        api = 'https://api.github.com/search/repositories?q='
        query = 'topic:crawler+language:python+'
        when  = 'created:' + str(datetime.now()).split()[0]
        full_url = api + query + when
        print(full_url)
        r = requests.get(full_url)
        return r.json()['items']
    
    def push_it(message):     #利用API推送信息
        request.post(message)
        #如果想要解析信息的话,一般会写 r = request.post(message) ,但是无所谓
        #这里我们并不管锥网页的内容,只是想要把信息推送到手机上就可以了
    
    
    def make_message(repo_info):    #message制作成型,制作完成后,交给push_it函数
        title = repo_info['name']
        url = repo_info['html_url']
        message = repo_info['description']
        token = 'a7ax2q2f5nxys79x6k2cvirz66khsR'  
        #这个数据自己去找,看官别想用我的API
        key = 'u3jfzjxk5v9b2a97mijxth58ardzvFOUR'
        #这个数据自己去找,看官别想用我的KEY
        api = 'https://api.pushover.net/1/messages.json?'
        template='token={token}&user={user}&message={msg}&title={t}&url={url}'
        #这个是字符串模板,常常是复杂字符串拼接时候会用的,是一种很简明的办法
        query = template.format(
            token = token,
            user = user,
            msg  =message,
            t = title,
            url = url
        )
        full_url=  api + query
        return full_url
    
    info_list = get_info_list()
    
    for info in info_list:
        message = make_messsgae(info)
        push_it(message)
    

    相关文章

      网友评论

          本文标题:03 发送新库提醒到手机

          本文链接:https://www.haomeiwen.com/subject/wrrfpftx.html