Esempio n. 1
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()
Esempio n. 2
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"))
Esempio n. 3
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")
Esempio n. 4
0
    def rssitems(self, n=10):
        result = []
        for file in self.data:
            try:
                rssitem = ItunesRSSItem(
                    title=file.title,
                    link=file.link if 'link' in file.__dict__
                    else 'http://www.podcast.de/',
                    author=file.artist,
                    description=file.description,
                    pubDate=file.pubdate,
                    guid=PyRSS2Gen.Guid(file.url),
                    enclosure=PyRSS2Gen.Enclosure(
                        file.url,
                        file.filesize,
                        "audio/mpeg"
                    )
                )
                rssitem.image = self._create_image_tag(rssitem)
                rssitem.duration = str(dt.timedelta(seconds=file.playtime))
                result.append(rssitem)
            except AttributeError as e:
                raise RuntimeError("{}: {}".format(file.basename, e.message))

        waste = [(i.pubDate, i) for i in result]
        waste.sort()
        waste.reverse()
        waste = waste[:n]
        result = [pair[1] for pair in waste]

        self.log.debug(u'  rssitems: Found %d items' % len(result))
        return result
Esempio n. 5
0
def feed_latest(request):
    entry = EntryDetail()
    entries = entry.get_queryset().filter(
        status=PUBLISHED).order_by('-creation_date')[:50]
    for entry in entries:
        if entry.entry_type == TYPE_ANNOUNCEMENT:
            url = entry.get_absolute_url().replace('/blog/', '/announcement/')
            entry.urls = url
        else:
            entry.urls = entry.get_absolute_url()
    items = []
    for entry in entries:
        link = "%s%s" % (settings.BASE_URL, entry.urls)
        enclosure = None
        if entry.image:
            enclosure = PyRSS2Gen.Enclosure(entry.image.url, 1024,
                                            'image/jpeg')
        item = PyRSS2Gen.RSSItem(title=entry.title,
                                 link=link,
                                 guid=PyRSS2Gen.Guid(link),
                                 enclosure=enclosure,
                                 pubDate=entry.creation_date)
        items.append(item)
    rss = PyRSS2Gen.RSS2(title='newtonproject.org',
                         link="%s/feed/" % settings.BASE_URL,
                         description="newtonproject",
                         lastBuildDate=datetime.datetime.now(),
                         docs='%s/about/' % settings.BASE_URL,
                         items=items)
    rss.rss_attrs['xmlns:atom'] = 'http://www.w3.org/2005/Atom'
    xml = rss.to_xml(encoding='UTF-8')
    return HttpResponse(xml, mimetype='application/rss+xml;charset=utf-8')
Esempio n. 6
0
    def process_ep(self, ep):

        for ext in self.options.upload_formats:

            fullpathname = os.path.join(self.show_dir, ext,
                                        ep.slug + "." + ext)

            if os.path.exists(fullpathname):

                # this should be ep.some_url but oh well.
                url = '{base}/{year}/{show}/{ext}/{slug}.{ext}'.format(
                    base=self.options.base_url,
                    year=ep.start.year,
                    show=ep.show.slug,
                    slug=ep.slug,
                    ext=ext)

                info = PyRSS2Gen.RSSItem(
                    title=ep.name,
                    description=ep.description,
                    guid=PyRSS2Gen.Guid(ep.conf_url),
                    pubDate=ep.start,
                    link=ep.conf_url,
                    enclosure=PyRSS2Gen.Enclosure(
                        url=url,
                        length=os.stat(fullpathname).st_size,
                        type='video/' + ext,
                    ))

                self.items.append(info)
Esempio n. 7
0
def make_video_rss(fh, eps):
    items = []
    for ep in eps:
        info = PyRSS2Gen.RSSItem(
            title=ep.name,
            description=ep.description,
            guid=PyRSS2Gen.Guid(ep.conf_url),
            pubDate=ep.end,
            link=ep.conf_url,
            enclosure=PyRSS2Gen.Enclosure(
                url=
                'http://meetings-archive.debian.net/pub/debian-meetings/%s/%s/%s.webm'
                % (ep.end.year, ep.show.slug, ep.slug),
                length=os.stat(
                    '/home/veyepar/Videos/veyepar/%s/%s/webm/%s.webm' %
                    (ep.show.client.slug, ep.show.slug, ep.slug)).st_size,
                type='video/webm',
            ))
        items.append(info)

    rss = PyRSS2Gen.RSS2(title="Debconf 16 video RSS feed",
                         link="https://debconf16.debconf.org",
                         description="The published videos from Debconf 16",
                         lastBuildDate=datetime.datetime.now(),
                         items=items)

    rss.write_xml(fh, encoding='UTF-8')
