[Fixed]-Automatically scan RSS feeds and populate WebContent model

1👍

There seem to be many problems in your code:

  1. Within the method generate_web_content you are creating a WebContent object by passing the argument user_profile=self while it should be blogger=self.

  2. In the method _scan_web_content you’ve queried all the Blogger objects like:

    urls = Blogger.objects.all()
    

    so, urls is a queryset object and you can’t access the key like urls['rss_url'] instead you should do

    d = feedparser.parse(self.rss_url)
    
  3. Inside the for loop you should add attributes to the WebContent object passed as an argument like:

    for post in d.entries:
        web_content.blogger = self
        web_content.title = post.title.encode('ascii', 'ignore')
        web_content.url = post.link.encode('ascii', 'ignore')
    web_content.save()
    

    otherwise this method does not do anything.

Hope it clarifies!

Leave a comment