当前位置: 首页>>代码示例>>Python>>正文


Python User.get_by_key_name方法代码示例

本文整理汇总了Python中user.User.get_by_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by_key_name方法的具体用法?Python User.get_by_key_name怎么用?Python User.get_by_key_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在user.User的用法示例。


在下文中一共展示了User.get_by_key_name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_last_session

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_by_key_name [as 别名]
 def get_last_session(cls, uid):
   cached_user = memcache.get(uid) or {}
   last_session_json = cached_user.get('last_session')
   if not last_session_json:
     user = User.get_by_key_name(uid)
     last_session = UserSession.all().filter('user =', user).order('-tune_in').get()
     if last_session:
       last_session_json = last_session.toJson()
       cached_user['last_session'] = last_session_json
       memcache.set(user.id, cached_user)
   return last_session_json
开发者ID:ebby,项目名称:brokentv,代码行数:13,代码来源:usersession.py

示例2: add

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_by_key_name [as 别名]
  def add(cls, media, user, text, acl, parent_id=None, to_user=None):
    from notification import Notification

    c = Comment(media=media, user=user, text=text)
    c.mentions = [x[0] for x in re.findall(r"@\[(\d+):([a-zA-z\s]+)\]", text)]

    if parent_id:
      c.parent_comment = Comment.get_by_id(int(parent_id))
      c.is_parent = False
    elif PRIVATE_COMMENTS:
      # ACL only needed on parent. Replies don't need ACLs.
      c.acl = acl
    c.put()

    media.comment_count += 1
    media.put()

    for m in c.mentions:
      if not to_user or (to_user and m != to_user.id):
        mentioned_user = User.get_by_key_name(m)
        if not mentioned_user or True:
          # Send them notification on FB
          fetch = urlfetch.fetch(url='https://graph.facebook.com/%s/notifications' % m,
                                 payload='access_token=%s&template=%s&href=%s' %
                                 (constants.facebook_app()['APP_ACCESS_TOKEN'],
                                 '@[' + user.id + ']' + ' mentioned you in a comment on ' + media.name + '!',
                                 media.get_path()),
                                 method=urlfetch.POST)
        else:
          n = Notification.add(mentioned_user, constants.NotificationType.MENTION, c)
          broadcast.broadcastNotification(n)

    if c.is_parent:
      from useractivity import UserActivity
      broadcast.broadcastNewActivity(UserActivity.add_comment(c.user, c))
    return c
开发者ID:ebby,项目名称:brokentv,代码行数:38,代码来源:comment.py

示例3: seen_by

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_by_key_name [as 别名]
 def seen_by(self, user):
   return [User.get_by_key_name(uid).toJson() for uid in self.seen if uid in user.friends]
开发者ID:ebby,项目名称:brokentv,代码行数:4,代码来源:media.py

示例4: fetch

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import get_by_key_name [as 别名]
  def fetch(self, collection=None, approve_all=False):
    all_medias = []

    if self.host == MediaHost.YOUTUBE:
      if not self.channel_id:
        yt_service = get_youtube_service()
        try:
          user_entry = yt_service.GetYouTubeUserEntry(username=self.host_id)
        except Exception as e:
          logging.error(e)
          return
        desc = user_entry.content.text
        desc = desc.decode('utf-8').replace("\n", r" ") if desc else None
        
        picture = urlfetch.fetch(user_entry.thumbnail.url)
        self.name = user_entry.title.text
        self.picture = db.Blob(picture.content)
        self.description = desc
        self.link = user_entry.link[0].href
        self.channel_id = re.search('/channel/(.*)', self.link).groups()[0]
        self.put()

      
      youtube3 = get_youtube3_service()
      
      
      publishedAfter = '1970-01-01T00:00:00Z'
      if constants.PUBLISHED_AFTER:
        publishedAfter = constants.PUBLISHED_AFTER
      elif self.last_fetch:
        publishedAfter = self.last_fetch.isoformat('T') + 'Z'
      
      ordering = ['date'] if self.last_fetch else ['date', 'rating', 'viewCount']
      
      for order in ordering:
        medias = []
        next_page_token = ''
        while next_page_token is not None:
          search_response = youtube3.search().list(
            channelId=self.channel_id,
            part='id',
            order=order,
            pageToken=next_page_token,
            publishedAfter=publishedAfter,
            maxResults=20
          ).execute()
          search_ids = ''
          for item in search_response.get('items', []):
            if item['id']['kind'] == 'youtube#video':
              search_ids += item['id']['videoId'] + ','
          videos_response = youtube3.videos().list(
            id=search_ids,
            part="id,snippet,topicDetails,contentDetails,statistics"
          ).execute()
          medias = Media.add_from_snippet(videos_response.get("items", []),
                                          collection=collection,
                                          publisher=self,
                                          enforce_category=len(collection.categories) > 0,
                                          approve=approve_all)
  
          all_medias += medias
          next_page_token = search_response.get('tokenPagination', {}).get('nextPageToken')

      self.last_fetch = datetime.datetime.now()
      self.put()
    if len(all_medias) and not approve_all:
      msg = emailer.Email(emailer.Message.FETCH, data={'count': len(medias)})
      for uid in constants.SUPER_ADMINS:
        user = User.get_by_key_name(uid)
        msg.send(user)
开发者ID:ebby,项目名称:brokentv,代码行数:72,代码来源:publisher.py


注:本文中的user.User.get_by_key_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。