Beispiel #1
0
Datei: rss.py Projekt: Kagami/bnw
 def publish_extensions(self, handler):
     if self.selflink:
         PyRSS2Gen._element(handler, 'atom:link', None,
                            {'rel': 'self',
                             'type': 'application/rss+xml',
                             'href': self.selflink,
                             })
def create_feed(bezirk, outfile):

    drucksachen = extractor.run_extractor(bvvfeeds.extractors['drucksachen'],
                                          (bezirk))

    # replace empty date fields with current date
    date_current = datetime.datetime.today()
    for ds in drucksachen:
        if not ds['date']:
            ds['date'] = date_current
        else:
            ds['date'] = ds['date']

    drucksachen = sorted(drucksachen, key=lambda s: s['date'], reverse=True)

    feeditems = []
    for drucksache in drucksachen:
        title = drucksache['name']
        link = "http://www.berlin.de/ba-%s/bvv-online/vo020.asp?VOLFDNR=%s" % (
            bezirk, drucksache['id'])
        description = "Art: %s<br />Initiator: %s<br />Link: <a href=\"%s\">%s</a>" % (
            drucksache['type'], drucksache['initiator'], link, link)
        try:
            guid = PyRSS2Gen.Guid(link, isPermaLink=True)
            item = PyRSS2Gen.RSSItem(title=title,
                                     link=link,
                                     description=description,
                                     guid=guid,
                                     pubDate=drucksache['date'])
            feeditems.append(item)
        except Exception, e:
            print e
            print drucksache
            continue
 def publish(self, handler):
     if not self.data:
         return
     if self.d:
         PyRSS2Gen._element(handler, self.__class__.XMLTAG, self.data, self.d)
     else:
         PyRSS2Gen._element(handler, self.__class__.XMLTAG, self.data)
Beispiel #4
0
 def get(self, ids=None):
     is_ed2k = self.get_argument('type', 'magnet') == 'ed2k'
     tvshows = self.model.select()
     if ids:
         ids = ids.split(',')
         tvshows = tvshows.where(self.model.id << ids)
     items = []
     count = 0
     for tvshow in tvshows:
         for episode in tvshow.episodes:
             item = PyRSS2Gen.RSSItem(
                 title=episode.title,
                 link=episode.ed2k if is_ed2k else episode.magnet,
                 guid=PyRSS2Gen.Guid(episode.magnet),
                 pubDate=episode.updated)
             items.append(item)
         count = count + 1
     if count > 0:
         updated = tvshows[0].updated
     else:
         updated = datetime.utcnow()
     rss = PyRSS2Gen.RSS2(title='rss',
                          link='http://127.0.0.1:8000',
                          description='',
                          lastBuildDate=updated,
                          items=items)
     self.set_header("Content-Type", 'application/rss+xml; charset="utf-8"')
     self.write(rss.to_xml())
Beispiel #5
0
    def _gen_modified_feed(self):
        items = [
            PyRSS2Gen.RSSItem(title=x.title,
                              link=x.link,
                              description=x.summary,
                              guid=x.link,
                              pubDate=datetime.datetime(
                                  x.modified_parsed[0], x.modified_parsed[1],
                                  x.modified_parsed[2], x.modified_parsed[3],
                                  x.modified_parsed[4], x.modified_parsed[5]))
            for x in self.feed['entries']
        ]

        rss = PyRSS2Gen.RSS2(
            title=self.feed['feed'].get("title"),
            link=self.feed['feed'].get("link"),
            description=self.feed['feed'].get("description"),
            language=self.feed['feed'].get("language"),
            copyright=self.feed['feed'].get("copyright"),
            managingEditor=self.feed['feed'].get("managingEditor"),
            webMaster=self.feed['feed'].get("webMaster"),
            pubDate=self.feed['feed'].get("pubDate"),
            lastBuildDate=self.feed['feed'].get("lastBuildDate"),
            categories=self.feed['feed'].get("categories"),
            generator=self.feed['feed'].get("generator"),
            docs=self.feed['feed'].get("docs"),
            items=items)

        self.xml = rss.to_xml()
        return self.xml
def renderToRss(feed):
    """Render feedparser data to RSS, taken from
    https://stackoverflow.com/a/191899/884682"""
    def dateOf(x):
        data = x.modified_parsed if hasattr(x, 'modified_parsed') else \
               x.published_parsed
        return datetime.datetime(*(data[:6]))

    items = [
        PyRSS2Gen.RSSItem(title=x.title,
                          link=x.link,
                          description=x.summary,
                          guid=x.link,
                          pubDate=dateOf(x)) for x in feed.entries
    ]

    rss = PyRSS2Gen.RSS2(title=feed['feed'].get("title"),
                         link=feed['feed'].get("link"),
                         description=feed['feed'].get("description"),
                         language=feed['feed'].get("language"),
                         copyright=feed['feed'].get("copyright"),
                         managingEditor=feed['feed'].get("managingEditor"),
                         webMaster=feed['feed'].get("webMaster"),
                         pubDate=feed['feed'].get("pubDate"),
                         lastBuildDate=feed['feed'].get("lastBuildDate"),
                         categories=feed['feed'].get("categories"),
                         generator=feed['feed'].get("generator"),
                         docs=feed['feed'].get("docs"),
                         items=items)

    return rss.to_xml()
