• Stars
    star
    638
  • Rank 70,537 (Top 2 %)
  • Language
    Python
  • License
    BSD 2-Clause "Sim...
  • Created over 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python module to generate ATOM feeds, RSS feeds and Podcasts.

Feedgenerator

Build Status Test Coverage Status

This module can be used to generate web feeds in both ATOM and RSS format. It has support for extensions. Included is for example an extension to produce Podcasts.

It is licensed under the terms of both, the FreeBSD license and the LGPLv3+. Choose the one which is more convenient for you. For more details have a look at license.bsd and license.lgpl.

More details about the project:

Installation

Prebuild packages

If your distribution includes this project as package, like Fedora Linux does, you can simply use your package manager to install the package. For example:

$ dnf install python3-feedgen

Using pip

You can also use pip to install the feedgen module. Simply run:

$ pip install feedgen

Create a Feed

To create a feed simply instantiate the FeedGenerator class and insert some data:

from feedgen.feed import FeedGenerator
fg = FeedGenerator()
fg.id('http://lernfunk.de/media/654321')
fg.title('Some Testfeed')
fg.author( {'name':'John Doe','email':'[email protected]'} )
fg.link( href='http://example.com', rel='alternate' )
fg.logo('http://ex.com/logo.jpg')
fg.subtitle('This is a cool feed!')
fg.link( href='http://larskiesow.de/test.atom', rel='self' )
fg.language('en')

Note that for the methods which set fields that can occur more than once in a feed you can use all of the following ways to provide data:

  • Provide the data for that element as keyword arguments
  • Provide the data for that element as dictionary
  • Provide a list of dictionaries with the data for several elements

Example:

fg.contributor( name='John Doe', email='[email protected]' )
fg.contributor({'name':'John Doe', 'email':'[email protected]'})
fg.contributor([{'name':'John Doe', 'email':'[email protected]'}, ...])

Generate the Feed

After that you can generate both RSS or ATOM by calling the respective method:

atomfeed = fg.atom_str(pretty=True) # Get the ATOM feed as string
rssfeed  = fg.rss_str(pretty=True) # Get the RSS feed as string
fg.atom_file('atom.xml') # Write the ATOM feed to a file
fg.rss_file('rss.xml') # Write the RSS feed to a file

Add Feed Entries

To add entries (items) to a feed you need to create new FeedEntry objects and append them to the list of entries in the FeedGenerator. The most convenient way to go is to use the FeedGenerator itself for the instantiation of the FeedEntry object:

fe = fg.add_entry()
fe.id('http://lernfunk.de/media/654321/1')
fe.title('The First Episode')
fe.link(href="http://lernfunk.de/feed")

The FeedGenerator's method add_entry(...) will generate a new FeedEntry object, automatically append it to the feeds internal list of entries and return it, so that additional data can be added.

Extensions

The FeedGenerator supports extensions to include additional data into the XML structure of the feeds. Extensions can be loaded like this:

fg.load_extension('someext', atom=True, rss=True)

This example would try to load the extension “someext” from the file ext/someext.py. It is required that someext.py contains a class named “SomextExtension” which is required to have at least the two methods extend_rss(...) and extend_atom(...). Although not required, it is strongly suggested to use BaseExtension from ext/base.py as superclass.

load_extension('someext', ...) will also try to load a class named “SomextEntryExtension” for every entry of the feed. This class can be located either in the same file as SomextExtension or in ext/someext_entry.py which is suggested especially for large extensions.

The parameters atom and rss control if the extension is used for ATOM and RSS feeds respectively. The default value for both parameters is True, meaning the extension is used for both kinds of feeds.

Example: Producing a Podcast

One extension already provided is the podcast extension. A podcast is an RSS feed with some additional elements for ITunes.

To produce a podcast simply load the podcast extension:

from feedgen.feed import FeedGenerator
fg = FeedGenerator()
fg.load_extension('podcast')
...
fg.podcast.itunes_category('Technology', 'Podcasting')
...
fe = fg.add_entry()
fe.id('http://lernfunk.de/media/654321/1/file.mp3')
fe.title('The First Episode')
fe.description('Enjoy our first episode.')
fe.enclosure('http://lernfunk.de/media/654321/1/file.mp3', 0, 'audio/mpeg')
...
fg.rss_str(pretty=True)
fg.rss_file('podcast.xml')

If the FeedGenerator class is used to load an extension, it is automatically loaded for every feed entry as well. You can, however, load an extension for a specific FeedEntry only by calling load_extension(...) on that entry.

Even if extensions are loaded, they can be temporarily disabled during the feed generation by calling the generating method with the keyword argument extensions set to False.

Custom Extensions

