[PYTHON] A simple RSS reader made with Django

Try to make a simple RSS reader

I can't learn anything unless I keep making it, so I'm going to use Django to get RSS that I've done once before. It seems that you can throw it into the database with reference to past articles, get only the text and chain it with Markov.

I tried it as a simple configuration as usual.

Write Views

myapp/views.py


import feedparser
import sys, codecs
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)

from django.http import (HttpResponse, HttpResponseRedirect,)
from django.shortcuts import (render, redirect,)
from django.core.mail import (send_mail, BadHeaderError,)

def index(request):
    url = 'http://news.yahoo.co.jp/pickup/local/rss.xml'
    feeder = feedparser.parse(url)

    for entry in feeder['entries']:
        title = entry['title']
        link = entry['link']

        context = {
        'title':title,
        'link':link,
        }

        return render(request,'index.html',context)

Write index.html

It is a simple template that displays only one item.

templates/index.html


{% extends "base.html" %}
{% block body %}
  <div class="container">
    <div class="row">

      <div class="col-md-6">
        {{ title }}
        {{ link }}
      </div>

    </div>
  </div>

{% endblock %}

I have an interesting feeling that it will be interesting to put it in the database and process it hard. Well, here is the production. Let's save it in the database.

Customization example

Get the adult video RSS of DMM and save it in the database.

views.py


import feedparser
import sys, codecs
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)

from django.http import HttpResponse
from django.shortcuts import (render, redirect,)
from myapp.models import Feedmodel

def index(request):
    url = 'http://www.dmm.co.jp/digital/videoa/-/list/rss/=/sort=date/'
    feeder = feedparser.parse(url)

    
    for entry in feeder['entries']:
        data = Feedmodel()
        data.title_name = entry['title']
        data.url_link = entry['link']
        data.package_img = entry['package']#Get package thumbnail
        data.save()

        all_data = Feedmodel.objects.order_by('-id')

    context = {
        'all_data': all_data,
    }

    return render(request,'index.html',context)

models.py


from django.db import models

class Feedmodel(models.Model):
    title_name = models.CharField(max_length=140)
    url_link = models.CharField(max_length=140)
    package_img = models.TextField(null=True)

Whether or not it is there is subtle, but it is for the management screen.

admin.py


from django.contrib import admin
from myapp.models import Feedmodel


class FeedmodelAdmin(admin.ModelAdmin):
    list_display = ('id','title_name','url_link','package_img')

admin.site.register(Feedmodel,FeedmodelAdmin)

index.html


{% extends "base.html" %}
{% block body %}
  <div class="container">
    <div class="row">

      <div class="col-md-12">
        {% for i in all_data %}
        <div class="col-md-4 clearfix">
          <p><img src="{{ i.package_img }}"><a href="{{ i.url_link }}">{{ i.title_name }}</a></p>
        </div>
        {% endfor %}
      </div>

    </div>
  </div>

{% endblock %}

It is unclear what it can be used for and whether it is practical.

Recommended Posts

A simple RSS reader made with Django
I made a simple RSS reader ~ C edition ~
I made a simple blackjack with Python
I made a WEB application with Django
I made a simple Bitcoin wallet with pycoin
A simple to-do list created with Python + Django
Create a homepage with django
Deploy a Django app made with PTVS on Azure
I made a simple typing game with tkinter in Python
A simple interactive music player made with Chuck and OpenPose
I made a simple book application with python + Flask ~ Introduction ~
(For beginners) Try creating a simple web API with Django
Deploy a Django application with Docker
I made a fortune with Python.
Django Tips-Create a ranking site with Django-
Twitter posting application made with Django
Creating a simple app with flask
Build a web application with Django
Make a filter with a django template
I made a daemon with Python
Create a file uploader with Django
I made a simple circuit with Python (AND, OR, NOR, etc.)
Make a simple OMR (mark sheet reader) with Python and OpenCV
Rails users try to create a simple blog engine with Django
[Python] I made an image viewer with a simple sorting function.
I made a development environment for Django 3.0 with Docker, Docker-compose, Poetry
Creating a simple PowerPoint file with Python
Your own Twitter client made with Django
Simple Slack API client made with Python
I made a character counter with Python
Creating a login screen with Django allauth
Let's make a simple language with PLY 1
Create a simple web app with flask
I made CORS custom middleware with Django
A note on enabling PostgreSQL with Django
I made a Hex map with Python
I made a life game with Numpy
I made a stamp generator with GAN
I made a roguelike game with Python
I made a configuration file with Python
I made a neuron simulator with Python
[Django] I made a field to enter the date with 4 digit numbers
I made a stamp substitute bot with line
Until you CI what you made with Django with Jenkins
Set up a simple HTTPS server with asyncio
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
I made a GUI application with Python + PyQt5
A memo that made a graph animated with plotly
How to develop a cart app with Django
Make a simple pixel art generator with Flask
Start Django in a virtual environment with Pipenv
Internationalization with django
I made a Twitter fujoshi blocker with Python ①
Procedure for creating a LineBot made with Python
A super introduction to Django by Python beginners! Part 5 I made a super simple diary application with a class-based general-purpose view
Start a simple Python web server with Docker
[Python] Build a Django development environment with Docker
[Python] I made a Youtube Downloader with Tkinter.
Build a Django environment with Vagrant in 5 minutes
Create a dashboard for Network devices with Django!