Wednesday, November 3, 2021

Real Python: Build a Content Aggregator in Python

In this project-based tutorial, you’ll build a content aggregator from scratch using Python and the popular framework Django.

With so much content coming out online daily, it can be time consuming to go to multiple sites and sources to consume information about your favorite subjects. This is why content aggregators are so popular and powerful, as you can use them to view all the latest news and content in one place.

Whether you’re looking for a portfolio project or ways in which to extend future projects beyond simple CRUD capabilities, this tutorial will have something for you.

In this tutorial, you’ll learn:

  • How to work with RSS feeds
  • How to create a Django custom management command
  • How to run your custom command automatically on a schedule
  • How to use unit tests to test your Django app’s functionality

Click the link below to download the code for this project and follow along as you build your own content aggregator:

Get Source Code: Click here to get the source code you’ll use to build a content aggregator with Django and Python in this tutorial.

Demo: What You’ll Build

You’ll build your own podcast content aggregator in Python named pyCasts! by following this tutorial from start to finish.

The application will be a single web page displaying the latest Python podcast episodes from The Real Python Podcast and the Talk Python to Me Podcast. After completing this tutorial, you can practice what you’ve learned by adding more podcast feeds to the application.

Here’s a quick demo video of how it will look in action:

There are many moving parts behind the scenes that make this work efficiently and effectively in an automated fashion. You’ll learn about all of them in this tutorial. Get ready to delve in.

Project Overview

In order to be able to display the content to the end user, you have several steps to follow:

  1. Set up the project
  2. Build the podcast model
  3. Create the homepage view
  4. Parse a podcast RSS feed
  5. Create a Django custom command
  6. Add additional feeds
  7. Schedule tasks with django-apscheduler

You’ll walk through each of these over the course of this tutorial. Now you’ll look at which technologies and frameworks you’re going to use for the above steps.

In order to fetch the podcast RSS feeds into your application and parse them, you’ll learn how to use the feedparser library. You’ll use this library to extract only the newest episode data from the feed, which you’ll marshall into an Episode model and save to the database with the Django ORM.

You could add this code to a script and manually run it periodically, but that would defeat the point of having an aggregator to save time. Instead, you’ll learn how to use a built-in Django tool called a custom management command. To parse and save the data, you’ll run your code from within Django itself.

With help from the django-apscheduler library, you’ll set a schedule for your function calls, which are also called jobs. You can then use the Django admin panel to view which jobs ran and when. This will ensure that the fetching and parsing of your feed will happen automatically without needing admin intervention.

You’ll then use the Django template engine to show the user the queried context—in other words, the latest episodes.

Prerequisites

To get the most out of this tutorial, you should be comfortable with the following concepts and technologies:

You might also find it helpful to have some experience with Bootstrap 4.

Read the full article at https://realpython.com/build-a-content-aggregator-python/ »


[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...