Beispiel #7
0
def generate_site(token):

    site = Site.select().where(Site.token == token).get()
    rss_title = get_template('rss_title_message').render(site=site.name)
    md = markdown.Markdown()

    items = []
    for row in (Comment.select().join(Site).where(
            Site.token == token,
            Comment.published).order_by(-Comment.published).limit(10)):
        item_link = '%s://%s%s' % (config.get(
            config.RSS_PROTO), site.url, row.url)
        items.append(
            PyRSS2Gen.RSSItem(
                title='%s - %s://%s%s' % (config.get(
                    config.RSS_PROTO), row.author_name, site.url, row.url),
                link=item_link,
                description=md.convert(row.content),
                guid=PyRSS2Gen.Guid('%s/%d' % (item_link, row.id)),
                pubDate=row.published,
            ))

    rss = PyRSS2Gen.RSS2(
        title=rss_title,
        link='%s://%s' % (config.get(config.RSS_PROTO), site.url),
        description='Commentaires du site "%s"' % site.name,
        lastBuildDate=datetime.now(),
        items=items,
    )
    rss.write_xml(open(config.get(config.RSS_FILE), 'w'), encoding='utf-8')
Beispiel #8
0
def rss():
    """ RSS2 Support.

        support xml for RSSItem with 12 diaries.

    Args:
        none
    Return:
        diaries_object: list
        site_settings: title, link, description
    """
    articles = Diary.objects.order_by('-publish_time')[:12]
    items = []
    for article in articles:
        content = article.html

        url = Config.SITE_URL + '/diary/' + str(article.pk) + '/' + \
            article.title
        items.append(
            PyRSS2Gen.RSSItem(
                title=article.title,
                link=url,
                description=content,
                guid=PyRSS2Gen.Guid(url),
                pubDate=article.publish_time,
            ))
    rss = PyRSS2Gen.RSS2(title=Config.MAIN_TITLE,
                         link=Config.SITE_URL,
                         description=Config.DESCRIPTION,
                         lastBuildDate=datetime.datetime.now(),
                         items=items).to_xml('utf-8')
    return rss
Beispiel #9
0
def get_rss(content):
    soup = BeautifulSoup(content).contents[0]
    myrss = PyRSS2Gen.RSS2(
        title='91ri',
        link='http://www.91ri.org/',
        atom_link='http://117.28.237.21:29956/ording/resource/91ri.xml',
        description=str(datetime.date.today()),
        # pubDate=datetime.datetime.now(),
        lastBuildDate=datetime.datetime.now(),
        language="zh-CN",
        items=[])
    for x in xrange(0, len(soup)):
        print soup.contents[x].find_all(
            attrs={"data-no-turbolink": "true"})[0].get('href')
        print soup.contents[x].find_all(
            attrs={"data-no-turbolink": "true"})[0].string
        # print soup.contents[x].p.string
        get_content(soup.contents[x].find_all(
            attrs={"data-no-turbolink": "true"})[0].get('href'))
        rss = PyRSS2Gen.RSSItem(
            title='<![CDATA[' + soup.contents[x].find_all(
                attrs={"data-no-turbolink": "true"})[0].string + ']]>',
            link=soup.contents[x].find_all(
                attrs={"data-no-turbolink": "true"})[0].get('href'),
            comments=soup.contents[x].find_all(
                attrs={"data-no-turbolink": "true"})[0].get('href') +
            "#comments",
            pubDate=datetime.datetime.now(),
            description=get_content(soup.contents[x].find_all(
                attrs={"data-no-turbolink": "true"})[0].get('href')))
        myrss.items.append(rss)
    return myrss
Beispiel #10
0
def generic_rss_renderer(lang, title, link, description, timeline,
                         output_path):
    """Takes all necessary data, and renders a RSS feed in output_path."""
    items = []
    for post in timeline[:10]:
        args = {
            'title': post.title(lang),
            'link': post.permalink(lang),
            'description': post.text(lang),
            'guid': post.permalink(lang),
            'pubDate': post.date,
        }
        items.append(rss.RSSItem(**args))
    rss_obj = rss.RSS2(
        title=title,
        link=link,
        description=description,
        lastBuildDate=datetime.datetime.now(),
        items=items,
        generator='nikola',
    )
    dst_dir = os.path.dirname(output_path)
    if not os.path.isdir(dst_dir):
        os.makedirs(dst_dir)
    with open(output_path, "wb+") as rss_file:
        rss_obj.write_xml(rss_file)
Beispiel #11
0
def create_rss(files):

    contents = to_html(files)
    titles = [re.search('<h1>(.*?)</h1>', c).groups()[0] for c in contents]

    dates = []
    for filename in files:
        try:
            dates.append(
                [int(z) for z in os.path.basename(filename).split('-')])
        except ValueError:
            pass
    dates = [datetime.datetime(*date) for date in dates]

    items = []
    for filename, title, desc, date in zip(files, titles, contents, dates):
        anchor = get_anchor(desc)
        items.append(
            PyRSS2Gen.RSSItem(
                title=title,
                link="http://puddletag.sourceforge.net/news.html#%s" % anchor,
                description=('\n'.join(desc.split('\n')[1:]).decode('utf8')),
                pubDate=date,
                author='concentricpuddle'))

    rss = PyRSS2Gen.RSS2(title="puddletag news feed",
                         link="http://puddletag.sourceforge.net",
                         description="The latest news about puddletag: "
                         "A tag-editor for GNU/Linux.",
                         lastBuildDate=datetime.datetime.now(),
                         docs=None,
                         items=items)

    return rss
