Exemplo n.º 1
0
    def __init__(
            self,
            title=None,  # string
            link=None,  # url as string
            description=None,  # string
            author=None,  # email address as string
            categories=None,  # list of string or Category
            comments=None,  # url as string
            enclosure=None,  # an Enclosure
            guid=None,  # a unique string
            pubDate=None,  # a datetime
            source=None,  # a Source
            icon_url=None,  # an icon to display
    ):

        if guid is not None:
            guid = Guid(guid)

        # Initialise base class ..
        RSSItem.__init__(self, title, link, description, author, categories,
                         comments, enclosure, guid, pubDate, source)

        # Add media name space (for item icons)
        self.icon = None
        if icon_url is not None:
            self.icon = MediaContentImage(icon_url)
Exemplo n.º 2
0
def posts_feed():
    base_url = url_for('general.index', _external=True)
    items = []
    posts = Post.get_published(num=10).all()

    for post in posts:
        post_url = urljoin(base_url, post.url)

        # TODO: Add a real description
        item = RSSItem(title=post.title,
                       link=post_url,
                       description=post.body.split('\r\n', 1)[0],
                       author='{} ({})'.format(post.author.email,
                                               post.author.full_name),
                       categories=[tag.name for tag in post.tags],
                       guid=Guid(post_url),
                       pubDate=post.pub_date)
        items.append(item)

    feed_config = current_app.config['BLOG_POSTS_FEED']
    rss2_feed = RSS2(title=feed_config['title'],
                     link=base_url,
                     description=feed_config['description'],
                     language='en-us',
                     webMaster=feed_config['webmaster'],
                     lastBuildDate=posts[0].pub_date if posts else None,
                     ttl=1440,
                     items=items)
    return current_app.response_class(rss2_feed.to_xml(encoding='utf-8'),
                                      mimetype='application/rss+xml')
Exemplo n.º 3
0
    def toRSSItem(self):
        title = self.repo.tagname

        if self.message and len(self.message) > 50:
            title += " - " + str(Markup.escape(self.message[:50])) + "..."
        elif self.message:
            title += " - " + str(Markup.escape(self.message))

        if self.dbkeywords: title += " - " + ",".join(self.dbkeywords)

        description = "<pre>"
        description += str(self.getpprint(True))
        description += "</pre>"

        if type(title) != unicode:
            title = unicode(title, 'utf-8')
        if type(description) != unicode:
            description = unicode(description, 'utf-8')
        title = unicodedata.normalize('NFKD', title).encode('ascii', 'ignore')
        description = unicodedata.normalize('NFKD', description).encode(
            'ascii', 'ignore')

        guid = Config.rooturl + "/commit/" + self.repo.tagname + "/" + self.uniqueid
        link = ''
        if self.repo.viewlink:
            link = self.repo.viewlink.replace('%ID', self.uniqueid)
        else:
            link = guid

        item = RSSItem(title=title,
                       link=link,
                       description=description,
                       guid=Guid(guid, isPermaLink=0),
                       pubDate=unixToDatetime(self.date))
        return item
Exemplo n.º 4
0
    def event_to_rssitem(self, event):
        """Function converting an event (Python dict) to an RSSItem object."""

        title = (CrabStatus.get_name(event['status']) + ': ' +
                    event['user'] + ' @ ' + event['host'])
        if event['command'] is not None:
            title += ': ' + event['command']
        link = self.base + '/job/' + str(event['id'])
        if event['finishid'] is not None:
            link += '/output/' + str(event['finishid'])
        output = ''
        if event['stdout']:
            output += event['stdout']
        if event['stderr']:
            if event['stdout']:
                output += '\n\nStandard Error:\n\n'
            output += event['stderr']

        date = self.store.parse_datetime(event['datetime'])

        guid = ':'.join(['crab', self.fqdn, str(event['id']),
               str(calendar.timegm(date.timetuple())), str(event['status'])])

        info = {}

        if output != '':
            info['description'] = '<pre>' + output + '</pre>'

        return RSSItem(title=title,
                       link=link,
                       pubDate=date,
                       guid=Guid(guid, isPermaLink = False),
                       **info)
Exemplo n.º 5
0
 def rss(self,language=None,*args,**kwargs):
     if language:
         l = models.get_language(language)
     conf = cherrypy.request.app.config['ligiloj']
     query = models.Link().select(models.Link,models.Language).join(models.Language)
     if language:
         query = query.where(models.Link.language == l)
     cherrypy.response.headers['Content-Type'] = 'application/xml'
     return RSS2(title=u'{0} - {1}'.format(conf['site_title'],language and l.name or conf['global_title_text']),
         link=conf['rss_site_url'],
         description=conf['rss_description'],
         language=language or conf['rss_default_language'],
         items=[RSSItem(title=language and link.title or u"{0}: {1}".format(link.language.name,link.title),
             link=link.url,
             pubDate=link.published.isoformat(),
             guid=Guid(link.url,str(link.id))) for link in query]).to_xml('utf-8')
Exemplo n.º 6
0
 def generate_rss(self):
     if 'rss_title' not in self.config or 'rss_description' not in self.config:
         return
     RSS2(title=self.config['rss_title'],
          link=self.root_url,
          description=self.config['rss_description'],
          lastBuildDate=datetime.datetime.now(),
          items=[
              RSSItem(title=entry['title'],
                      link=self.root_url + entry['link'],
                      description=entry['html'],
                      guid=Guid(self.root_url + entry['link']),
                      pubDate=datetime.datetime.strptime(
                          entry['date'][:10], '%Y-%m-%d'))
              for entry in self.entries
          ]).write_xml(file(self.out + 'feed.xml', 'wb'), encoding='utf-8')
