Skip to main content

This parser is intended for RSS/XML that does not communicate the standard rfc5005

Project description

## Django rss/xml parser(django_rss_xml)
This parse is intended for XML / RSS, which does not conform to the standard:

for standard RSS

### install

pip install django-rss_xml-parser

add to settings


### usage
1) create mappers
afisha = {
"elements": "event",
"items_to": {"id__attr": "event_id", "title": "title", "text": "text"}

yandex = {
"elements": "item",
"items_to": {"title": "title", "description": "text"}

kassir = {"elements": "item"}

2) create models

from django.db import models
from django.utils.translation import ugettext as _
from django.utils.timezone import now

class Tags(models.Model):
tag = models.CharField(max_length=50, verbose_name=_("Tag"))

class RssModel(models.Model):
event_id = models.IntegerField(verbose_name=_("event ID"), null=True)
title = models.CharField(max_length=550, verbose_name=_("Title"), null=True)
text = models.TextField(verbose_name=_("Description"), null=True)
time = models.DateTimeField(verbose_name=_("Time and Date"), default=now, blank=True)
tags = models.ForeignKey(Tags, on_delete=models.CASCADE, verbose_name=_('Tags'), null=True, blank=True)


3) add in view
rss_rules = {"uri": 'rss/data/afisha.xml', "rule": afisha}
rss_rules = {"uri": '', "rule": yandex}
from django.views.generic import TemplateView
from .rss_mapper import kassir, afisha, yandex
from django_rss_xml.rss_parser import RSS
from .models import RssModel

class RSSView(TemplateView, RSS):
template_name = "rss/rss.html"
rss_rules = {"uri": 'rss/data/afisha.xml', "rule": afisha}

def get_context_data(self, **kwargs):
context = super(RSSView, self).get_context_data(**kwargs)
context['rss_obj'] = self.rss_to_object()
context['rss_m'] = self.rss_to_model(RssModel)
return context

## Running tests

python test django_rss_xml

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-rss_xml-parser-0.4.tar.gz (5.1 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page