Beispiel #12
0
def fetch():
    allheadlines = []

    newsurls = {
        'googlenews': 'https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss',
    }

    for key, url in newsurls.items():
        allheadlines.extend(getHeadlines(url))

    rss = PyRSS2Gen.RSS2(
        title='తెలుగులో నాసా ఇమేజ్ ఆఫ్ ది డే',
        link='https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss',
        description='తాజా నాసా ఇమేజ్ ఆఫ్ ది డే చిత్రం తెలుగులో',
        language='te-ind',
        items=[],
    )

    for hl in allheadlines:
        rss.items.append(
            PyRSS2Gen.RSSItem(
                title=hl[1],
                link=hl[0],
                description=hl[2],
                enclosure=PyRSS2Gen.Enclosure(url=hl[3],
                                              length=hl[4],
                                              type=hl[5]),
                pubDate=hl[6],
            ))

    # rss.write_xml(open("తెలుగులో నాసా ఇమేజ్ ఆఫ్ ది డే.xml", "w", encoding="utf-16"))
    soup = BeautifulSoup(rss.to_xml(encoding="utf-16"), 'lxml')
    return soup.prettify()
Beispiel #13
0
def index(name):
    resp, content = client.request(
        'http://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=%s'
        % name,
        method='GET',
    )

    feed = json.loads(content)

    link_tmpl = 'http://twitter.com/{user}/status/{id}'

    rss = PyRSS2Gen.RSS2(
        title='Twitter / {0}'.format(name),
        link='http://twitter.com/{0}'.format(feed[0]['user']['name']),
        description=feed[0]['user']['description'],
        lastBuildDate=datetime.datetime.now(),
        items=[
            PyRSS2Gen.RSSItem(
                title=item['text'],
                link=link_tmpl.format(user=name, id=item['id']),
                description=item['text'],
                guid=PyRSS2Gen.Guid(link_tmpl.format(user=name,
                                                     id=item['id'])),
                pubDate=datetime.datetime.strptime(
                    item['created_at'][:19] + item['created_at'][25:],
                    '%a %b %d %H:%M:%S %Y')) for item in feed
        ])

    response.content_type = 'application/rss+xml; charset=latin9'
    return rss.to_xml()
Beispiel #14
0
def generate_feed(min_weight=3):
    items = []
    q = db.Query(NewsChunks)
    for nc in q:

        # must be added for quality results!
        if nc.weight < min_weight:
            continue

        x = pickle.loads(nc.entry_data)
        items.append(
            PyRSS2Gen.RSSItem(title=x.title,
                              link=x.link,
                              description=x.summary,
                              guid=x.link,
                              pubDate=x.published))

    # feed generation!
    rss = PyRSS2Gen.RSS2(title="Foodtech News of This Week",
                         link="https://morning-scroll2.appspot.com/rss",
                         description="By Josh Cho",
                         language="en",
                         copyright="",
                         pubDate=datetime.now(),
                         lastBuildDate=datetime.now(),
                         categories="",
                         generator="",
                         docs="https://validator.w3.org/feed/docs/rss2.html",
                         items=items)

    return rss.to_xml(encoding="utf-8")
Beispiel #15
0
def get_entries(url, verify):
    content  = requests.get(url, verify=verify)
    soup = BeautifulSoup(content.text, "lxml")
    rows = soup.find_all("tr")
    entries = []
    if rows:
        # Apache
        for row in rows[3:-1]:
            if row.find_all("a")[0]['href'].endswith("/"):
                entries.extend(get_entries(url + ("" if url.endswith("/") else "/") + row.find_all("a")[0]['href'], verify))
            else:
                entries.append(PyRSS2Gen.RSSItem(
                    title = unquote(row.find_all("a")[0].text),
                    link = url + ("" if url.endswith("/") else "/") + row.find_all("a")[0]['href'],
                    guid = PyRSS2Gen.Guid(row.find_all("a")[0].text),
                    pubDate = datetime.datetime.strptime(row.find_all("td")[2].text.strip(), "%Y-%m-%d %H:%M")))
    else:
        # Nginx
        rows = soup.find_all("a")
        if rows[0]['href'] == "../":
            rows = rows[1:]
        for row in rows:
            if row['href'].endswith("/"):
                entries.extend(get_entries(url + ("" if url.endswith("/") else "/") + row['href'], verify))
            else:
                entries.append(PyRSS2Gen.RSSItem(
                    title = unquote(row['href']),
                    link = url + ("" if url.endswith("/") else "/") + row['href'],
                    guid = PyRSS2Gen.Guid(row.text),
                    pubDate = datetime.datetime.strptime(" ".join(row.next_sibling.strip(" ").split(" ")[0:2]), "%d-%b-%Y %H:%M")))
    return entries
Beispiel #16
0
def build_rss_feed(title, link, description, items, filename):
    """
    Generates a local XML file (RSS compliant)

    :param title: Title of the feed
    :param link: URL of the feed
    :param description: Description of the feed
    :param items: list of items to be included in the feed
    :param filename: output filename
    """
    rss_items = []

    for item in items:
        item_date = datetime.datetime.strptime(item['date'], '%Y-%m-%d')

        rss_item = PyRSS2Gen.RSSItem(
                title=item['title'],
                link=item['link'],
                description=item['description'],
                guid=PyRSS2Gen.Guid(item['link']),
                pubDate=item_date
        )

        rss_items.append(rss_item)

    rss = PyRSS2Gen.RSS2(
        title=title,
        link=link,
        description=description,
        lastBuildDate=datetime.datetime.now(),
        items=rss_items)

    rss.write_xml(open(filename, "w"))