Exemplo n.º 7
0
def read_rss():
    rss = []
    count = 0
    while exists(RSS_FILE + str(count)):
        with open(RSS_FILE + str(count)) as source:
            title = source.readline()
            url = source.readline()
            date = eval(source.readline())
            description = ''.join(source.readlines())
            rss.append(
                RSSItem(title=title,
                        link=BASE_URL + url,
                        description=description,
                        guid=Guid(url),
                        pubDate=datetime(*date[0:5])))
        count = count + 1
    return rss
Exemplo n.º 8
0
    def pushRSSItem(self, item):
        """Adds an RSS Item to the top of an RSS feed. If the
        resulting feed is longer than the maximum number of items, and
        some of those items were put on the feed in previous runs, the
        earliest such item will be shifted off the feed."""
        if not getattr(item, 'guid') and item.link:
            item.guid = Guid(item.link)
        if not getattr(item, 'pubDate'):
            item.pubDate = self.lastBuildDate

        #Stringify data from external sources (eg. Beautiful Soup) to
        #avoid complications with pickling.
        for field in ('title', 'link', 'description', 'author', 'category',
                      'comments', ' source'):
            s = getattr(item, field, None)
            if s:
                setattr(item, field, str(s))

        if self.hasSeen(item.guid):
            #print "Checking for newer version of %s", item.guid.guid
            #This item is already in this feed. Replace it with the possibly
            #new version.
            for i in range(0, len(self.items)):
                check = self.items[i]
                if check.guid.guid == item.guid.guid:
                    #print "Updating possibly old version of %s" % item.guid.guid
                    self.items[i] = item
                    break
        else:
            #We haven't seen this item before, so the new one can go in.
            #print "Inserting ", item.guid.guid
            self.items.insert(0, item)
            self.currentGuids[item.guid.guid] = self.lastBuildDate
        while len(self.items) > self.maxItems \
            and self.currentGuids.get(self.items[-1].guid.guid) != self.lastBuildDate:
            #There are too many items in the feed, and the oldest one
            #was inserted in a previous update, so we can get rid of
            #it.
            #print "%s pushed off the edge!" % self.items[-1].guid.guid
            old = self.items.pop(-1)
            del (self.currentGuids[old.guid.guid])
Exemplo n.º 9
0
def menu():
	resource = urllib2.urlopen("http://www.ufrgs.br/ufrgs/ru")
	page = BeautifulSoup(resource)
	items = []
	for ru in page.find_all("div", "ru"):
		ru_name = ru.h3.contents[0]
		desc = ', '.join([(item or '').strip() for item in ru.div.contents if not hasattr(item, 'contents')])
		items.append(RSSItem(
			title = '%s - %s' % (ru_name, date.today().strftime('%d/%m/%Y')),
			link='http://www.ufrgs.br/ufrgs/ru',
			description=desc,
			guid=Guid(ru_name+date.today().isoformat()),
		))
	feed = RSS2(
		title=u"Cardápio do RU-UFRGS - diário",
		link='http://www.ufrgs.br/ufrgs/ru',
		description=u"Cardápio do dia no Restaurante Universitário da UFRGS",
		pubDate=datetime.today(),
		items=items,
	)
	return feed.to_xml()
Exemplo n.º 10
0
    def HTML2RSS(self, headers, body):
        soup = BeautifulSoup(body, 'html.parser')
        items = []
        for item in soup.find_all("tr", "titlebg2"):
            a = item.find_all("a")[-1]
            #topic_details = item.find("div", "topic_details")
            #author = topic_details.find("strong").a.text
            #a = topic_details.find("h5").find_all("a")[1]
            link = a['href']
            subject = a.text

            if 'ICO' not in subject:
                continue
            logging.info(subject)

            rss = RSSItem(author='x',
                          title=subject,
                          link=link,
                          pubDate='',
                          guid=Guid(link),
                          description='')
            items.append(rss)
        self.addRSSItems(items)
def get_guid(site, workshop):
    '''
    Create non-permalink Guid consisting of Software Carpentry
    site URL and workshop identifier ('slug').
    '''
    return Guid('{0}/{1}'.format(site, workshop['slug']), isPermaLink=False)
Exemplo n.º 12
0
            guid = link
        if "rel" in a.attrib:
            author = a.text # NOT COMPLIANT

    description = work.xpath(".//blockquote[@class='userstuff summary']")[0].text_content().strip()
    category = work.xpath(".//a[@class='tag']")[0].text
    try:
        comments = urljoin(BASE_URL, work.xpath(".//dd[@class='comments']/a/@href")[0])
    except Exception:
        comments = None
    pubDate = dateparser.parse(work.xpath(".//p[@class='datetime']")[0].text)
    item = RSSItem(
            title = title,
            link = link,
            description = description,
            guid = Guid(guid),
            pubDate = pubDate,
            comments = comments)
    items.append(item)
    print (title, link, author, description, category,comments, pubDate)
    item = None
    link = None
    description = None
    guid = None
    pubDate = None
    comments = None



rss = RSS2(
        title = "AO3 works of {}".format(USER),