Esempio n. 8
0
    def gallery_rss(self, img_list, dest_img_list, img_titles, lang, permalink,
                    output_path, title):
        """Create a RSS showing the latest images in the gallery.

        This doesn't use generic_rss_renderer because it
        doesn't involve Post objects.
        """
        def make_url(url):
            return urljoin(self.site.config['BASE_URL'], url.lstrip('/'))

        all_data = list(zip(img_list, dest_img_list, img_titles))

        if self.kw['sort_by_date']:
            all_data.sort(key=lambda a: self.image_date(a[0]))
        else:  # Sort by name
            all_data.sort(key=lambda a: a[0])

        if all_data:
            img_list, dest_img_list, img_titles = zip(*all_data)
        else:
            img_list, dest_img_list, img_titles = [], [], []

        items = []
        for img, srcimg, title in list(zip(
                dest_img_list, img_list, img_titles))[:self.kw["feed_length"]]:
            img_size = os.stat(
                os.path.join(self.site.config['OUTPUT_FOLDER'], img)).st_size
            args = {
                'title':
                title,
                'link':
                make_url(img),
                'guid':
                rss.Guid(img, False),
                'pubDate':
                self.image_date(srcimg),
                'enclosure':
                rss.Enclosure(make_url(img), img_size,
                              mimetypes.guess_type(img)[0]),
            }
            items.append(rss.RSSItem(**args))
        rss_obj = rss.RSS2(title=title,
                           link=make_url(permalink),
                           description='',
                           lastBuildDate=datetime.datetime.utcnow(),
                           items=items,
                           generator='https://getnikola.com/',
                           language=lang)

        rss_obj.rss_attrs["xmlns:dc"] = "http://purl.org/dc/elements/1.1/"
        rss_obj.self_url = make_url(permalink)
        rss_obj.rss_attrs["xmlns:atom"] = "http://www.w3.org/2005/Atom"
        dst_dir = os.path.dirname(output_path)
        utils.makedirs(dst_dir)
        with io.open(output_path, "w+", encoding="utf-8") as rss_file:
            data = rss_obj.to_xml(encoding='utf-8')
            if isinstance(data, utils.bytes_str):
                data = data.decode('utf-8')
            rss_file.write(data)
Esempio n. 9
0
def enclosure(entry):
    return next(
            PyRSS2Gen.Enclosure(
                url = link.href,
                length = link.length,
                type = link.type
            )
            for link in entry.links 
            if link.rel == 'enclosure'
            )
Esempio n. 10
0
File: tests.py Progetto: emillon/pod
 def setup_podcast(self, url):
     assert httpretty.is_enabled()
     items = [PyRSS2Gen.RSSItem(
         title='Episode %d' % n,
         enclosure=PyRSS2Gen.Enclosure('http://example.com/%d.mp3' % n,
                                       42,
                                       'audio/mpeg'
                                       )
         ) for n in [1, 2, 3]]
     items.append(PyRSS2Gen.RSSItem(title='Not an episode'))
     rss = PyRSS2Gen.RSS2('title', 'link', 'description', items=items)
     httpretty.register_uri(httpretty.GET, url, body=rss.to_xml())
def feed(items, data=FEED_DATA):
    return RSS2.RSS2(
        **data,
        items = [RSS2.RSSItem(
            title = i['title'],
            link  = i['link'],
            description = i['description'],
            guid  = RSS2.Guid(i['guid']),
            enclosure = RSS2.Enclosure(url=i['file'], type='audio/mpeg', length=i['bytes']),
            pubDate = i['date'],
        ) for i in items ]
    )