Beispiel #17
0
    def buildRss(self):
        """Construct the RSS feed of the blog
        """
        last_post = self.posts_list[0]

        away, host, user, password, remote = self.readConf()
        rss_name = remote.replace('/', '')
        # decalage de temps
        delta_t = datetime.timedelta(hours=1)

        p_items = [PyRSS2Gen.RSSItem(
             title = post.title,
             link = away + post.url,
             description = post.html_content,
             pubDate = post.postdate-delta_t) \
             for post in self.posts_list]

        rss = PyRSS2Gen.RSS2(
            title="%s feed" % self.blog_dic_names["blog_name"],

            # added on 9 mars 2008
            language="fr",
            webMaster="*****@*****.**",
            pubDate=post.postdate - delta_t,
            generator="PyRSS2Gen",
            link=away + "index.html",
            description=last_post.html_content,  # le contenu
            lastBuildDate=datetime.datetime.now(),
            items=p_items)
        rss.write_xml(open(os.path.join(self._out, "flux.xml"), "w"))
Beispiel #18
0
def post2rss(baseurl, post, *, digest=False, pic=None):
    url = urljoin(baseurl, post['url'])
    if digest:
        content = post['excerpt'].strip()
    elif post.get('title_image'):
        content = '<p><img src="%s"></p>' % post['title_image'] + \
            post['content']
    else:
        content = post['content']

    if content:
        content = process_content(content)

        doc = fromstring(content)
        if pic:
            base.proxify_pic(doc, re_zhihu_img, pic)
        content = tostring(doc, encoding=str)
        content = content.replace('<div>', '')
        content = content.replace('</div>', '')

    item = PyRSS2Gen.RSSItem(
        title=post['title'].replace('\x08', ''),
        link=url,
        guid=PyRSS2Gen.Guid(url),
        description=cdata(content),
        pubDate=datetime.datetime.utcfromtimestamp(post['updated']),
        author=post['author']['name'],
    )
    return item
Beispiel #19
0
def blog_rss():
    if not env.owner or not env.owner.id:
        raise UserNotFound

    if env.owner.type == 'feed':
        raise Forbidden

    plist = posts.recent_blog_posts(env.owner, settings.page_limit, 0)

    feed = PyRSS2Gen.RSS2(title="%s@point" % env.owner.login,
                          link='http://%s.%s/' %
                          (env.owner.login, settings.domain),
                          description="Point.im user's blog")

    for p in plist:
        if 'comment_id' in p and p['comment_id']:
            title = '#%s/%s' % (p['post'].id, p['comment_id'])
            link = 'http://%s/%s#%s' % \
                    (settings.domain, p['post'].id, p['comment_id'])
        else:
            title = '#%s' % p['post'].id
            link = 'http://%s/%s' % (settings.domain, p['post'].id)

        feed.items.append(
            PyRSS2Gen.RSSItem(author=env.owner.login,
                              title=title,
                              link=link,
                              guid=link,
                              pubDate=p['post'].created,
                              categories=p['post'].tags,
                              description=render_string('/rss-text.html',
                                                        p=p)))

    return Response(feed.to_xml(), mimetype='application/rss+xml')
Beispiel #20
0
async def rss(request):
    engine = DatabaseContext.default.engine
    async with engine.acquire() as connection:
        topic_dao = TopicDAO(connection)
        topics = await topic_dao.latest100()

    rss = PyRSS2Gen.RSS2(
        title="DOIST",
        link="https://doist.cn/",
        description=u"实干家",
        lastBuildDate="",
        items=[
            PyRSS2Gen.RSSItem(
                title=topic['title'],
                link="https://doist.cn/t/%d" % (topic['id'], ),
                description=markdown.markdown(
                    bleach.clean(topic['content']),
                    extensions=['markdown.extensions.tables']),
                guid="https://doist.cn/t/%d" % (topic['id'], ),
                pubDate=topic['created_at'],
            ) for topic in topics
        ])
    response = web.StreamResponse(headers={'Content-Type': 'text/xml'})
    await response.prepare(request)
    buf = StringIO()
    rss.write_xml(buf, 'utf-8')

    await response.write(buf.getvalue().encode('utf-8'))

    return response
    def publish_extensions(self, handler):
        """Datacasting extensions to the RSSItem Publish functionality"""
        aST = self.acquisitionStartDate
        if isinstance(aST, datetime.datetime):
            aST = PyRSS2Gen.DateElement("datacasting:acquisitionStartDate", aST)
        PyRSS2Gen._opt_element(handler, "datacasting:acquisitionStartDate", aST)

        aET = self.acquisitionEndDate
        if isinstance(aET, datetime.datetime):
            aET = PyRSS2Gen.DateElement("datacasting:acquisitionEndDate", aET)
        PyRSS2Gen._opt_element(handler, "datacasting:acquisitionEndDate", aET)

        aD = self.acquisitionDuration
        if aD is not None:
            aD = FloatElement("datacasting:acquisitionDuration", aD)
        PyRSS2Gen._opt_element(handler, "datacasting:acquisitionDuration", aD)

        if self.extents is not None:
            self.extents.publish(handler)

        if type(self.enclosureList) is list:
            for enc in self.enclosureList:
                enc.publish(handler)

        if type(self.customElementList) is list:
            for cutomElt in self.customElementList:
                cutomElt.publish(handler)

        PyRSS2Gen._opt_element(handler, "datacasting:preview", self.preview)
        PyRSS2Gen._opt_element(handler, "datacasting:productName", self.productName)
