コード例 #1
0
def subscribe(source):
    """Subscribes to a source.

  Also receives some past posts and adds propagate tasks for them.

  http://documentation.superfeedr.com/subscribers.html#addingfeedswithpubsubhubbub

  Args:
    source: Blogger, Tumblr, or WordPress
  """
    if appengine_info.LOCAL:
        logger.info('Running locally, not subscribing to Superfeedr')
        return

    data = {
        'hub.mode':
        'subscribe',
        'hub.topic':
        source.feed_url(),
        'hub.callback':
        util.host_url(f'/{source.SHORT_NAME}/notify/{source.key_id()}'),
        # TODO
        # 'hub.secret': 'xxx',
        'format':
        'json',
        'retrieve':
        'true',
    }

    logger.info(f'Adding Superfeedr subscription: {data}')
    resp = util.requests_post(PUSH_API_URL,
                              data=data,
                              auth=HTTPBasicAuth(SUPERFEEDR_USERNAME,
                                                 SUPERFEEDR_TOKEN))
    handle_feed(resp.json(), source)
コード例 #2
0
def subscribe(source, handler):
  """Subscribes to a source.

  Also receives some past posts and adds propagate tasks for them.

  http://documentation.superfeedr.com/subscribers.html#addingfeedswithpubsubhubbub

  Args:
    source: Blogger, Tumblr, or WordPress
    handler: :class:`webapp2.RequestHandler`
  """
  if appengine_config.DEBUG:
    logging.info('Running in dev_appserver, not subscribing to Superfeedr')
    return

  data = {
    'hub.mode': 'subscribe',
    'hub.topic': source.feed_url(),
    'hub.callback': '%s/%s/notify/%s' % (
      handler.request.host_url, source.SHORT_NAME, source.key.id()),
    # TODO
    # 'hub.secret': 'xxx',
    'format': 'json',
    'retrieve': 'true',
    }

  logging.info('Adding Superfeedr subscription: %s', data)
  resp = util.requests_post(
    PUSH_API_URL, data=data,
    auth=HTTPBasicAuth(appengine_config.SUPERFEEDR_USERNAME,
                       appengine_config.SUPERFEEDR_TOKEN),
    headers=util.REQUEST_HEADERS)
  resp.raise_for_status()
  handle_feed(resp.text, source)
コード例 #3
0
ファイル: superfeedr.py プロジェクト: siakaramalegos/bridgy
def subscribe(source, handler):
  """Subscribes to a source.

  Also receives some past posts and adds propagate tasks for them.

  http://documentation.superfeedr.com/subscribers.html#addingfeedswithpubsubhubbub

  Args:
    source: Blogger, Tumblr, or WordPress
    handler: :class:`webapp2.RequestHandler`
  """
  if appengine_config.DEBUG:
    logging.info('Running in dev_appserver, not subscribing to Superfeedr')
    return

  data = {
    'hub.mode': 'subscribe',
    'hub.topic': source.feed_url(),
    'hub.callback': '%s/%s/notify/%s' % (
      util.host_url(handler), source.SHORT_NAME, source.key.id()),
    # TODO
    # 'hub.secret': 'xxx',
    'format': 'json',
    'retrieve': 'true',
    }

  logging.info('Adding Superfeedr subscription: %s', data)
  resp = util.requests_post(
    PUSH_API_URL, data=data,
    auth=HTTPBasicAuth(appengine_config.SUPERFEEDR_USERNAME,
                       appengine_config.SUPERFEEDR_TOKEN),
    headers=util.REQUEST_HEADERS)
  resp.raise_for_status()
  handle_feed(resp.text, source)
コード例 #4
0
ファイル: push.py プロジェクト: dust2021/douyin_dynamic_push
    def _wechat_push(self,
                     access_token,
                     title,
                     content,
                     url=None,
                     pic_url=None):
        """
        推送(wechat)
        :param access_token: 调用接口凭证
        :param title: 标题
        :param content: 内容
        :param url: 跳转url
        :param pic_url: 图片url
        """
        push_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send'
        params = {"access_token": access_token}
        body = {
            "touser": "******",
            "agentid": self.wechat_agent_id,
            "safe": 0,
            "enable_id_trans": 0,
            "enable_duplicate_check": 0,
            "duplicate_check_interval": 1800
        }

        if pic_url is None:
            body["msgtype"] = "textcard"
            body["textcard"] = {
                "title": title,
                "description": content,
                "url": url,
                "btntxt": "打开详情"
            }
        else:
            body["msgtype"] = "news"
            body["news"] = {
                "articles": [{
                    "title": title,
                    "description": content,
                    "url": url,
                    "picurl": pic_url
                }]
            }

        response = util.requests_post(push_url,
                                      '推送_wechat',
                                      params=params,
                                      data=json.dumps(body))
        logger.info('【推送_wechat】{msg}'.format(
            msg='成功' if util.check_response_is_ok(response) else '失败'))
コード例 #5
0
ファイル: push.py プロジェクト: dust2021/douyin_dynamic_push
 def _server_chan_turbo_push(self, title, content, url=None):
     """
     推送(serverChan_Turbo)
     :param title: 标题
     :param content: 内容
     :param url: 跳转地址
     """
     content = '`' + content + '`[点我直达]({url})'.format(url=url)
     push_url = 'https://sctapi.ftqq.com/{key}.send'.format(
         key=self.serverChan_turbo_SendKey)
     response = util.requests_post(push_url,
                                   '推送_serverChan_Turbo',
                                   params={
                                       "title": title,
                                       "desp": content
                                   })
     logger.info('【推送_serverChan_Turbo】{msg}'.format(
         msg='成功' if util.check_response_is_ok(response) else '失败'))