Beispiel #1
0
    def feedbuild(self, title, link, desc, pubdate, entries):
        fg = FeedGenerator()
        fg.docs(docs='')
        fg.generator(generator='', version=None, uri=None)
        fg.title(title)
        fg.link(href=link, replace=False)
        fg.description(desc)
        fg.lastBuildDate(lastBuildDate=currenttime())

        for entrie in reversed(entries):
            fe = fg.add_entry()
            fe.link(
                {
                    "href": unquote_plus(entrie[0]),
                    "rel": "alternate",
                    "type": None,
                    "hreflang": "en",
                    "title": entrie[1],
                    "length": 0,
                },
                replace=False)
            fe.title(entrie[1])
            fe.guid(guid=entrie[2], permalink=True)
            fe.category({"term": entrie[3], "scheme": None}, replace=False)
            fe.description(unquote_plus(entrie[4]))
            fe.pubDate(entrie[5])
        return fg.rss_str(pretty=True)
Beispiel #2
0
    def out_rss(self,filename):
	fg=FeedGenerator()
	fg.register_extension('albopop',AlbopopExtension,AlbopopEntryExtension)
	fg.id(self.url)
	fg.title(self.title)
	fg.description(self.title)
	fg.author({'name':'alboPOP','email':''})
	fg.link(href=self.url)
	fg.pubDate(formatdate())
	fg.webMaster(self.webMaster)
	fg.docs('https://github.com/mfortini/alboPOP_saga')
	fg.language('it')

	fg.albopop.categoryName(self.categoryName)
	fg.albopop.categoryType(self.categoryType)

	for item in self.items:
		fe=fg.add_entry()
		fe.id(item['link'])
		fe.category(term=item['tipo'])
		fe.pubdate(item['pubDate'])
		fe.link(href=item['link'])
		fe.title(item['title'])
		fe.description(item['description'])
		fe.albopop.categoryUID(str(item['numero'])+'/'+str(item['anno']))

	fg.rss_file(filename)
Beispiel #3
0
class YoutubeFeed:  
    ydl_opts = {
        'format': 'bestaudio/best',
        'outtmpl': '%(id)s.%(ext)s',
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        }]
    }

    def __init__(self, name):
        self.name = name
        self.ydl = youtube_dl.YoutubeDL(self.ydl_opts)

        self.fg = FeedGenerator()
        self.fg.title(name)
        self.fg.author({"name": "Youtube Audio Feed", "email": ""})
        self.fg.link(href="http://www.foo.bar.baz.com", rel="alternate")
        self.fg.description("Personalized Youtube audio feed")
        self.fg.generator("")
        self.fg.docs("")

    def add_video(self, url):
        info = self.ydl.extract_info(url, download=True)
        entry = self.fg.add_entry()
        entry.id(info['id'])
        entry.title(info['title'])
        entry.description(info['description'])
        entry.enclosure(info['id'] + ".mp3", str(info['duration']), 'audio/mpeg')

    def save(self):
        self.fg.rss_file(name + '.xml')
Beispiel #4
0
def main():
    fg = FeedGenerator()
    fg.id(ID_URL)
    fg.title("New/Updated flake8 Plugins")
    fg.author({"name": "Brian Skinn", "email": "*****@*****.**"})
    fg.link(
        href="https://github.com/bskinn/flake8-bot/raw/master/feed/feed.rss",
        rel="self")
    fg.link(href="https://github.com/bskinn/flake8-bot", rel="alternate")
    fg.logo(
        "https://github.com/bskinn/flake8-bot/raw/master/_static/f8_logo.jpg")
    fg.language("en")
    fg.description("Daily feed of new/updated flake8 plugins")
    fg.docs("http://www.rssboard.org/rss-specification")

    data = load_rss_json()

    for item in data:
        fe = fg.add_entry()
        fe.id(ID_URL + "-".join(("", str(item["timestamp"]), item["pkg"])))
        fe.title(
            f"{item['status'].title()}: {item['pkg']} ({item['version']})")
        fe.link({
            "href": f"https://pypi.org/project/{item['pkg']}",
            "rel": "alternate"
        })
        fe.author(fg.author())
        fe.content(item["summary"])
        fe.updated(arrow.get(item["timestamp"]).datetime)
        fe.published(fe.updated())

    fg.rss_file("feed/feed.rss", pretty=True)
Beispiel #5
0
def get_rss(limit, limit_days, message_type=None):
    start_at = datetime.today() - timedelta(days=limit_days + 1)
    app.logger.info('get_rss: Start set to {}'.format(start_at))
    status = Status.query.filter(Status.timestamp >= start_at).order_by(
        Status.id.desc())
    if message_type:
        status = status.filter(Status.message_type == message_type)

    fg = FeedGenerator()
    fg.title('NREC Status updates')
    fg.language('en')
    fg.link(href='https://status.nrec.no', length=140)
    fg.description('Status messages from NREC')
    fg.docs('https://report.nrec.no/api/ui/')
    tz = pytz.timezone('Europe/Oslo')
    for s in status.all()[:limit]:
        app.logger.info("add {}".format(s.id))
        fe = fg.add_entry(order='append')
        fe.id(str(s.id))
        fe.title(s.timestamp.strftime("%a, %d %b %Y"))
        fe.content(s.message)
        fe.category(category=dict({'term': s.message_type}))
        fe.published(tz.localize(s.timestamp))

    return fg.rss_str(pretty=True), 200