Beispiel #22
0
def all_posts_rss():
    plist = posts.select_posts(private=False,
                               author_private=False,
                               deny_anonymous=False,
                               blacklist=True,
                               limit=settings.page_limit * 4)

    feed = PyRSS2Gen.RSS2(title="Point.im",
                          link='http://%s/' % (settings.domain),
                          description="Point.im")

    for p in plist:
        if 'comment_id' in p and p['comment_id']:
            title = '#%s/%s' % (p['post'].id, p['comment_id'])
            link = 'http://%s/%s#%s' % \
                    (settings.domain, p['post'].id, p['comment_id'])
        else:
            title = '#%s' % p['post'].id
            link = 'http://%s/%s' % (settings.domain, p['post'].id)

        feed.items.append(
            PyRSS2Gen.RSSItem(author=env.owner.login,
                              title=title,
                              link=link,
                              guid=link,
                              pubDate=p['post'].created,
                              categories=p['post'].tags,
                              description=render_string('/rss-text.html',
                                                        p=p)))

    return Response(feed.to_xml(), mimetype='application/rss+xml')
Beispiel #23
0
    def get(self, request):
        items = []
        blogs = Blog.objects.filter(page_type=Blog.BLOG).order_by('-pub_date')

        imageType = ContentType.objects.filter(
            type_name=ContentType.IMAGE_TYPE).first()
        for blog in blogs:
            img = blog.contents.filter(content_type_id=imageType.id).first()
            item = PyRSS2Gen.RSSItem(
                title=blog.blog_title,
                link=blog.guid,
                author="[email protected] (Maria)",
                pubDate=blog.pub_date,
                guid=PyRSS2Gen.Guid(blog.guid),
            )
            if img != None:
                item.enclosure = PyRSS2Gen.Enclosure(
                    url="http://designminted.com/get-img/{0}/".format(img.id),
                    length=len(img.content_data),
                    type=img.file_extension,
                )
            items.append(item)

        rss = MyRSS2.MyRSS2(
            title="Design Minted, LLC",
            link="http://designminted.com",
            description=
            "Maria from Design Minted, LLC's interior decorating blog",
            lastBuildDate=datetime.datetime.now(),
            items=items,
        )

        rss.rss_attrs['xmlns:atom'] = "http://www.w3.org/2005/Atom"

        return HttpResponse(rss.to_xml(), content_type="application/rss+xml")
Beispiel #24
0
    def get(self):

        query = blog.Post.all()
        query.order('-pub_date')
        posts = query.fetch(10)

        rss_items = []
        for post in posts:
            item = PyRSS2Gen.RSSItem(
                title=post.title,
                link="%s%s" %
                (config.SETTINGS['url'], post.get_absolute_url()),
                description=post.excerpt_html or post.body_html,
                guid=PyRSS2Gen.Guid(
                    "%s%s" %
                    (config.SETTINGS['url'], post.get_absolute_url())),
                pubDate=post.pub_date)
            rss_items.append(item)

        rss = PyRSS2Gen.RSS2(title=config.SETTINGS['title'],
                             link=config.SETTINGS['url'],
                             description=config.SETTINGS['description'],
                             lastBuildDate=datetime.datetime.now(),
                             items=rss_items)
        rss_xml = rss.to_xml()
        self.response.headers['Content-Type'] = 'application/rss+xml'
        self.response.out.write(rss_xml)
 def publish(self, handler):
     handler.startElement("georss:where", self.whereElement_attrs)
     handler.startElement("gml:Envelope", self.envelopeElement_attrs)
     PyRSS2Gen._element(handler, "gml:lowerCorner", ("%f %f" % (self.lcLat, self.lcLon)), self.lcElement_attrs)
     PyRSS2Gen._element(handler, "gml:upperCorner", ("%f %f" % (self.ucLat, self.ucLon)), self.ucElement_attrs)
     handler.endElement("gml:Envelope")
     handler.endElement("georss:where")
Beispiel #26
0
def row_to_rss_item(row):
    #lang_name, period_name, rank, date,
    #repo_name, description, readme_html, last_seen, first_seen
    item = dict()

    # Use \x23 instead of '#' if .format trips on it
    item['title'] = (
        '{0.repo_name} #{0.rank} in {0.lang_name}, {0.period_name}'.format(row)
    )
    item['link'] = 'https://github.com/{}'.format(row.repo_name)
    item['author'] = row.repo_name.split('/')[0]
    item['guid'] = PyRSS2Gen.Guid(item['link'], isPermaLink=False)

    #TODO categories? Language(s)? (that'd only be relevant for 'all'...)

    #SQLite stores dates as YYYY-MM-DD
    pub_date = datetime.strptime(row.date, '%Y-%m-%d')
    #offset pubdate by ranking so chronological order == ranking order
    item['pubDate'] = pub_date + timedelta(minutes=row.rank)

    row_descr = row.description or '[No description found.]'

    #TODO when more stable, include first/last seen?
    #descr = '<p><i>{}</i></p> <p>Last seen <b>{}</b>; First seen <b>{}</b></p>'.format(
    #        row_descr, row.last_seen, row.first_seen)
    descr = '<p><i>{}</i></p>'.format(row_descr)

    descr += row.readme_html or '<p>No README was found for this project.</p>'
    item['description'] = descr

    return PyRSS2Gen.RSSItem(**item)
Beispiel #27
0
    def generate(self):
        md = markdown.Markdown()

        items = []
        for row in (Comment.select().where(
                Comment.published).order_by(-Comment.published).limit(10)):
            item_link = "%s://%s%s" % (self._rss_proto, self._site_url,
                                       row.url)
            items.append(
                PyRSS2Gen.RSSItem(
                    title="%s - %s://%s%s" % (self._rss_proto, row.author_name,
                                              self._site_url, row.url),
                    link=item_link,
                    description=md.convert(row.content),
                    guid=PyRSS2Gen.Guid("%s/%d" % (item_link, row.id)),
                    pubDate=row.published,
                ))

        rss_title = 'Commentaires du site "%s"' % self._site_name
        rss = PyRSS2Gen.RSS2(
            title=rss_title,
            link="%s://%s" % (self._rss_proto, self._site_url),
            description=rss_title,
            lastBuildDate=datetime.now(),
            items=items,
        )
        rss.write_xml(open(self._rss_file, "w"), encoding="utf-8")