Esempio n. 12
0
    def getAsRssItem(self):
        statinfo = os.stat(self.abs_filepath)
        file_length = statinfo.st_size

        return PyRSS2Gen.RSSItem(
            title=self.title,
            link=self.target_url,
            description="No Description for " + self.title,
            guid=PyRSS2Gen.Guid(self.target_url),
            pubDate=datetime.datetime.now(),
            enclosure=PyRSS2Gen.Enclosure(self.target_url, file_length,
                                          'audio/mpeg'),
        )
Esempio n. 13
0
 def __init__(self, base_url, rel_file, full_name):
     """
     Override PyRSS2Gen.RSSItem constructor to simplify constructor args for user
     """
     tag = TinyTag.get(rel_file)
     if tag.title is None:
         tag.title, ext = os.path.splitext(os.path.basename(rel_file))
     super().__init__(
         title=tag.title,
         link=urllib.parse.quote(rel_file),
         author=tag.artist,
         enclosure=PyRSS2Gen.Enclosure(base_url + "/" + urllib.parse.quote(rel_file), tag.filesize, "audio/mpeg"),
         guid=PyRSS2Gen.Guid(hashlib.sha256(full_name.encode('utf-8')).hexdigest(), isPermaLink=False),
         pubDate=tag.year
     )
Esempio n. 14
0
    def gallery_rss(self, img_list, img_titles, lang, permalink, output_path,
                    title):
        """Create a RSS showing the latest images in the gallery.

        This doesn't use generic_rss_renderer because it
        doesn't involve Post objects.
        """
        def make_url(url):
            return urljoin(self.site.config['BASE_URL'], url)

        items = []
        for img, full_title in list(zip(img_list,
                                        img_titles))[:self.kw["feed_length"]]:
            img_size = os.stat(
                os.path.join(self.site.config['OUTPUT_FOLDER'], img)).st_size
            args = {
                'title':
                full_title.split('"')[-2] if full_title else '',
                'link':
                make_url(img),
                'guid':
                rss.Guid(img, False),
                'pubDate':
                self.image_date(img),
                'enclosure':
                rss.Enclosure(make_url(img), img_size,
                              mimetypes.guess_type(img)[0]),
            }
            items.append(rss.RSSItem(**args))
        rss_obj = utils.ExtendedRSS2(
            title=title,
            link=make_url(permalink),
            description='',
            lastBuildDate=datetime.datetime.now(),
            items=items,
            generator='Nikola <http://getnikola.com/>',
            language=lang)
        rss_obj.self_url = make_url(permalink)
        rss_obj.rss_attrs["xmlns:atom"] = "http://www.w3.org/2005/Atom"
        dst_dir = os.path.dirname(output_path)
        utils.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, utils.bytes_str):
                data = data.decode('utf-8')
            rss_file.write(data)
Esempio n. 15
0
def create_rss(info: Program, stuff):
    rss = PyRSS2Gen.RSS2(
        title=info.name,
        link="http://fake-link.com",
        description="podcast description",
        lastBuildDate=datetime.now(),
        items=[
            PyRSS2Gen.RSSItem(
                title=s["title"],
                description=s["description"],
                guid=PyRSS2Gen.Guid(s["audio_url"]),
                enclosure=PyRSS2Gen.Enclosure(s["audio_url"], 0, "audio/mpeg"),
                pubDate=s["date"],
            )
            for s in stuff
        ],
    )
    return rss
