lkiesow / python-feedgen

Python module to generate ATOM feeds, RSS feeds and Podcasts.
https://feedgen.kiesow.be/
BSD 2-Clause "Simplified" License
728 stars 122 forks source link

AttributeError: 'PodcastExtension' object has no attribute 'itunes_duration' #100

Closed Mewash1 closed 9 months ago

Mewash1 commented 4 years ago

I have the following code for rss feed generator:


import sys
from feedgen.feed import FeedGenerator

def generator():
    fg = FeedGenerator()
    fg.load_extension('podcast')
    fg.title('xyz')
    fg.link(href='https://something.coml', rel='alternate')
    fg.language('en')

    fg.podcast.itunes_category({"cat":"Leisure", "sub":"Games"})

    fe = fg.add_entry()
    fe = fg.podcast.itunes_duration('123')
    fe.title('The First Episode')

    fg.rss_str(pretty=True)
    fg.rss_file('podcast.xml')

generator()

Also, I deleted categories that are irrelevant to the problem. For some reason, I get an AttributeError. I have literally no idea why this happens, the library is imported properly.

limburgher commented 3 years ago

The library, as of 0.9.0, does not yet support itunes_duration.

calpaterson commented 2 years ago

The library, as of 0.9.0, does not yet support itunes_duration.

Yes it does:

https://github.com/lkiesow/python-feedgen/blob/ffe3e4d752ac76e23c879c35682c310c2b1ccb86/feedgen/ext/podcast_entry.py#L136

Here's some code I use elsewhere:

https://github.com/calpaterson/dircast/blob/a9c27572b38f9e5d22bce526b6d82196a749b019/dircast/feed.py#L10-L25

hanscees commented 1 year ago

I have the same kind of error in extention media, see the question of today " please give an working example of media extention

AttributeError: 'MediaExtension' object has no attribute 'content'

AttributeError: 'MediaExtension' object has no attribute 'media_content'

??

gftabor commented 1 year ago

I had similar issue and realized the problem. I assumed fe was a podcast_entry when you loaded the podcast extension and asked for a new entry. The OP's problem is they needed to do fe.podcast.itunes_duration not fg.podcast.itunes_duration and my problem had been trying fe.itunes_duration.

image

lkiesow commented 9 months ago

Exactly. The fixed code would be something like:

import sys
from feedgen.feed import FeedGenerator

def generator():
    fg = FeedGenerator()
    fg.load_extension('podcast')
    fg.title('xyz')
    fg.link(href='https://something.coml', rel='alternate')
    fg.language('en')
    fg.description('...')

    fg.podcast.itunes_category({"cat":"Leisure", "sub":"Games"})

    fe = fg.add_entry()
    fe.podcast.itunes_duration('123')
    fe.title('The First Episode')

    fg.rss_str(pretty=True)
    fg.rss_file('podcast.xml')

generator()