Blog Aggregator

In this blog i will be writing about how to make a blog aggregator.

A blog aggregator is a web application which aggregates syndicated web content such as online newspapers, blogs, podcasts, and video blogs in one location for easy viewing.The most important ingredient in making a blog aggregator is to import the rss feed. we can use Django to develop a full fledged blog aggregator in python. The steps to make a blog aggregator are mentioned bellow:

Django

1*u_Jr6FozmyMCi3pe9ZsoFg.png

First we need to create a virtual environment in which we must create a django project named rssfeed(these names are just for reference). Inside this project we must create an app named blogaggr. We must add the blogaggr name in the installed apps inside settings.py file of the project rssfeed.Inside the urls.py file of the project we need to add url(r’^feed/’, include(‘blogaggr.urls’)),  which will let the project access the urls inside the blogaggr using the url ‘feed’.

Inside the app:

Models.py

Inside models.py we need to type:

class link(models.Model):
     url = models.CharField(max_length=250)

     def __str__(self):
          return self.url

Here we are creating a class named link in which we are defining url as the model to stored data after parsing the data from the feed as you will see below. We are then returning itself.

Urls.py

Inside urls.py first we import views from the same folder.Then we need to type:

urlpatterns = [
url(r’^blogaggr’, views.feed, name = ‘feed’),
url(r’^search’, views.search, name = ‘search’),

]

Here we are defining 2 urls, ‘blogaggr’ and ‘search’ which are used to import the feed and search in the views.py file respectively. Then we are naming them as feed and search.

Templates:

We need to create a templates folder in the app and inside it a folder named blogaggr(i.e. the name of the app) and inside it create a html file named home.html

https://code.jquery.com/jquery-3.2.1.slim.min.js
https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js
https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js


 

Enter the RSS feed link to be searched:

 


 

 

First inside the head of the file we give links to bootstrap which will help our web page to look beautiful. In the body we need to add an action in form to send the data to the file specified(i.e, feed/search). Then we add a textbox with the name ‘q’ which is specified as to ease the use of the data in it. Then we add a submit button.  

Views.py

Screenshot from 2018-07-05 22-47-12

In the views.py file of the app first we import forms, render, models, HttpResponse, re, feedparser. Then we define feed which will return all the data that has been saved in the html file. Next we define search in which we get ‘q’ present in the home.html file’s textbox then we define d as the parsed data from the rssfeed of q. And then we define s as the feed’s title and description. Then for every post inside ‘d'(i.e,the parsed data) we define s as itself plus the post title and sm as the post summary and the next line is the regular expression. Then we define s as itself plus the data stored inside sm. Then for every post in ‘d’ we add its post link to the data we gathered. Next we save it all in the url and return a HttpResponse of s. If the rss feed is not found or if nothing is inputed we show an error as a HttpResponse.

Thank you.

 
Continue reading “Blog Aggregator”

Advertisements