Esempio n. 16
0
 def generate_feed_items(self):
     self.cursor.execute(
         "select * from posts order by timestamp desc limit 10")
     from_db = self.cursor.fetchall()
     posts = list()
     files = list()
     for (id_, text, enclosure_url, enclosure_media_type,
          timestamp) in from_db:
         post = RSS2.RSSItem(
             title=text,
             description=text,
             link=self.base_url + "%s.html" % id_,
             guid=RSS2.Guid(self.base_url + "%s.html" % id_),
             pubDate=formatdate(
                 totimestamp(dateutil.parser.parse(timestamp))))
         if enclosure_url is not None:
             post.enclosure = RSS2.Enclosure(url=enclosure_url,
                                             type=enclosure_media_type,
                                             length=0)
         posts.append(post)
         html_output = Template(self.template).render(
             rss_title=self.title,
             rss_link=self.link,
             rss_description=self.description,
             rss_feed_link=self.base_url + self.rss_filename,
             post_title=text,
             post_description=text,
             post_timestamp=timestamp,
             post_id=id_,
             enclosure_url=enclosure_url,
             enclosure_media_type=enclosure_media_type)
         html_fname = os.path.join(self.output_dir, "%s.html" % id_)
         with open(html_fname, "wb") as fh:
             fh.write(html_output)
         files.append(html_fname)
     rss = RSS2.RSS2(title=self.title,
                     link=self.link,
                     description=self.description,
                     lastBuildDate=datetime.datetime.utcnow(),
                     items=posts)
     rss_fname = os.path.join(self.output_dir, self.rss_filename)
     rss.write_xml(open(rss_fname, "wb"))
     files.append(rss_fname)
     return files
Esempio n. 17
0
    print(listDir)
    lm = list(
        map(lambda x: list(map(lambda k: x + '/' + k, os.listdir(x))),
            listDir))
    print("lm:{}\n *********************".format(lm))
    listDir = reduce(lambda x, y: x + y, lm)
files = list(
    filter(
        lambda x: path.splitext(x)[
            1] in [".MP3", ".mp3", ".M4V", ".m4v", '.mp4', ".MP4", ".mov"],
        listDir + os.listdir(dir)))
files.sort(key=_cmp)
myItems = [
    (rss.RSSItem(title=n,
                 description='',
                 enclosure=rss.Enclosure(url + ':' + str(port) + '/' + esc(n),
                                         0, "audio/mpeg"))) for n in files
]
myItems.reverse()
feed = rss.RSS2(title=path.basename(path.abspath(dir)),
                link="http://unnotigkeit.ya.ru",
                description="",
                lastBuildDate=datetime.datetime.now(),
                items=myItems)

feed.write_xml(
    open((dir + '/' + path.basename(path.abspath(dir)) + ".xml"), "w"),
    "utf-8")
print(url + ':' + str(port) + '/' + esc(path.basename(path.abspath(dir))) +
      ".xml")
import http.server
Esempio n. 18
0
    if not (x == y):
        raise AssertionError( (x, y) )

class RecordingHandler:
    def __init__(self):
        self.events = []
    def startElement(self, tag, d):
        self.events.append( ("SE", tag, d) )
    def characters(self, text):
        self.events.append( ("C", text) )
    def endElement(self, tag):
        self.events.append( ("EE", tag) )

def publish_it(obj):
    h = RecordingHandler()
    obj.publish(h)
    return h.events

obj = PyRSS2Gen.Enclosure("http://example.com", 5, "text/plain")
EQ(publish_it(obj), [("SE", "enclosure", {"url": "http://example.com",
                                          "length": "5",
                                          "type": "text/plain"}),
                     ("EE", "enclosure"),
                     ])

obj = PyRSS2Gen.Guid("ABCDEF", False)
EQ(publish_it(obj), [("SE", "guid", {"isPermaLink": "false"}),
                     ("C", "ABCDEF"),
                     ("EE", "guid"),
                     ])
Esempio n. 19
0
import PyRSS2Gen as RSS2
import feedparser
import re

# dan lebatard, Best of and Local shows
infeed = 'http://espn.go.com/espnradio/podcast/feeds/itunes/podCast?id=9941853'
outfeed = 'rss.xml'
pattern = 'Best|Local'

d = feedparser.parse(infeed)

rss = RSS2.RSS2(title=d.feed['title'],
                link=d.feed['links'][0]['href'],
                description=d.feed['summary'],
                items=[
                    RSS2.RSSItem(
                        title=post['title'],
                        link=post['link'],
                        description=post['summary'],
                        pubDate=post['published'],
                        enclosure=RSS2.Enclosure(post['links'][1]['href'],
                                                 post['links'][1]['length'],
                                                 post['links'][1]['type']),
                    ) for post in d.entries if re.search(pattern, post.title)
                ])

