def PrintEntryDetails(entry):
  rss = """
<item>
  <guid isPermaLink="false">youtube:{yt_id}</guid>
  <title>{title_text}</title> 
  <pubDate>{timestamp}</pubDate>
  <description>
    <iframe width="560"
            height="315"
            src="https://www.youtube.com/embed/{yt_id}?rel=0"
            frameborder="0"
            allowfullscreen="true">
    </iframe>
  <div>{desc}</div>
  </description>
</item>
"""
  yt_id     = parse_qs(urlparse(entry.media.player.url).query)['v'][0]
  timestamp = rfc822.timestamp_from_tf(
      rfc3339.tf_from_timestamp(entry.published.text)
  )
  return rss.format(
      yt_id       = yt_id,
      title_text  = entry.media.title.text,
      timestamp   = timestamp,
      desc        = entry.media.description.text
  )
Example #2
0
    def _seedTime(self):
        try:
            from feed.date import rfc3339
            from feed.date import rfc822
            import time

            now = time.time()
            self.config["time"] = now
            self.config["time_rfc3339"] = rfc3339.timestamp_from_tf(now)        
            self.config["time_rfc822"] = rfc822.timestamp_from_tf(now)        
        except:
            pass
Example #3
0
def PrintEntryDetails(entry):
  YT_ID = parse_qs(urlparse(entry.media.player.url).query)['v'][0]
  rss = ''
  rss+= '<item>'
  rss+= "<guid isPermaLink='false'>youtube:%s</guid>" % YT_ID
  rss+= '<title>%s</title>' % entry.media.title.text
  rss+= '<pubDate>%s</pubDate>' % rfc822.timestamp_from_tf(
      rfc3339.tf_from_timestamp(entry.published.text)
      )
  rss+= '<description><iframe width="560" height="315" src="https://www.youtube.com/embed/%(url)s?rel=0" frameborder="0" allowfullscreen="true" ></iframe><div>%(desc)s</div></description>' % {"url" : YT_ID, "desc" : entry.media.description.text}
  rss+= '</item>'
  return rss
Example #4
0
def PrintEntryDetails(entry):
    YT_ID = parse_qs(urlparse(entry.media.player.url).query)['v'][0]
    rss = ''
    rss += '<item>'
    rss += "<guid isPermaLink='false'>youtube:%s</guid>" % YT_ID
    rss += '<title>%s</title>' % entry.media.title.text
    rss += '<pubDate>%s</pubDate>' % rfc822.timestamp_from_tf(
        rfc3339.tf_from_timestamp(entry.published.text))
    rss += '<description><iframe width="560" height="315" src="https://www.youtube.com/embed/%(url)s?rel=0" frameborder="0" allowfullscreen="true" ></iframe><div>%(desc)s</div></description>' % {
        "url": YT_ID,
        "desc": entry.media.description.text
    }
    rss += '</item>'
    return rss
Example #5
0
 def __str__(self):
     if self.tf:
         return rfc822.timestamp_from_tf(self.tf, self.time_offset)
     return ""
Example #6
0
 def __str__(self):
     if self.tf:
         return rfc822.timestamp_from_tf(self.tf, self.time_offset)
     return ""
Example #7
0
    def get(self, mc, db, pkey):
        def check_encoding(string):
            data = string
            if string is not unicode:
                data = unicode(string)

            return ud.normalize('NFKD', data).encode('ascii', 'xmlcharrefreplace')

        h = HTMLParser.HTMLParser()
        try:
            # host URL
            urlparts = request.urlparts
            host_url = '%s://%s/feeds/%s' % (urlparts.scheme, urlparts.netloc, pkey)

            # get feed data
            cfg = self._app.config
            obj = FeedService.get_feed_activities(db, mc, cfg, pkey)
            activities = obj['activities']
            user_id = obj['user_id']

            # namespaces
            xmldoc, channel = new_xmldoc_echannel()
            xmldoc.root_element.attrs['xmlns:media'] = 'http://search.yahoo.com/mrss/'
            xmldoc.root_element.attrs['xmlns:atom'] = 'http://www.w3.org/2005/Atom'
            xmldoc.root_element.attrs['xmlns:geo'] = 'http://www.w3.org/2003/01/geo/wgs84_pos#'

            # compose items
            channel.title = 'Plus Channel feed'
            channel.description = 'Google+ List of Activities for %s' % obj['name']
            channel.generator = 'Plus Channel %s' % cfg.get('main.version')
            channel.link = 'http://plus.google.com/' + user_id
            channel.docs.text = ''
            channel.atom_link = AtomLink(host_url)
            if 'photo_url' in obj and obj['photo_url'] is not None:
                channel.image = Image(
                    url=obj['photo_url'],
                    title='Plus Channel feed',
                    link='http://plus.google.com/' + user_id,
                    width=cfg.get('feed.photo_size.database'),
                    height=cfg.get('feed.photo_size.database'))
            for activity in activities:

                title = activity['title']
                content = activity['content']
                url = activity['url']

                # check content
                if content is None or content == title:
                    content = ''

                # check title
                if title is None:
                    title = 'notitle'

                # reformat strings
                title = h.unescape(title)
                title = re.sub('<[^>]*>', '', title)
                title = escape(title)
                content = h.unescape(content)
                content = re.sub('<[^>]*>', '', content)
                content = escape(content)

                # log activity
                logging.debug('--- activity ---')
                logging.debug(title)
                logging.debug(content)
                logging.debug(url)
                logging.debug('----------------')

                # create item
                item = Item()
                item.title = check_encoding(title)
                updated = tf_from_timestamp(activity['datePublished'])
                updated = timestamp_from_tf(updated)
                item.pubDate = TextElement('pubDate', updated)

                # process content
                c_content = CDATA()
                c_content.text = check_encoding(content)
                item.description = str(c_content)

                # check image presence
                if 'imageUrl' in activity and activity['imageUrl'] != '':
                    image = TextElement('media:thumbnail')
                    image.attrs['url'] = activity['imageUrl']

                    # check size
                    if 'imageWidth' in activity and 'imageHeight' in activity:
                        image.attrs['width'] = activity['imageWidth']
                        image.attrs['height'] = activity['imageHeight']

                    item.thumbnail = image

                # check coordinates
                if activity['hasCoordinates']:
                    item.lat = TextElement('geo:lat', activity['latitude'])
                    item.long = TextElement('geo:long', activity['longitude'])

                # check link
                if url is None or url == '':
                    url = activity['url']
                item.link = escape(url)
                item.guid = escape(activity['id'])
                item.guid.attrs['isPermaLink'] = 'false'

                channel.items.append(item)

            # return created feed
            response.set_header('content-type', 'application/rss+xml; charset=utf-8')
            return unicode(xmldoc)

        except FeedService.FeedNotFoundException:
            abort(404)

        except FeedService.UserIdNotFoundException:
            abort(410)