Beispiel #28
0
def buildFeed(entries,output):
    entries.sort(key = lambda t:t[3],reverse=True)
    items = []
    for e in entries:
        items.append(PyRSS2Gen.RSSItem(
             title = e[0],
             link = e[1],
             pubDate=e[3],
             enclosure = PyRSS2Gen.Enclosure(e[1],0, "video/mp4"),
             description = e[2]
             ))
    rss = PyRSS2Gen.RSS2(
        title='Daly News Dump',
        link='http://newspodcast.github.io/newspodcast/podcast.xml',
        description = 'Get your daly news!',
        lastBuildDate = datetime.datetime.now(),
        image=PyRSS2Gen.Image("http://icons.iconarchive.com/icons/pelfusion/long-shadow-ios7/1024/News-icon.png", "Logo", "http://icons.iconarchive.com/icons/pelfusion/long-shadow-ios7/1024/News-icon.png",
                            1024, 1024, "awsome logo"),
        pubDate = datetime.datetime.now(),
        items = items
    )
    rss.write_xml(open(output, "w"))
    f = open(output,"r")
    xml = xl.parse(f)
    result = xml.toprettyxml()
    f.close()
    with open(output,"wb") as f:
        f.write(result.encode("utf-8"))
Beispiel #29
0
def dict_to_rss(results, count, query):
    if not query:
        query = '*'
    docs = results

    items = [
        pyrss.RSSItem(title=str(doc.get('title')),
                      link=doc['id'].get('url'),
                      description=json.dumps(doc, indent=4, sort_keys=True),
                      guid='http://' + settings.URL + '/' +
                      doc.get('location')[0],
                      pubDate=str(doc.get('timestamp'))) for doc in docs
        if doc.get('location') is not None
    ]
    logger.info("{n} documents added to RSS feed".format(n=len(items)))
    rss = pyrss.RSS2(
        title='scrAPI: RSS feed for documents retrieved from query: "{query}"'.
        format(query=query),
        link='{base_url}/rss?q={query}'.format(base_url=settings.URL,
                                               query=query),
        items=items,
        description='{n} results, {m} most recent displayed in feed'.format(
            n=count, m=len(items)),
        lastBuildDate=str(datetime.datetime.now()),
    )

    f = StringIO()
    rss.write_xml(f)

    return f.getvalue()
Beispiel #30
0
	def publish_extensions(self, handler):
		"""
		Overrides RSSItem.publish_extension so that I can provide a 
		mcv:updated tag if needed.
		"""
		if self.version != None:
			RSS2._opt_element(handler, "mcv:version", self.version)
Beispiel #31
0
    def gen_rss(self):
        rss_item = []
        for news in self.info:
            # print(news)
            item = PyRSS2Gen.RSSItem(
                title=news['title'],
                link=news['url'],
                description=news['title'],
                pubDate=arrow.get(news['lastupdatetime']).format('YYYY-MM-DD'))
            rss_item.append(item)

        rss = PyRSS2Gen.RSS2(title="scurss feed",
                             link="http://scurss.les1ie.com",
                             description=" 四川大学校内新闻聚合平台",
                             lastBuildDate=datetime.datetime.now(),
                             items=rss_item)
        rss.write_xml(open("./web/feed.xml", "w"))
        # 修改格式
        f = open("./web/feed.xml", 'r')
        con = f.read()
        f.close()

        con = con.replace("iso-8859-1", 'utf-8')
        f = open('./web/feed.xml', 'w')
        f.write(con)
        f.close()
Beispiel #32
0
def rss(request):
    """Generate RSS feed."""

    items = []

    for prod in get_products(only_available=False):
        items.append(PyRSS2Gen.RSSItem(
            title=prod.name,
            link=prod.url,
            description="Current status:{}Available".format(
                " " if prod.availability else " NOT "
            )
        ))

    feed = PyRSS2Gen.RSS2(
        title="RPi0 Watch",
        link='http://rpi0.satanowski.net/rss',
        description="Current status of RPi0 availability",
        lastBuildDate=datetime.now(),
        generator='RPi0 Watch',
        docs='http://rpi0.satanowski.net/',
        items=items
    )
    return web.Response(
        body=feed.to_xml('utf-8').encode(),
        content_type='application/rss+xml'
    )
Beispiel #33
0
def generic_rss_renderer(lang, title, link, description, timeline, output_path,
                         rss_teasers):
    """Takes all necessary data, and renders a RSS feed in output_path."""
    items = []
    for post in timeline[:10]:
        args = {
            'title': post.title(lang),
            'link': post.permalink(lang, absolute=True),
            'description': post.text(lang, teaser_only=rss_teasers),
            'guid': post.permalink(lang, absolute=True),
            # PyRSS2Gen's pubDate is GMT time.
            'pubDate': (post.date if post.date.tzinfo is None else
                        post.date.astimezone(pytz.timezone('UTC'))),
            'categories': post._tags.get(lang, []),
        }
        items.append(rss.RSSItem(**args))
    rss_obj = rss.RSS2(
        title=title,
        link=link,
        description=description,
        lastBuildDate=datetime.datetime.now(),
        items=items,
        generator='nikola',
    )
    dst_dir = os.path.dirname(output_path)
    if not os.path.isdir(dst_dir):
        os.makedirs(dst_dir)
    with codecs.open(output_path, "wb+", "utf-8") as rss_file:
        data = rss_obj.to_xml(encoding='utf-8')
        if isinstance(data, bytes_str):
            data = data.decode('utf-8')
        rss_file.write(data)