rss.write_xml(open(outfeed, "w"))
Esempio n. 20
0
def generateRSS( rootNode, indent=2 ):
    """Generate an OPML/XML tree from OutlineNode rootNode.
    
    parameters:
     filepath - unused since file writing has been factored out
     indent   - if > 0 indent with indent spaces per level
    return
     etree.Element of rootNode
    """

    valid_RSSChannel = ( "title", "link", "description", "language",
            "copyright", "managingEditor", "webMaster", "pubDate",
            "lastBuildDate", "categories", "generator", "docs",
            "cloud", "ttl", "image", "rating", "textInput",
            "skipHours", "skipDays", "items")

    valid_RSSItems = ( "title", "link", "description", "author",
            "categories", "comments", "enclosure", "guid",
            "pubDate", "source" )

    backTranslator = {
        'subtitle': 'description',
        'title': 'title',
        'published': 'pubDate',
        'id': 'guid'
    }

    now = str(datetime.datetime.now())
    now = now[:19]
    now = now.replace(" ", "_")

    # unused
    creator = CactusVersion.document_creator + " on %s." % (now,)

    # defaults
    head_d = {
        'title': "No Channel Title",
        'description': "No Channel description.",
        'link':  ""}

    headOP = rootNode.findFirstChildWithName_( "head" )

    if headOP:
        for headsub in headOP.children:
            name = headsub.name
            name = backTranslator.get(name, name)
            if name in valid_RSSChannel:
                value = headsub.getValueDict()
                if name == 'cloud':
                    cloud = PyRSS2Gen.Cloud(
                            value.get('domain', ""),
                            value.get('port', ""),
                            value.get('path', ""),
                            value.get('registerProcedure', ""),
                            value.get('protocol', ""))
                    head_d[ 'cloud' ] = cloud
                elif name == 'image':
                    image = PyRSS2Gen.Image(
                            value.get('href', ""),
                            value.get('title', ""),
                            value.get('link', ""),
                            value.get('width', None),
                            value.get('height', None),
                            value.get('description', None))
                    head_d[ 'image' ] = image

                else:
                    if len(value) == 1:
                        head_d[name] = value.values()[0]
                    else:
                        
                        head_d[name] = value
        print "HEAD:"
        pp(head_d)
    body_l = []
    bodyOP = rootNode.findFirstChildWithName_( "body" )

    if bodyOP:
        for bodysub in bodyOP.children:
            name = bodysub.name
            value = bodysub.getValueDict()
            d = {'title': "No Item Title",
                 'description': "No Item description."}

            for key in value:
                v = value[key]
                k = backTranslator.get(key, key)
                if k == "summary":
                    k = "description"
                if k in valid_RSSItems:

                    if k == 'enclosure':
                        url, rest = value[key].split('<<<')
                        length, type_ = rest.split(';', 1)
                        try:
                            length = int(length)
                        except ValueError, err:
                            if kwlog:
                                print "BOGUS ENCLOSURE LENGTH: %s" % repr(length)
                            length = 0
                        enc = PyRSS2Gen.Enclosure( url, length, type_)
                        d[k] = enc
                    else:
                        # TODO: check for type here; dicts and lists may be bad
                        d[ k ] = v #value[key]
                        if type(d[ k ]) in (list, dict, tuple):
                            print "\ngenerateRSS() type error.\n"
                        
            #print "ITEM:"
            #pp( d )
            body_l.append( PyRSS2Gen.RSSItem( **d ) )
Esempio n. 21
0
        youtube_description = youtube_info['description']
        if not youtube_description:
            youtube_description = ""
        if len(youtube_description) > 0 and youtube_description[-1] != ' ':
            youtube_description = youtube_description + ' '

        item_dict['description'] = conf['video_description'].format(
            youtube_description=youtube_description.encode('utf-8'),
            video_location=(" / ".join(description)).encode('utf-8'),
            pretty_length=pretty_length.encode('utf-8'),
            duration=youtube_info['duration_str'].encode('utf-8'),
            **conf)

        item_dict['enclosure'] = PyRSS2Gen.Enclosure(url=urlparse.urljoin(
            conf['url_base'], base_filename),
                                                     length=length,
                                                     type=conf['mimetype'])
        items.append(PyRSS2Gen.RSSItem(**item_dict))

if conf["reverse"]:
    items.reverse()

