source: subversion/applications/routing/pyroute-dev/poi_geoRss.py @ 18454

Last change on this file since 18454 was 18454, checked in by buerste, 10 years ago

-further updates of spaces to tabs

  • Property svn:keywords set to Rev
File size: 2.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""
5"""
6
7__version__ = "$Rev: 18454 $"
8__license__ = """This program is free software: you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation, either version 3 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program. If not, see <http://www.gnu.org/licenses/>."""
20_debug = 0
21
22
23from poi_base import *
24import feedparser
25
26class geoRss(poiModule):
27        def __init__(self, modules, filename):
28                poiModule.__init__(self, modules)
29                f = open(filename,"r")
30                try:
31                        for line in f:
32                                url = line.rstrip()
33                                if(url):
34                                        feed = feedparser.parse(url)
35                                        name = feed.feed.title
36                                        self.add(name, feed)
37                finally:
38                        f.close()
39                print self.groups
40
41        def getLatLon(self,item):
42                # Try getting the "point = lat lon"
43                try:
44                        lat,lon = [float(ll) for ll in item['point'].split(" ")]
45                        return(lat,lon,True)
46                except KeyError:
47                        pass
48                except ValueError:
49                        pass
50
51                # Try getting the "pos = lat lon"
52                try:
53                        lat,lon = [float(ll) for ll in item['pos'].split(" ")]
54                        return(lat,lon,True)
55                except KeyError:
56                        pass
57                except ValueError:
58                        pass
59
60                # Try getting the "geo:lat = lat, geo:lon = lon"
61                try:
62                        lat = float(item['geo_lat'])
63                        lon = float(item['geo_lon'])
64                        return(lat,lon,True)
65                except KeyError:
66                        pass
67
68                return(0,0,False)
69
70        def add(self, name, feed):
71                group = poiGroup(name)
72                count = 0
73                for item in feed.entries:
74                        lat, lon, valid = self.getLatLon(item)
75                        if(valid):
76                                x = poi(lat,lon)
77                                x.title = item.title
78                                group.items.append(x)
79                                count = count + 1
80                #print "Added %d items from %s" % (count, name)
81
82                self.groups.append(group)
83
84if __name__ == "__main__":
85        g = geoRss('../Setup/feeds.txt')
86        name = g.groups.keys()[0]
87        print g.groups[name].items
88
Note: See TracBrowser for help on using the repository browser.