Author: dmeyer Date: Sun Sep 16 06:19:39 2007 New Revision: 2820 Log: add header
Modified: trunk/beacon/src/server/feedmanager/__init__.py trunk/beacon/src/server/feedmanager/core.py trunk/beacon/src/server/feedmanager/manager.py trunk/beacon/src/server/feedmanager/rss.py Modified: trunk/beacon/src/server/feedmanager/__init__.py ============================================================================== --- trunk/beacon/src/server/feedmanager/__init__.py (original) +++ trunk/beacon/src/server/feedmanager/__init__.py Sun Sep 16 06:19:39 2007 @@ -1,58 +1,105 @@ -# ################################################################## -# Brain Dump +# -*- coding: iso-8859-1 -*- +# ----------------------------------------------------------------------------- +# feedmanager - RPC entry point to the feedmanager +# ----------------------------------------------------------------------------- +# $Id$ +# +# ----------------------------------------------------------------------------- +# kaa.beacon.server - A virtual filesystem with metadata +# Copyright (C) 2007 Dirk Meyer +# +# First Edition: Dirk Meyer <[EMAIL PROTECTED]> +# Maintainer: Dirk Meyer <[EMAIL PROTECTED]> +# +# Please see the file AUTHORS for a complete list of authors. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MER- +# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# ----------------------------------------------------------------------------- +# +# TODO # # - Improve RSS feed for better video and audio feed support # https://feedguide.participatoryculture.org/front -# - Flickr image feed # - Torrent downloader (needed for some democracy feeds) -# - Add more item metadata (e.g. download thumbnail/image) -# - Feed configuration: -# o always download / download on demand / play from stream -# o how much entries should be show -# o keep entries on hd (while in feed / while not watched / up to x) # - Add parallel download function -# - Add feed as 'file' to kaa.beacon making it possible to merge -# feed entries and real files. -# o does it belong into beacon? -# o is it an extra kaa module with beacon plugin? -# o daemon to keep feeds in beacon up-to-date +# - make sure update() is called only once at a time +# - add username / password stuff to rpc or config +# +# External plugins +# - Flickr image feed +# - Gallery support +# - Youtube / Stage6 plugin # # ################################################################## +# kaa imports import kaa.rpc +# feedmanager imports import manager import core import rss @kaa.rpc.expose('feeds.update') def update(id=None): + """ + Update feed with given id or all if id is None + """ if id == None: return manager.update() for c in manager.list_feeds(): if id == c.id: return c.update() return False - + + @kaa.rpc.expose('feeds.list') def list_feeds(): + """ + List all feeds. Returns a list of dicts. + """ feeds = [] for c in manager.list_feeds(): feeds.append(c.get_config()) return feeds + @kaa.rpc.expose('feeds.add') def add_feed(url, destdir, download=True, num=0, keep=True): + """ + Add a new feed. + """ return manager.add_feed(url, destdir, download, num, keep).get_config() + @kaa.rpc.expose('feeds.remove') def remove_feed(id): + """ + Remove feed with given id. + """ for c in manager.list_feeds(): if id == c.id: manager.remove_feed(c) return True return False + def set_database(database): + """ + Set the database. Called by server at startup. + """ core.Feed._db = database manager.init() Modified: trunk/beacon/src/server/feedmanager/core.py ============================================================================== --- trunk/beacon/src/server/feedmanager/core.py (original) +++ trunk/beacon/src/server/feedmanager/core.py Sun Sep 16 06:19:39 2007 @@ -1,6 +1,37 @@ +# -*- coding: iso-8859-1 -*- +# ----------------------------------------------------------------------------- +# core.py - Feedmanager Core providing Feed and Entry +# ----------------------------------------------------------------------------- +# $Id$ +# +# ----------------------------------------------------------------------------- +# kaa.beacon.server - A virtual filesystem with metadata +# Copyright (C) 2007 Dirk Meyer +# +# First Edition: Dirk Meyer <[EMAIL PROTECTED]> +# Maintainer: Dirk Meyer <[EMAIL PROTECTED]> +# +# Please see the file AUTHORS for a complete list of authors. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MER- +# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# ----------------------------------------------------------------------------- + +# python imports import sys import os -import re import md5 import urllib import urllib2 @@ -49,7 +80,7 @@ _db = None NEXT_ID = 0 - + def __init__(self, url, destdir): self.url = url self.dirname = destdir @@ -62,7 +93,7 @@ os.makedirs(destdir) self.id = Feed.NEXT_ID Feed.NEXT_ID += 1 - + def configure(self, download=True, num=0, keep=True): """ @@ -87,7 +118,7 @@ download = self._download, num = self._num, keep = self._keep) - + def _readxml(self, node): """ Read XML node with feed configuration and cache. @@ -205,7 +236,7 @@ if not os.path.isfile(filename): log.error('error fetching', entry.url) continue - + if os.path.isfile(filename): item = self._db.query(filename=filename) if not item.scanned(): @@ -247,7 +278,7 @@ if self._keep or self._download: # only delete links in the filesystem return - + # get directory information beacondir = self._db.query(filename=self.dirname) allurls = [ e[0] for e in self._entries ] Modified: trunk/beacon/src/server/feedmanager/manager.py ============================================================================== --- trunk/beacon/src/server/feedmanager/manager.py (original) +++ trunk/beacon/src/server/feedmanager/manager.py Sun Sep 16 06:19:39 2007 @@ -1,7 +1,40 @@ +# -*- coding: iso-8859-1 -*- +# ----------------------------------------------------------------------------- +# manager.py - Manage all feeds +# ----------------------------------------------------------------------------- +# $Id$ +# +# ----------------------------------------------------------------------------- +# kaa.beacon.server - A virtual filesystem with metadata +# Copyright (C) 2007 Dirk Meyer +# +# First Edition: Dirk Meyer <[EMAIL PROTECTED]> +# Maintainer: Dirk Meyer <[EMAIL PROTECTED]> +# +# Please see the file AUTHORS for a complete list of authors. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MER- +# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# ----------------------------------------------------------------------------- + +# python imports import os import logging from xml.dom import minidom +# kaa imports import kaa.notifier from kaa.strutils import unicode_to_str @@ -63,7 +96,7 @@ _feeds.remove(feed) feed.remove() save() - + def save(): """ @@ -79,7 +112,7 @@ f.write(doc.toprettyxml()) f.close() - + def init(): """ Load cached feeds from disc. @@ -95,7 +128,7 @@ feed._readxml(c) _feeds.append(feed) return - + if not os.path.isfile(CACHE): return Modified: trunk/beacon/src/server/feedmanager/rss.py ============================================================================== --- trunk/beacon/src/server/feedmanager/rss.py (original) +++ trunk/beacon/src/server/feedmanager/rss.py Sun Sep 16 06:19:39 2007 @@ -1,10 +1,43 @@ -import re +# -*- coding: iso-8859-1 -*- +# ----------------------------------------------------------------------------- +# rss.py - RSS Feed implementation +# ----------------------------------------------------------------------------- +# $Id$ +# +# ----------------------------------------------------------------------------- +# kaa.beacon.server - A virtual filesystem with metadata +# Copyright (C) 2007 Dirk Meyer +# +# First Edition: Dirk Meyer <[EMAIL PROTECTED]> +# Maintainer: Dirk Meyer <[EMAIL PROTECTED]> +# +# Please see the file AUTHORS for a complete list of authors. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MER- +# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# ----------------------------------------------------------------------------- + +# python imports import time import logging import urllib2 +# kaa imports import kaa.notifier +# feedmanager imports import feedparser as _feedparser import core @@ -14,12 +47,21 @@ @kaa.notifier.execute_in_thread() def feedparser(url): + """ + feedparser.parse wrapper in a thread. + """ return _feedparser.parse(urllib2.urlopen(url)) + class Feed(core.Feed): + """ + RSS Feed. + """ def __iter__(self): - # get feed in a thread + """ + Iterate over feed entries. + """ feed = feedparser(self.url) yield feed feed = feed.get_result() @@ -59,7 +101,7 @@ metadata['timestamp'] = int(time.mktime(t)) except ValueError: log.error('bad "updated" string: %s', timestamp) - + if 'itunes_duration' in f.keys(): duration = 0 for p in f.itunes_duration.split(':'): @@ -69,7 +111,7 @@ metadata['description']=f.summary if 'title' in f.keys(): metadata['title'] = f.title - + if 'enclosures' in f.keys(): # FIXME: more details than expected if len(f.enclosures) > 1: ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Freevo-cvslog mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/freevo-cvslog