Beispiel #34
0
def generate_rss(javascript, project=""):
    title = "OpenStack %s watch RSS feed" % (project)
    rss = PyRSS2Gen.RSS2(
        title=title,
        link="http://github.com/chmouel/openstackwatch.rss",
        description="The latest reviews about OpenStack, straight "
                    "from Gerrit.",
        lastBuildDate=datetime.datetime.now()
    )
    for row in parse_javascript(javascript):
        author = row['owner']['name']
        author += " <%s>" % ('email' in row['owner'] and
                             row['owner']['email']
                             or row['owner']['username'])
        rss.items.append(
            PyRSS2Gen.RSSItem(
                title="%s [%s]: %s" % (os.path.basename(row['project']),
                                       row['status'],
                                       row['subject']),
                author=author,
                link=row['url'],
                guid=PyRSS2Gen.Guid(row['id']),
                description=row['subject'],
                pubDate=datetime.datetime.fromtimestamp(row['lastUpdated']),
            ))
    return rss.to_xml()
Beispiel #35
0
def feed():
    sets = eol.get_photosets()
    feed_items = []
    for s in sets:
        name = str(s['num']) + " New Images From the ISS"
        link = "http://eol-browser.herokuapp.com/updates/" + s['id']
        desc = str(
            s['num']
        ) + " new images added to the EOL database, scrapped on " + s['datestr']
        date = datetime.datetime.strptime(s['id'], "%Y%m%d")
        item = PyRSS2Gen.RSSItem(name, link, desc, "EOL Browser", None, None,
                                 None, PyRSS2Gen.Guid(link), date)
        feed_items.append(item)

    rss = PyRSS2Gen.RSS2(title="Recent Images From the ISS",
                         link="http://eol-browser.herokuapp.com/",
                         description="The latest images of Earth from space",
                         lastBuildDate=datetime.datetime.now(),
                         items=feed_items)

    return Response(
        rss.to_xml(),
        mimetype=
        'application/rss+xml, application/rdf+xml, application/atom+xml, application/xml, text/xml'
    )
 def publish(self, handler):
     self.element_attrs = {"name": self.name}
     if isinstance(self.value, str):
         self.element_attrs["value"] = self.value
         PyRSS2Gen._element(handler, "datacasting:customElement", None, self.element_attrs)
     else:
         handler.startElement("datacasting:customElement", self.element_attrs)
         self.value.publish(handler)
         handler.endElement("datacasting:customElement")
Beispiel #37
0
 def publish_extensions(self, handler):
     # implement this method to embed the <itunes:*> elements
     # into the channel header.
     if self.duration is not None:
         PyRSS2Gen._opt_element(handler, "itunes:duration", self.duration)
     if self.image is not None and \
         isinstance(self.image, PyRSS2Gen.Image) and \
             self.image.url is not None:
         handler.startElement('itunes:image',  {'href': self.image.url})
         handler.endElement('itunes:image')
    def publish_extensions(self, handler):
        """Datacasting extensions to the RSS2 Publish functionality"""
        PyRSS2Gen._opt_element(handler, "datacasting:channelUID", self.channelUID)
        PyRSS2Gen._opt_element(handler, "datacasting:dataSource", self.dataSource)
        if type(self.customEltDefList) is list:
            for eltDef in self.customEltDefList:
                eltDef.publish(handler)

        if self.format is not None:
            self.format.publish(handler)
 def publish(self, handler):
     self.element_attrs = {"name": self.name, "type": self.type}
     if self.displayName is not None:
         self.element_attrs["displayName"] = self.displayName
     if self.units is not None:
         self.element_attrs["units"] = self.units
     if self.min is not None:
         self.element_attrs["min"] = self.min
     if self.max is not None:
         self.element_attrs["max"] = self.max
     PyRSS2Gen._element(handler, "datacasting:customEltDef", None, self.element_attrs)
 def publish(self, handler):
     handler.startElement("georss:where", self.whereElement_attrs)
     handler.startElement("gml:Polygon", self.polygonElement_attrs)
     handler.startElement("gml:exterior", self.exteriorElement_attrs)
     handler.startElement("gml:LinearRing", self.linearRingElement_attrs)
     PyRSS2Gen._element(
         handler,
         "gml:posList",
         (" ".join([("%f %f" % (x, y)) for (x, y) in self.listLatLonPairs])),
         self.posListElement_attrs,
     )
     handler.endElement("gml:LinearRing")
     handler.endElement("gml:exterior")
     handler.endElement("gml:Polygon")
     handler.endElement("georss:where")
Beispiel #41
0
def _convert_to_liberal(obj):
    if isinstance(obj, basestring):
        return obj
    elif isinstance(obj, int):
        return str(obj)
    elif isinstance(obj, datetime.datetime):
        return PyRSS2Gen._format_date(obj)
    else:
        d = {}
        for k, v in obj.__dict__.items():
            if v is None:
                continue
            if k == "element_attrs":
                d.update(v)
            elif k in ("categories", "days", "hours", "author",
                       "comments", "source"):
                # feedparser doesn't handle these
                continue
            elif k == "guid" and not isinstance(v, str):
                d[k] = v.guid
            else:
                if k == "pubDate":
                    k = "date"
                d[k] = _convert_to_liberal(v)
        return d
