def get(self):
		client = utils.makeFoursquareClient()
		
		content_id = self.request.get('content_id')
		if content_id:
			content_info = ContentInfo.all().filter('content_id=', content_id).get()
			if not content_info:
				self.error(404)
				return
			return self.appGet(client)
    def get(self):
        client = utils.makeFoursquareClient()

        content_id = self.request.get('content_id')
        if content_id:
            content_info = ContentInfo.all().filter('content_id =',
                                                    content_id).get()
            if not content_info:
                self.error(404)
                return
            return self.contentGet(client, content_info)

        return self.appGet(client)
Exemple #3
0
  def getCoreCheckin(self, checkinId, client):
    checkinCacheValue = memcache.get('checkin:%s' % checkinId)
    if checkinCacheValue is not None:
      return checkinCacheValue
    else:
      contentInfo = ContentInfo.get_checkin_reply(checkinId)
      content_json = {}
      if contentInfo is not None:
        content_json = json.loads(contentInfo.content)

      coreCheckin = {}
      if (content_json is not None and 'coreCheckin' in content_json):
        coreCheckin = content_json['coreCheckin']
      else:
        coreCheckin = self.checkinToCore(client.checkins(checkinId)['checkin'])

      # Cache checkin for 1 hour
      if not memcache.set('checkin:%s' % checkinId, coreCheckin, 3600):
        logging.error('Memcache set failed on checkin %s' % checkinId)

      return coreCheckin
    def get_content_for_date(self,
                             date: datetime.date) -> Iterable[ContentInfo]:
        date_string = date.strftime("%Y-%m-%d")
        params = {
            "expand": ["content.version.number", "content.metadata.mediatype"],
            "includeArchivedSpaces":
            True,
            "cql":
            f"lastModified={date_string} or created={date_string} order by lastModified,created asc"
        }

        for r in self._client.paginated_get("search", params):
            content = r.get("content")
            result_global_container = r.get("resultGlobalContainer")
            if not content or not result_global_container:
                continue

            space = SpaceInfo(
                result_global_container["displayUrl"].split("/")[-1],
                result_global_container["title"])
            content_id = content["id"]
            latest_version = content["version"]["number"]
            title = ConfluenceRepository._extract_title(r)

            mime_type = None
            if content["type"] == "attachment":
                mime_type = ConfluenceRepository._extract_mime_type(r, title)
                if not mime_type.startswith(
                        "text/"
                ) and mime_type not in self.supported_attachment_types:
                    if not mime_type.startswith("image/"):
                        logging.warning(
                            f"Content type {mime_type} not supported. Skipping attachment {title}"
                        )
                    continue

            yield ContentInfo(content_id, content["type"], latest_version,
                              title, space, mime_type)
Exemple #5
0
  def makeContentInfo(self,
                      checkin_json,
                      content,
                      url=None,
                      text=None, photoId=None,
                      reply=False, post=False):
    assert (reply ^ post), "Must pass exactly one of reply or post"
    assert (text or photoId)

    # Avoid posting duplicate content.
    request = ContentInfo.all()
    request = request.filter('checkin_id = ', checkin_json['id'])
    existing_contents = request.fetch(10)
    for existing_content in existing_contents:
      # Check that they're the same type of content
      if existing_content.reply_id and not reply:
        continue
      if existing_content.post_id and not post:
        continue
      # Check if the content payload is the same
      if existing_content.content == content:
        logging.info('Avoided posting duplicate content %s' % content)
        return existing_content

    content_id = utils.generateId()
    checkin_id = checkin_json['id']

    content_info = ContentInfo()
    content_info.content_id = content_id
    content_info.fs_id = checkin_json['user']['id']
    content_info.checkin_id = checkin_id
    content_info.venue_id = checkin_json['venue']['id']
    content_info.content = content

    access_token = self.fetchAccessToken(content_info.fs_id)
    client = utils.makeFoursquareClient(access_token)

    if not url:
      params = {}
    else:
      params = {'contentId' : content_id,
                'url' : url}

    if text:
      params['text'] = text.encode('utf-8')
    if photoId:
      params['photoId'] = photoId

    logging.info('creating content with params=%s' % params)

    if post:
      if CONFIG['local_dev']:
        content_info.post_id = utils.generateId()
      else:
        response_json = client.checkins.addpost(checkin_id, params)
        content_info.post_id = response_json['post']['id']
    elif reply:
      if CONFIG['local_dev']:
        content_info.reply_id = utils.generateId()
      else:
        response_json = client.checkins.reply(checkin_id, params)
        reply_id = None
        if 'replies' in response_json:
          reply_id = response_json['replies']['id']
        elif 'reply' in response_json:
          # Right now we return "replies" but we should probably return "reply"
          # adding this so I don't have to do it later in the event we rename
          reply_id = response_json['reply']['id']
        else:
          logging.error("Could not find reply id in /checkins/reply response: %s" % response_json)

        content_info.reply_id = reply_id

    content_info.put()

    return content_info
 def fetchContentInfo(self, content_id):
     request = ContentInfo.all().filter("content_id = ", content_id)
     return request.get()
    def makeContentInfo(self,
                        checkin_json,
                        content,
                        url=None,
                        text=None,
                        photoId=None,
                        reply=False,
                        post=False):
        assert (reply ^ post), "Must pass exactly one of reply or post"
        assert (text or photoId)

        # Avoid posting duplicate content.
        request = ContentInfo.all()
        request = request.filter('checkin_id = ', checkin_json['id'])
        existing_contents = request.fetch(10)
        for existing_content in existing_contents:
            # Check that they're the same type of content
            if existing_content.reply_id and not reply:
                continue
            if existing_content.post_id and not post:
                continue
            # Check if the content payload is the same
            if existing_content.content == content:
                logging.info('Avoided posting duplicate content %s' % content)
                return existing_content

        content_id = utils.generateId()
        checkin_id = checkin_json['id']

        content_info = ContentInfo()
        content_info.content_id = content_id
        content_info.fs_id = checkin_json['user']['id']
        content_info.checkin_id = checkin_id
        content_info.venue_id = checkin_json['venue']['id']
        content_info.content = content
        if not url:
            url = self.generateContentUrl(content_id)

        access_token = self.fetchAccessToken(content_info.fs_id)
        client = utils.makeFoursquareClient(access_token)

        params = {'contentId': content_id, 'url': url}
        if text:
            params['text'] = text
        if photoId:
            params['photoId'] = photoId

        logging.info('creating content with params=%s' % params)

        if post:
            if CONFIG['local_dev']:
                content_info.post_id = utils.generateId()
            else:
                response_json = client.checkins.addpost(checkin_id, params)
                content_info.post_id = response_json['post']['id']
        elif reply:
            if CONFIG['local_dev']:
                content_info.reply_id = utils.generateId()
            else:
                response_json = client.checkins.reply(checkin_id, params)
                reply_id = None
                if 'replies' in response_json:
                    reply_id = response_json['replies']['id']
                elif 'reply' in response_json:
                    # Right now we return "replies" but we should probably return "reply"
                    # adding this so I don't have to do it later in the event we rename
                    reply_id = response_json['reply']['id']
                else:
                    logging.error(
                        "Could not find reply id in /checkins/reply response: %s"
                        % response_json)

                content_info.reply_id = reply_id

        content_info.put()

        return content_info
 def fetchContentInfo(self, content_id):
     request = ContentInfo.all().filter("content_id = ", content_id)
     return request.get()