rss = PyRSS2Gen.RSS2(title=conf["podcast_title"].format(**conf),
                     link=args.course_url,
                     description=conf["podcast_description"].format(**conf),
                     lastBuildDate=datetime.datetime.now(),
                     items=items,
                     managingEditor="edX Learning Sciences")

## Write output to a file
data = StringIO.StringIO()
Esempio n. 22
0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

res = br.open(podbean_feed_url)
soup = BeautifulSoup(res.read(), features='html5lib')

posts = soup.find_all('div', attrs={'class': 'post'})

podcast_feed = []

for post in posts:
    if post.find('div', attrs={'class': 'premium-btn-block'}):
        post_title = filter(lambda x: x in string.printable, ''.join(post.find('h2').string))
        post_date = post.find('p', attrs={'class': 'post-info'}).get_text()
        post_date = parse(post_date, fuzzy=True)
        post_audio = PyRSS2Gen.Enclosure(post.find('div', attrs={'class': 'pbplayerBox theme13'})['data-uri'],
                                         '300000000', 'audio/mpeg')
        post_permlink = post.find_all('a', href=True)[0]['href']

        post_soup = BeautifulSoup(br.open(post_permlink).read(), features='html5lib')
        post_description_html = post_soup.find('div', attrs={'class': 'entry'})

        post_description_html.find(('div'), attrs={'class': 'podPress_content'}).decompose()
        post_description = bleach.clean(str(post_description_html),
                                        tags=['a', 'abbr', 'acronym', 'b', 'blockquote', 'code',
                                              'em', 'i', 'li', 'ol', 'strong', 'ul', 'p'],
                                        strip=True).strip()

        podcast_feed.append((post_title, post_audio, post_description, post_date, post_permlink))