Beispiel #42
0
    def publish_extensions(self, handler):
        """Publish the Media RSS Feed elements as XML."""
        if isinstance(self.media_content, list):
            [PyRSS2Gen._opt_element(handler, "media:content", mc_element) for
             mc_element in self.media_content]
        else:
            PyRSS2Gen._opt_element(handler, "media:content",
                                   self.media_content)

        if hasattr(self, 'media_title'):
            PyRSS2Gen._opt_element(handler, "media:title", self.media_title)

        if hasattr(self, 'media_text'):
            PyRSS2Gen._opt_element(handler, "media:text", self.media_text)
 def publish_extensions(self, handler):
     # handler.startElement("content:encoded")
     # handler.endElement("content:encoded")
     PyRSS2Gen._opt_element(handler, "content:encoded", self.content)
 def publish(self, handler):
     PyRSS2Gen._element(handler, "media:thumbnail", None, {"url": self.url })
 def publish_extensions(self, handler):
     def characters(self, key, description):
         self._out.write('%s<![CDATA[\n %s \n]]>%s' % ("<%s>"%key, description, "</%s>"%key))
     characters(handler, "description", self.d1)
     PyRSS2Gen._opt_element(handler, "author", itunesAuthor(self.author))
     PyRSS2Gen._opt_element(handler, "subtitle", itunesSubtitle(self.subtitle))
     PyRSS2Gen._opt_element(handler, "summary", itunesSummary(self.summary))
     PyRSS2Gen._opt_element(handler, "keywords", itunesKeywords(self.keywords))
     PyRSS2Gen._opt_element(handler, "explicit", itunesExplicit(self.explicit))
     PyRSS2Gen._opt_element(handler, "duration", itunesDuration(self.duration))
 def publish_extensions(self, handler):
     def characters(self, key, description):
         self._out.write('%s<![CDATA[\n %s \n]]>%s' % ("<%s>"%key, description, "</%s>"%key))
     characters(handler, "description", self.d1)
     PyRSS2Gen._opt_element(handler, "media_thumbnail", media_thumbnail(self.media_thumbnail))
Beispiel #47
0
    def publish(self, handler):
        handler.startElement("rss", self.rss_attrs)
        handler.startElement("channel", self.element_attrs)
        PyRSS2Gen._element(handler, "title", self.title)
        PyRSS2Gen._element(handler, "link", self.link)
        PyRSS2Gen._element(handler, "description", self.description)

        self.publish_extensions(handler)

        PyRSS2Gen._opt_element(handler, "language", self.language)
        PyRSS2Gen._opt_element(handler, "copyright", self.copyright)
        PyRSS2Gen._opt_element(handler, "managingEditor", self.managingEditor)
        PyRSS2Gen._opt_element(handler, "webMaster", self.webMaster)

        pubDate = self.pubDate
        if isinstance(pubDate, datetime.datetime):
            pubDate = PyRSS2Gen.DateElement("pubDate", pubDate)
        PyRSS2Gen._opt_element(handler, "pubDate", pubDate)

        lastBuildDate = self.lastBuildDate
        if isinstance(lastBuildDate, datetime.datetime):
            lastBuildDate = PyRSS2Gen.DateElement(
                "lastBuildDate", lastBuildDate
            )
        PyRSS2Gen._opt_element(handler, "lastBuildDate", lastBuildDate)

        for category in self.categories:
            if isinstance(category, basestring):
                category = PyRSS2Gen.Category(category)
            category.publish(handler)

        PyRSS2Gen._opt_element(handler, "generator", self.generator)
        PyRSS2Gen._opt_element(handler, "docs", self.docs)

        handler.startElement(
            "atom:link",
            {
                "href": "http://destrock.com/rss",
                "rel": "self",
                "type": "application/rss+xml"
            }
        )
        handler.endElement("atom:link")

        if self.cloud is not None:
            self.cloud.publish(handler)

        ttl = self.ttl
        if isinstance(self.ttl, int):
            ttl = PyRSS2Gen.IntElement("ttl", ttl)
        PyRSS2Gen._opt_element(handler, "ttl", ttl)

        if self.image is not None:
            self.image.publish(handler)

        PyRSS2Gen._opt_element(handler, "rating", self.rating)
        if self.textInput is not None:
            self.textInput.publish(handler)
        if self.skipHours is not None:
            self.skipHours.publish(handler)
        if self.skipDays is not None:
            self.skipDays.publish(handler)

        for item in self.items:
            item.publish(handler)

        handler.endElement("channel")
        handler.endElement("rss")
 def publish(self, handler):
     handler.startElement("georss:where", self.whereElement_attrs)
     handler.startElement("gml:Point", self.pointElement_attrs)
     PyRSS2Gen._element(handler, "gml:pos", ("%f %f" % (self.lat, self.lon)), self.posElement_attrs)
     handler.endElement("gml:Point")
     handler.endElement("georss:where")
    def publish_extensions(self, handler):

        if self.selflink:
            PyRSS2Gen._element(
                handler, "atom:link", None, {"rel": "self", "type": "application/rss+xml", "href": self.selflink}
            )
 def publish_extensions(self, handler):
     PyRSS2Gen._element(handler, 'atom:link', None, {
         'href': LOCAL_URL_PREFIX + "feed/ckan.rss",
         'rel': 'self',
         'type': 'application/rss+xml'})
Beispiel #51
0
 def publish(self, handler):
     """Publish the MediaContent as XML."""
     PyRSS2Gen._element(handler, "media:content", None, self.element_attrs)
Beispiel #52
0
 def publish_extensions(self, handler):
     for p in GeoRSSItem.properties:
         value = getattr(self,p)
         if value is not None:
             PyRSS2Gen._element(handler,"georss:%s" % p, _seq_to_string(value))