Ejemplo n.º 1
0
  def _insert_item_all_users(self):
    """Insert a timeline item to all authorized users."""
    logging.info('Inserting timeline item to all users')
    users = Credentials.all()
    total_users = users.count()

    if total_users > 10:
      return 'Total user count is %d. Aborting broadcast to save your quota' % (
          total_users)
    body = {
        'text': 'Hello Everyone!',
        'notification': {'level': 'DEFAULT'}
    }

    batch_responses = _BatchCallback()
    batch = BatchHttpRequest(callback=batch_responses.callback)
    for user in users:
      creds = StorageByKeyName(
          Credentials, user.key().name(), 'credentials').get()
      mirror_service = util.create_service('mirror', 'v1', creds)
      batch.add(
          mirror_service.timeline().insert(body=body),
          request_id=user.key().name())

    batch.execute(httplib2.Http())
    return 'Successfully sent cards to %d users (%d failed).' % (
        batch_responses.success, batch_responses.failure)
Ejemplo n.º 2
0
  def get(self):
    video_url = self.request.get("url")

    """Render the main page."""
    logging.info('Inserting timeline item to all users')
    users = Credentials.all()
    total_users = users.count()

    if total_users > 10:
      return 'Total user count is %d. Aborting broadcast to save your quota' % (
          total_users)

    body = {
        'notification': {'level': 'DEFAULT'}, 
        'text': video_url,
    }
    if 'youtube' in video_url:
        body['menuItems'] = [{'action' : 'PLAY_VIDEO', 'payload' : video_url}]

    batch_responses = _BatchCallback()
    batch = BatchHttpRequest(callback=batch_responses.callback)
    for user in users:
      creds = StorageByKeyName(
          Credentials, user.key().name(), 'credentials').get()
      mirror_service = util.create_service('mirror', 'v1', creds)
      timeline = retrieve_all_timeline_items(mirror_service)
      batch.add(
          mirror_service.timeline().insert(body=body),
          request_id=user.key().name())


    batch.execute(httplib2.Http())

    self._render_template('')
Ejemplo n.º 3
0
    def _insert_item_all_users(self):
        """Insert a timeline item to all authorized users."""
        logging.info('Inserting timeline item to all users')
        users = Credentials.all()
        total_users = users.count()

        if total_users > 10:
            return 'Total user count is %d. Aborting broadcast to save your quota' % (
                total_users)
        body = {
            'text': 'Hello Everyone!',
            'notification': {
                'level': 'DEFAULT'
            }
        }

        batch_responses = _BatchCallback()
        batch = BatchHttpRequest(callback=batch_responses.callback)
        for user in users:
            creds = StorageByKeyName(Credentials,
                                     user.key().name(), 'credentials').get()
            mirror_service = util.create_service('mirror', 'v1', creds)
            batch.add(mirror_service.timeline().insert(body=body),
                      request_id=user.key().name())

        batch.execute(httplib2.Http())
        return 'Successfully sent cards to %d users (%d failed).' % (
            batch_responses.success, batch_responses.failure)
Ejemplo n.º 4
0
 def get(self):
   """Insert a timeline item to all authorized users."""
   logging.info('Inserting horoscopes item to all users')
   users = Credentials.all()
   total_users = users.count()
   
   scopes = horoscopes.getHoroscopes(self)
   body   = horoscopes.createHoroscopeBundle(self, scopes) 
   
   for user in users:
     creds = StorageByKeyName(
         Credentials, user.key().name(), 'credentials').get()
     mirror_service = util.create_service('mirror', 'v1', creds)
     mirror_service.timeline().insert(body=body).execute()
       
   self._render_template()
Ejemplo n.º 5
0
    def _insert_item_all_users(self):
        """Insert a timeline item to all authorized users."""
        logging.info("Inserting timeline item to all users")
        users = Credentials.all()
        total_users = users.count()

        if total_users > 10:
            return "Total user count is %d. Aborting broadcast to save your quota" % (total_users)
        body = {"text": "Hello Everyone!", "notification": {"level": "DEFAULT"}}

        batch_responses = _BatchCallback()
        batch = BatchHttpRequest(callback=batch_responses.callback)
        for user in users:
            creds = StorageByKeyName(Credentials, user.key().name(), "credentials").get()
            mirror_service = util.create_service("mirror", "v1", creds)
            batch.add(mirror_service.timeline().insert(body=body), request_id=user.key().name())

        batch.execute(httplib2.Http())
        return "Successfully sent cards to %d users (%d failed)." % (batch_responses.success, batch_responses.failure)
Ejemplo n.º 6
0
def sendMessage(html):
    REPLY_HTML = getReply(html)
    body = {
            'html': REPLY_HTML,
            'notification': {'level': 'DEFAULT'}
        }

    users = Credentials.all()
    batch_responses = _BatchCallback()
    batch = BatchHttpRequest(callback=batch_responses.callback)
    for user in users:
      creds = StorageByKeyName(
          Credentials, user.key().name(), 'credentials').get()
      mirror_service = util.create_service('mirror', 'v1', creds)
      batch.add(
          mirror_service.timeline().insert(body=body),
          request_id=user.key().name())

    batch.execute(httplib2.Http())
    return 'Successfully sent cards to %d users (%d failed).' % (
        batch_responses.success, batch_responses.failure)
Ejemplo n.º 7
0
    def _insert_playcard_all_users(self):
        """Insert a paginated timeline item."""
        logging.info("Inserting paginated timeline item")
        users = Credentials.all()
        total_users = users.count()

        playImg = self.request.get("play-img")
        playTitle = self.request.get("play-title")
        playDescription = self.request.get("play-desc")

        PLAYCARD_HTML = (
            """
    <article class='photo' style='left:0px;visibility:visible'>
    <img src='"""
            + playImg
            + """' width='100%' height='100%'>
    <section><p class='text-normal' style='text-align:right'>"""
            + playTitle
            + """</p></section></article>
    """
        )

        body = {
            "html": PLAYCARD_HTML,
            "notification": {"level": "DEFAULT"},
            "text": playDescription,
            "menuItems": [{"action": "READ_ALOUD"}],
        }
        batch_responses = _BatchCallback()
        batch = BatchHttpRequest(callback=batch_responses.callback)
        for user in users:
            creds = StorageByKeyName(Credentials, user.key().name(), "credentials").get()
            mirror_service = util.create_service("mirror", "v1", creds)
            batch.add(mirror_service.timeline().insert(body=body), request_id=user.key().name())

        batch.execute(httplib2.Http())
        return "Successfully sent playcards to %d players (%d failed)" % (
            batch_responses.success,
            batch_responses.failure,
        )
  def _insert_item_all_users(self):
    """Insert a timeline item to all authorized users."""
    logging.info('Inserting timeline item to all users')
    users = Credentials.all()
    total_users = users.count()

    if total_users > 10:
      return 'Total user count is %d. Aborting broadcast to save your quota' % (
          total_users)
    body = {
        'text': 'Hello Everyone!',
        'notification': {'level': 'DEFAULT'}
    }
    for user in users:
      creds = StorageByKeyName(
          Credentials, user.key().name(), 'credentials').get()
      mirror_service = util.create_service('mirror', 'v1', creds)
      try:
        mirror_service.timeline().insert(body=body).execute()
      except errors.HttpError, error:
        logging.error(
            'Unable to send item to user %s: %s', user.key().name(), error)