~ubuntu-branches/ubuntu/trusty/buxon/trusty

« back to all changes in this revision

Viewing changes to src/buxon/rdf/fetcher.py

  • Committer: Bazaar Package Importer
  • Author(s): Nacho Barrientos Arias
  • Date: 2011-08-28 11:36:14 UTC
  • mfrom: (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110828113614-wt8f10vp2z8vbs7s
Tags: 0.0.5-3
* debian/patches (+1 patches)
 - manpage-typos: s/a RDF/an RDF/

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
"""a cache service for sioc:Forum"""
21
21
 
 
22
import logging
22
23
from rdflib import URIRef
23
24
from rdflib.Graph import ConjunctiveGraph
24
25
from rdflib.sparql.sparqlGraph import SPARQLGraph
44
45
                              ('?post', DC['title'], '?title')])
45
46
            posts = Query.query(sparqlGr, select, where)
46
47
 
47
 
            print len(posts), 'posts:'
 
48
            logging.info(len(posts) + ' posts:')
48
49
 
49
50
            for post, title in posts:
50
 
                print post,
51
51
                try:
52
 
                    print title
 
52
                    logging.info(post + " " + title)
53
53
                except:
54
 
                    print '(bad formed title)'
 
54
                    logging.info(post + ' (bad formed title)')
55
55
 
56
56
        except Exception, details:
57
 
            print 'parsing exception:', str(details)
 
57
            logging.error('parsing exception:' + str(details))
58
58
            return None
59
59
 
60
60
 
66
66
        """
67
67
 
68
68
        graph = ConjunctiveGraph()
69
 
        print 'Getting mailing list data (', uri, ')...',
 
69
        logging.debug('Getting mailing list data (' + uri + ')...')
70
70
        graph.parse(uri)
71
 
        print 'OK, loaded', len(graph), 'triples'
 
71
        logging.info('OK, loaded ' + str(len(graph)) + ' triples')
72
72
 
73
 
        self.uri = self.__getForums(graph)[0]
74
 
        print 'Using ' + self.uri + ' sioc:Forum'
 
73
        forums = self.__getForums(graph)
 
74
        if forums.__len__() < 1:
 
75
            return None
 
76
        
 
77
        self.uri = forums[0]
 
78
        logging.info('Using ' + self.uri + ' sioc:Forum')
75
79
 
76
80
        if (self.pb != None):
77
81
            self.pb.progress()
88
92
        @param uri: uri to load
89
93
        """
90
94
 
91
 
        print 'Resolving reference to get additional data (', uri, ')...',
 
95
        logging.debug('Resolving reference to get additional data (' + uri + ')...')
92
96
        try:
93
97
            self.graph.parse(uri)
94
98
        except:
95
 
            print '\nAn exception ocurred parsing ' + uri
 
99
            logging.error('An exception ocurred parsing ' + uri)
96
100
            return
97
101
 
98
102
        if (self.pb != None):
103
107
        if (self.ptsw != None):
104
108
            self.ptsw.ping(uri)
105
109
 
106
 
        print 'OK, now', len(self.graph), 'triples'
 
110
        logging.debug('OK, now ' + str(len(self.graph)) + ' triples')
107
111
 
108
112
    def __getForums(self, graph):
109
113
        """
163
167
        try:
164
168
            self.graph = self.loadMailingList(self.uri)
165
169
        except Exception, details:
166
 
            print '\nAn exception ocurred parsing ' + self.uri + ': ' + str(details)
 
170
            logging.error('An exception ocurred parsing ' + self.uri + ': ' + str(details))
167
171
            self.bad = True
168
172
            return
169
173
 
170
 
        self.loadAdditionalData()
171
 
 
172
 
        #self.__listPosts()
 
174
        if self.graph == None:
 
175
            self.bad = True
 
176
            logging.error('None sioc:Forum founded on ' + self.uri)
 
177
        else:
 
178
            self.loadAdditionalData()
 
179
            #self.__listPosts()
173
180
 
174
181
        if (self.pb != None):
175
182
            self.pb.destroy()
176
183
 
177
184
        if (self.ptsw != None):
178
 
            print self.ptsw.stats()
 
185
            logging.debug(self.ptsw.stats())
179
186
 
180
187
        if self.bad:
181
188
            return None
182
189
        else:
183
 
            print 'Total triples loaded:', len(self.graph)
 
190
            logging.info('Total triples loaded: ' + str(len(self.graph)))
184
191
            return self.graph
185
192
 
186
193
    def __init__(self, base, ping, pb=None):