blog datafeed parser returns stats
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Tue, 28 Sep 2010 15:39:21 +0200
changeset 235 e41012cd4127
parent 234 6404e2ef309b
child 236 eb03943228a0
blog datafeed parser returns stats
sobjects.py
--- a/sobjects.py	Tue Sep 28 15:37:10 2010 +0200
+++ b/sobjects.py	Tue Sep 28 15:39:21 2010 +0200
@@ -179,15 +179,18 @@
         entity_type = 'BlogEntry'
 
         def process(self, url):
+            stats = {'update':0, 'creation':0}
             for item in self.parse(url):
                 author = item.pop('author', None)
                 avatar = item.pop('avatar', None)
                 euri = self.sget_entity('ExternalUri', uri=item.pop('uri'))
                 if euri.same_as:
-                    sys.stdout.write('.')
+                    #sys.stdout.write('.')
+                    stats['update'] += 1
                     post = self.update_blogpost(euri.same_as[0], item)
                 else:
-                    sys.stdout.write('+')
+                    #sys.stdout.write('+')
+                    stats['creation'] += 1
                     post = self.create_blogpost(item, euri)
                 if author:
                     account = self.sget_entity('UserAccount', name=author)
@@ -195,7 +198,8 @@
                     if avatar:
                         auri = self.sget_entity('ExternalUri', uri=avatar)
                         self.sget_relation(account.eid, 'has_avatar', auri.eid)
-                sys.stdout.flush()
+                #sys.stdout.flush()
+            return stats
 
         def create_blogpost(self, item, uri):
             entity = self._cw.create_entity(self.entity_type, **item)