Beispiel #6
0
def rss():
    fg = FeedGenerator()
    fg.title('CloudWalk DevSecOps test')
    fg.description('A RSS Feed for HTTP and TCP service')
    fg.docs('')
    fg.generator('')
    fg.link(href='http://example.com')

    with open('log.txt') as f:
        for line in f.readlines():
            info = line.replace('\n', '').split(';')
            fe = fg.add_entry()
            fe.title(f"{info[1]}")
            fe.pubDate(f"{info[0]} GTM-3")
            fe.description(f"server: {info[2]} port:{info[3]}")

    response = make_response(fg.rss_str())
    response.headers.set('Content-type', 'application/rss+xml')
    return response
Beispiel #7
0
    def setUp(self):

        fg = FeedGenerator()

        self.nsAtom = "http://www.w3.org/2005/Atom"
        self.nsRss = "http://purl.org/rss/1.0/modules/content/"

        self.feedId = 'http://lernfunk.de/media/654321'
        self.title = 'Some Testfeed'

        self.authorName = 'John Doe'
        self.authorMail = '*****@*****.**'
        self.author = {'name': self.authorName, 'email': self.authorMail}

        self.linkHref = 'http://example.com'
        self.linkRel = 'alternate'

        self.logo = 'http://ex.com/logo.jpg'
        self.subtitle = 'This is a cool feed!'

        self.link2Href = 'http://larskiesow.de/test.atom'
        self.link2Rel = 'self'

        self.language = 'en'

        self.categoryTerm = 'This category term'
        self.categoryScheme = 'This category scheme'
        self.categoryLabel = 'This category label'

        self.cloudDomain = 'example.com'
        self.cloudPort = '4711'
        self.cloudPath = '/ws/example'
        self.cloudRegisterProcedure = 'registerProcedure'
        self.cloudProtocol = 'SOAP 1.1'

        self.icon = "http://example.com/icon.png"
        self.contributor = {
            'name': "Contributor Name",
            'uri': "Contributor Uri",
            'email': 'Contributor email'
        }
        self.copyright = "The copyright notice"
        self.docs = 'http://www.rssboard.org/rss-specification'
        self.managingEditor = '*****@*****.**'
        self.rating = '(PICS-1.1 "http://www.classify.org/safesurf/" ' + \
            '1 r (SS~~000 1))'
        self.skipDays = 'Tuesday'
        self.skipHours = 23

        self.textInputTitle = "Text input title"
        self.textInputDescription = "Text input description"
        self.textInputName = "Text input name"
        self.textInputLink = "Text input link"

        self.ttl = 900

        self.webMaster = '*****@*****.**'

        fg.id(self.feedId)
        fg.title(self.title)
        fg.author(self.author)
        fg.link(href=self.linkHref, rel=self.linkRel)
        fg.logo(self.logo)
        fg.subtitle(self.subtitle)
        fg.link(href=self.link2Href, rel=self.link2Rel)
        fg.language(self.language)
        fg.cloud(domain=self.cloudDomain,
                 port=self.cloudPort,
                 path=self.cloudPath,
                 registerProcedure=self.cloudRegisterProcedure,
                 protocol=self.cloudProtocol)
        fg.icon(self.icon)
        fg.category(term=self.categoryTerm,
                    scheme=self.categoryScheme,
                    label=self.categoryLabel)
        fg.contributor(self.contributor)
        fg.copyright(self.copyright)
        fg.docs(docs=self.docs)
        fg.managingEditor(self.managingEditor)
        fg.rating(self.rating)
        fg.skipDays(self.skipDays)
        fg.skipHours(self.skipHours)
        fg.textInput(title=self.textInputTitle,
                     description=self.textInputDescription,
                     name=self.textInputName,
                     link=self.textInputLink)
        fg.ttl(self.ttl)
        fg.webMaster(self.webMaster)
        fg.updated('2017-02-05 13:26:58+01:00')
        fg.pubDate('2017-02-05 13:26:58+01:00')
        fg.generator('python-feedgen', 'x', uri='http://github.com/lkie...')
        fg.image(url=self.logo,
                 title=self.title,
                 link=self.link2Href,
                 width='123',
                 height='123',
                 description='Example Inage')

        self.fg = fg
