~doctormo/gnome-wallchanger/trunk

« back to all changes in this revision

Viewing changes to gwc/plugins/deviant.py

  • Committer: Martin Owens (DoctorMO)
  • Date: 2009-10-11 19:32:33 UTC
  • Revision ID: doctormo@gmail.com-20091011193233-15p70kim7zsjyhqx
Add new modules for ver 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright 2009, Martin Owens.
 
3
#
 
4
# This program is free software: you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation, either version 3 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
#
 
17
"""
 
18
List images from a deviantArt search.
 
19
"""
 
20
 
 
21
from gwc.base import add_lister
 
22
from gwc.rssbase import rssBase
 
23
 
 
24
class deviantLister(rssBase):
 
25
    """DeviantArt wallpaper search listing (via RSS)"""
 
26
    name      = 'deviant'
 
27
    variables = [ 'folder', 'search' ]
 
28
 
 
29
    def __init__(self, folder, search):
 
30
        self._search = unicode(search)
 
31
        rssLister.__init__( self, folder, self.rssurl() )
 
32
 
 
33
    def rssurl(self):
 
34
        """Return the URL to get a DeviantArt search RSS result"""
 
35
        return "http://backend.deviantart.com/rss.xml?q=in%3Acustomization/wallpaper%20sort%3Atime%20"+self._search+"&type=deviation"
 
36
 
 
37
    def getItem(self, url):
 
38
        """Return a single item from this RSS result"""
 
39
        da_page = self.get_url(url)
 
40
        if da_page:
 
41
            f = '"fullview":{'
 
42
            a = da_page.find(f)
 
43
            if a > -1:
 
44
                a += len(f)
 
45
                b = da_page.find('}', a)
 
46
                meta = {}
 
47
                for d in da_page[a:b].replace('"','').replace('\\','').split(','):
 
48
                    key,val = d.split(':',1)
 
49
                    meta[key] = val
 
50
                return lister.getItem(self, meta['src'])
 
51
        return None
 
52
 
 
53
 
 
54