rss = PyRSS2Gen.RSS2(
    title='Unofficial Zomia ONE Premium Feed',
Esempio n. 23
0
    upload_date = info["upload_date"] or "00000000"
    thumbnail_url = info["thumbnail"] or "https://i.ytimg.com/vi/%s/hqdefault.jpg" % info["id"]

    episodes.append(PyRSS2Gen.RSSItem(
        title = title,
        link = orig_url,
        description = "<p>%s &bull; %s.%s.%s</p> <p><a href=\"%s\"><img src=\"%s\"></a></p>" % (
            html.escape(author),
            upload_date[6:8], upload_date[4:6], upload_date[0:4],
            html.escape(orig_url),
            html.escape(thumbnail_url)
        ),
        author = author,
        enclosure = PyRSS2Gen.Enclosure(
            url = URL + "/" + mp3_name,
            type = "audio/mpeg",
            length = 0
        ),
        guid = orig_url,
        pubDate = info_time
    ))

    print("Episode: " + title)

rss = PyRSS2Gen.RSS2(
    title = "YouTube",
    link = "",
    description = "",
    image = PyRSS2Gen.Image(
        url = "https://via.placeholder.com/720/272727/f00?text=YT",
        title = "YouTube",
Esempio n. 24
0
response = urllib.request.urlopen(request)
list_page = response.read().decode("utf-8")
page_json = json.loads(list_page)
programs = page_json["programs"]

item_list = []
for program in programs:
	temp_item = PyRSS2Gen.RSSItem(
		title = program["name"],
		link = 	program_url+str(program["id"]),
		description = program["description"],
		pubDate = datetime.datetime.fromtimestamp(int(int(program["createTime"])/1000)),
		guid = "netease_"+str(program["id"]),
		enclosure = PyRSS2Gen.Enclosure(
			url = audio_url+str(program["mainSong"]["id"])+".mp3",
			length = program["mainSong"]["bMusic"]["size"],
			type = "audio/mpeg"
			)
		)
	item_list.append(temp_item);

rss = PyRSS2Gen.RSS2(  
	title = info["name"],  
	link = radio_url+radio_id,  
	description = info["desc"], 
	language = "zh_CN",
	image = PyRSS2Gen.Image(
		url = info["picUrl"],
		title = info["name"],
		link = radio_url+radio_id
	),
Esempio n. 25
0
    def ReadFromTextFile(self, txtFileName):

        if not os.path.lexists(txtFileName):
            print "WARNING: Item text file does not exist.  Empty Item created."
            return

        fileLines = file(txtFileName, 'r').readlines()
        # Process each line in the data file
        lineNum = 0
        for line in fileLines:
            lineNum = lineNum + 1
            try:
                lineList = [x.strip() for x in line.split("=", 1)]

                # Skip comment and blank lines
                if (lineList[0].startswith("#") or (lineList[0] == "")):
                    continue

                # Detect badly formed item lines
                if (lineList[1] == ''):
                    raise Exception, "no valid 'name = value' pair"

                # GIUD element
                if lineList[0] == 'guid':
                    self.guid = PyRSS2Gen.Guid(lineList[1])

                # ENCLOSURE element
                elif lineList[0] == 'enclosure':
                    if self.enclosureList is None:
                        self.enclosureList = []
                    s = [x.strip() for x in lineList[1].split(",")]
                    self.enclosureList.append(
                        PyRSS2Gen.Enclosure(s[0], int(s[1]), s[2]))

                # CUSTOMELEMENT element
                # These elements may vary based on the 'type' defined in the config
                # file, so this may be a bit tricky...
                elif lineList[0] == 'customElement':
                    # Create self.customElementList if necessary.  Should be since we're
                    # reading from a file...
                    if self.customElementList is None:
                        self.customElementList = []
                    # Tease out element name
                    (name,
                     value) = [x.strip() for x in lineList[1].split(",", 1)]
                    # If we know the parent feed, we understand the types of the
                    # custom elements...
                    if self.parentFeed is not None:
                        type = self.parentFeed.customEltDefNameHash[name].type
                        # If the type is a complex type, we need to build a value object
                        # and pass it along so that custom XML publish methods can be called
                        if (type == 'point'):
                            (lat, lon) = [x.strip() for x in value.split(",")]
                            value = cePoint(float(lat), float(lon))
                        elif (type == 'envelope'):
                            ### FIXME - future support for georss envelope custom element
                            pass

                        # Single value types are just passed along to be included as
                        # strings in the XML

                    self.customElementList.append(CustomElement(name, value))

                # Extents element
                elif lineList[0] == 'extents':
                    s = lineList[1].split(",")
                    self.extents = Extents(float(s[0]), float(s[1]),
                                           float(s[2]), float(s[3]))

                # ExtentsPoly element
                elif lineList[0] == 'extentsPoly':
                    s = lineList[1].split(",")
                    if (len(s) / 2 == len(s) / 2.0):
                        listLatLon = [(float(s[i]), float(s[i + 1]))
                                      for i in range(0, len(s), 2)]
                        if self.simplifyPologons:
                            self.extents = ExtentsPoly(listLatLon,
                                                       self.simplifyPolygons,
                                                       self.polyDistThresh,
                                                       self.polyMaxPoints)
                        else:
                            self.extents = ExtentsPoly(listLatLon,
                                                       simplifyPolygons=False)

                # All datetime object elements
                elif ((lineList[0] == 'acquisitionStartDate')
                      or (lineList[0] == 'acquisitionEndDate')
                      or (lineList[0] == 'acquisitionStartTime')
                      or (lineList[0] == 'acquisitionEndTime')
                      or (lineList[0] == 'pubDate')):
                    s = [int(x.strip()) for x in lineList[1].split(":")]
                    dtEvalStr = ("datetime.datetime(" +
                                 ", ".join([str(x) for x in s]) + ")")
                    # We are standardizing on Date, not Time special case patch (YUCK)
                    if ((lineList[0] == 'acquisitionStartTime')
                            or (lineList[0] == 'acquisitionEndTime')):
                        lineList[0] = lineList[0].replace('Time', 'Date')

                    # Write it into the Dictionary...
                    self.__dict__[lineList[0]] = eval(dtEvalStr)

                # All other simple single string elements
                else:
                    self.__dict__[lineList[0]] = lineList[1]

            except Exception, inst:
                print "WARNING: Badly formed Item text file line..."
                print "  Exception: %s" % inst
                print "  %d:  %s" % (lineNum, line.strip())
                print "  Line skipped."
Esempio n. 26
0
    def on_task_exit(self, task, config):
        """Store finished / downloaded entries at exit"""
        if not rss2gen:
            raise plugin.PluginWarning(
                'plugin make_rss requires PyRSS2Gen library.')
        config = self.prepare_config(config)

        # when history is disabled, remove everything from backlog on every run (a bit hackish, rarely useful)
        if not config['history']:
            log.debug('disabling history')
            for item in task.session.query(RSSEntry).filter(
                    RSSEntry.file == config['file']).all():
                task.session.delete(item)

        # save entries into db for RSS generation
        for entry in task.accepted:
            rss = RSSEntry()
            try:
                rss.title = entry.render(config['title'])
            except RenderError as e:
                log.error(
                    'Error rendering jinja title for `%s` falling back to entry title: %s',
                    entry['title'],
                    e,
                )
                rss.title = entry['title']
            for field in config['link']:
                if field in entry:
                    rss.link = entry[field]
                    break

            try:
                template = get_template(config['template'], scope='task')
            except ValueError as e:
                raise plugin.PluginError('Invalid template specified: %s' % e)
            try:
                rss.description = render_from_entry(template, entry)
            except RenderError as e:
                log.error(
                    'Error while rendering entry %s, falling back to plain title: %s',
                    entry, e)
                rss.description = entry['title'] + ' - (Render Error)'
            rss.file = config['file']
            if 'rss_pubdate' in entry:
                rss.published = entry['rss_pubdate']

            rss.enc_length = entry['size'] if 'size' in entry else None
            rss.enc_type = entry['type'] if 'type' in entry else None

            # TODO: check if this exists and suggest disabling history if it does since it shouldn't happen normally ...
            log.debug('Saving %s into rss database', entry['title'])
            task.session.add(rss)

        if not rss2gen:
            return
        # don't generate rss when learning
        if task.options.learn:
            return

        db_items = (task.session.query(RSSEntry).filter(
            RSSEntry.file == config['file']).order_by(
                RSSEntry.published.desc()).all())

        # make items
        rss_items = []
        for db_item in db_items:
            add = True
            if config['items'] != -1:
                if len(rss_items) > config['items']:
                    add = False
            if config['days'] != -1:
                if (datetime.datetime.today() -
                        datetime.timedelta(days=config['days']) >
                        db_item.published):
                    add = False
            if add:
                # add into generated feed
                hasher = hashlib.sha1()
                hasher.update(db_item.title.encode('utf8'))
                hasher.update(db_item.description.encode('utf8'))
                hasher.update(db_item.link.encode('utf8'))
                guid = base64.urlsafe_b64encode(
                    hasher.digest()).decode('ascii')
                guid = PyRSS2Gen.Guid(guid, isPermaLink=False)

                gen = {
                    'title': db_item.title,
                    'description': db_item.description,
                    'link': db_item.link,
                    'pubDate': db_item.published,
                    'guid': guid,
                }
                if db_item.enc_length is not None and db_item.enc_type is not None:
                    gen['enclosure'] = PyRSS2Gen.Enclosure(
                        db_item.link, db_item.enc_length, db_item.enc_type)
                log.trace('Adding %s into rss %s', gen['title'],
                          config['file'])
                rss_items.append(PyRSS2Gen.RSSItem(**gen))
            else:
                # no longer needed
                task.session.delete(db_item)

        # make rss
        rss = PyRSS2Gen.RSS2(
            title=config.get('rsstitle', 'FlexGet'),
            link=config.get('rsslink', 'http://flexget.com'),
            description=config.get('rssdesc', 'FlexGet generated RSS feed'),
            lastBuildDate=datetime.datetime.utcnow()
            if config['timestamp'] else None,
            items=rss_items,
        )

        # don't run with --test
        if task.options.test:
            log.info('Would write rss file with %d entries.', len(rss_items))
            return

        # write rss
        fn = os.path.expanduser(config['file'])
        with io.open(fn, 'wb') as file:
            try:
                log.verbose('Writing output rss to %s', fn)
                rss.write_xml(file, encoding=config['encoding'])
            except LookupError:
                log.critical('Unknown encoding %s', config['encoding'])
                return
            except IOError:
                # TODO: plugins cannot raise PluginWarnings in terminate event ..
                log.critical('Unable to write %s', fn)
                return