Beispiel #8
0
    def setUp(self):

        fg = FeedGenerator()

        self.nsAtom = "http://www.w3.org/2005/Atom"
        self.nsRss = "http://purl.org/rss/1.0/modules/content/"

        self.feedId = 'http://lernfunk.de/media/654321'
        self.title = 'Some Testfeed'

        self.authorName = 'John Doe'
        self.authorMail = '*****@*****.**'
        self.author = {'name': self.authorName, 'email': self.authorMail}

        self.linkHref = 'http://example.com'
        self.linkRel = 'alternate'

        self.logo = 'http://ex.com/logo.jpg'
        self.subtitle = 'This is a cool feed!'

        self.link2Href = 'http://larskiesow.de/test.atom'
        self.link2Rel = 'self'

        self.language = 'en'

        self.categoryTerm = 'This category term'
        self.categoryScheme = 'This category scheme'
        self.categoryLabel = 'This category label'

        self.cloudDomain = 'example.com'
        self.cloudPort = '4711'
        self.cloudPath = '/ws/example'
        self.cloudRegisterProcedure = 'registerProcedure'
        self.cloudProtocol = 'SOAP 1.1'

        self.icon = "http://example.com/icon.png"
        self.contributor = {'name': "Contributor Name",
                            'uri': "Contributor Uri",
                            'email': 'Contributor email'}
        self.copyright = "The copyright notice"
        self.docs = 'http://www.rssboard.org/rss-specification'
        self.managingEditor = '*****@*****.**'
        self.rating = '(PICS-1.1 "http://www.classify.org/safesurf/" ' + \
            '1 r (SS~~000 1))'
        self.skipDays = 'Tuesday'
        self.skipHours = 23

        self.textInputTitle = "Text input title"
        self.textInputDescription = "Text input description"
        self.textInputName = "Text input name"
        self.textInputLink = "Text input link"

        self.ttl = 900

        self.webMaster = '*****@*****.**'

        fg.id(self.feedId)
        fg.title(self.title)
        fg.author(self.author)
        fg.link(href=self.linkHref, rel=self.linkRel)
        fg.logo(self.logo)
        fg.subtitle(self.subtitle)
        fg.link(href=self.link2Href, rel=self.link2Rel)
        fg.language(self.language)
        fg.cloud(domain=self.cloudDomain, port=self.cloudPort,
                 path=self.cloudPath,
                 registerProcedure=self.cloudRegisterProcedure,
                 protocol=self.cloudProtocol)
        fg.icon(self.icon)
        fg.category(term=self.categoryTerm, scheme=self.categoryScheme,
                    label=self.categoryLabel)
        fg.contributor(self.contributor)
        fg.copyright(self.copyright)
        fg.docs(docs=self.docs)
        fg.managingEditor(self.managingEditor)
        fg.rating(self.rating)
        fg.skipDays(self.skipDays)
        fg.skipHours(self.skipHours)
        fg.textInput(title=self.textInputTitle,
                     description=self.textInputDescription,
                     name=self.textInputName, link=self.textInputLink)
        fg.ttl(self.ttl)
        fg.webMaster(self.webMaster)
        fg.updated('2017-02-05 13:26:58+01:00')
        fg.pubDate('2017-02-05 13:26:58+01:00')
        fg.generator('python-feedgen', 'x', uri='http://github.com/lkie...')
        fg.image(url=self.logo,
                 title=self.title,
                 link=self.link2Href,
                 width='123',
                 height='123',
                 description='Example Inage')

        self.fg = fg
Beispiel #9
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')

        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']

            # main element
            channel = FeedGenerator()
            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.id('https://plus.google.com/' + user_id)
            channel.link(href=host_url, rel='self')
            channel.docs('')
            if 'photo_url' in obj and obj['photo_url'] is not None:
                channel.image(url=obj['photo_url'],
                              title='Plus Channel feed',
                              link='https://plus.google.com/' + user_id,
                              width=str(cfg.get('feed.photo_size.database')),
                              height=str(cfg.get('feed.photo_size.database')))

            # additional namespaces
            channel.register_extension('media', MediaExtension, MediaEntryExtension)
            channel.register_extension('geo', GeoExtension, GeoEntryExtension)

            # compose items
            h = HTMLParser.HTMLParser()
            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 = channel.add_entry()
                item.title(check_encoding(title))
                item.pubdate(activity['datePublished'])

                # process content
                c_content = check_encoding(content)
                item.description(c_content)
                item.content(content=c_content, type='CDATA')

                # # check image presence
                if 'imageUrl' in activity and activity['imageUrl'] != '':
                    item.media.media_thumbnail_url(activity['imageUrl'])

                    # check size
                    if 'imageWidth' in activity and 'imageHeight' in activity:
                        item.media.media_thumbnail_width(activity['imageWidth'])
                        item.media.media_thumbnail_height(activity['imageHeight'])

                # check coordinates
                if activity['hasCoordinates']:
                    item.geo.geo_lat(activity['latitude'])
                    item.geo.geo_long(activity['longitude'])

                # check link
                if url is None or url == '':
                    url = activity['url']
                item.link(href=escape(url), rel='alternate')
                item.guid(escape(activity['id']))

            # return created feed
            response.set_header('content-type', 'application/rss+xml; charset=utf-8')
            out = channel.rss_str(pretty=True)
            del channel, activities, user_id, obj
            return out

        except FeedService.FeedNotFoundException:
            abort(404)

        except FeedService.UserIdNotFoundException:
            abort(410)