If you want to load custom extensions which are not part of the feedgen package, you can use the method register_extension instead. You can directly pass the classes for the feed and the entry extension to this method meaning that you can define them everywhere.

Testing the Generator

You can test the module by simply executing:

$ python -m feedgen

If you want to have a look at the code for this test to have a working code example for a whole feed generation process, you can find it in the __main__.py.

More Repositories

1

nodejs-irc-webclient

A simple IRC-Webclient based on node.js and socket.io.
JavaScript
22
star
2

surf

surf is a simple web browser based on WebKit/GTK+. This repository is a clone of http://git.suckless.org/surf
C
18
star
3

librply

RPly: ANSI C Library for PLY file format input and output
C
18
star
4

ptsviewer

ptsviewer is a simple OpenGL based viewer for pointclouds stored in pts files. Both colored and non colored pointclouds are supported
C
12
star
5

opencast-rpm-specs

Spec files for creating RPM packages for Opencast and its dependencies.
11
star
6

avermedia-game-capture-hd-ii-reverse-engineering

Documentation and code storage for the reverse engeneering of the AVerMedia Game Capture HD II. In particular this is a documentation of the RESTful web interface.
9
star
7

erlang-datetime

Erlang module providing import and export functions for datetime strings specified by RFC822/RFC2822/RSS to erlang datetime tuples
Erlang
9
star
8

intellij-idea-community-rpm

Spec files for building IDEA community edition bundles
Shell
8
star
9

matrix-notification

GitHub action to send a notification via Matrix
TypeScript
4
star
10

thesis-latex

Several LaTeX document classes and packages
TeX
4
star
11

lf-portal

A video portal for Opencast Matterhorn and compatible systems.
Python
4
star
12

bitbucket-pullrequest-filter

Filter BitBucket pull requests on a simple web interface
Python
3
star
13

minio-rpm

Files for automatically building RPMs for MinIO
Shell
3
star
14

pcl_marching_cubes_demo

Demonstration of the PCL Marching Cubes implementation.
C++
3
star
15

docms

A lightweight document management system using mod_python.
Python
2
star
16

g810-led-rpm

RPM specs for the g810-led project
2
star
17

libpts

libpts: library for reading pointclouds stored in pts files.
C
2
star
18

3d-models

A collection of 3d models designed for printing
G-code
2
star
19

setup-lxc-container

Setup an LXC Container on GitHub Actions
TypeScript
2
star
20

go-scan-http

Fast HTTP network scanner
Go
2
star
21

ansible-nginx-opencast-letsencrypt

Ansible scripts to set-up Nginx as reverse proxy for Opencast with Let's Encrypt certificate
Vim Script
2
star
22

audiobookshelf-rpm

RPM Package Repository for Audiobookshelf
2
star
23

docker-scp

Docker container to deploying files via scp
Shell
1
star
24

chrome-selfshorten-extension

JavaScript
1
star
25

system-configuration

Some important system and program configuration files.
Vim Script
1
star
26

pve-dns

Proxmox Virtual Environment: DNS/DHCP Server for Internal Network
1
star
27

geoip-gateway

GeoIP based service gateway.
Python
1
star
28

activemq-dist-rpm

RPM specs for ActiveMQ's binary distribution
1
star
29

matterhorn-scripts

Start, stop and service scripts for Opencast Matterhorn including service configuration
Shell
1
star
30

libkinect_aux

Library which provides easy acces to Kinect accelerator, leds and motor.
C
1
star
31

ansible-nginx-opencast-http

Ansible scripts to set-up Nginx as reverse proxy for Opencast (HTTP only)
Nginx
1
star
32

colorize

Transfer color information from one to another pointcloud.
C++
1
star
33

automated-quay.io-deployment

Tool to automate regular deployments on Quay.io using Trabis CI
Shell
1
star
34

texlive-fake

RPM Spec file to fake a texlive installation on Fedora (if you install Texlive from CTAN)
1
star
35

andCA

AndCA is a a small Android application to capture videos and ingest them into Matterhorn.
Java
1
star
36

opencast-engage-player-zoom

A zoomable version of the opencast engage player.
JavaScript
1
star
37

lernfunk

Lernfunk ermöglicht die Distribution von Vorlesungsaufzeichnungen und Podcasts über die in einer Hochschule vorhandenen Distributionskanäle wie Lernmanagment System, Wiki, Blogs oder Hompages von Dozenten und Kursen, liefert auch Werkzeuge um neue Kanäle wie zum Beispiel iTunes U zu erschließen.
PHP
1
star
38

lernfunk3

The Lernfunk media aggregation, enrichment and distribution system can import media of any type, administer it, add metadata and export these media. It is centered around a Core REST webservice. Thus it is easy distributable and extensible.
Python
1
star