some cleanups i promised
authorBryan Clark <clarkbw@gnome.org>
Tue, 17 Feb 2009 23:40:26 -0800
changeset 46 8ee054c5fcc6120101915d69853487fcd0993ae8
parent 45 3f9d0c9550d46bc05e5dbdcb34536cc59c4a30e0
child 47 ba518ea3ee85f7798835c50def4a433f1f9a6106
push id1
push userroot
push dateWed, 08 Apr 2009 01:46:05 +0000
some cleanups i promised actually check if the msg.id already exists actually use the contact if we already have it
server/python/junius/gettweets.py
--- a/server/python/junius/gettweets.py
+++ b/server/python/junius/gettweets.py
@@ -22,27 +22,32 @@ class JuniusAccount(object):
         self.re_tags = re.compile(r'#(\w+)')
 
     def create_account_if_necessary(self):
         self.twitter_user = self.twitter_account.GetUser(self.account_def.username)
         self.author = self.create_contact_if_necessary(self.account_def.username, self.twitter_user)
 
     def create_contact_if_necessary(self, username, account=None):
         if account is None:
+            # after getting this info we should really be putting lots of it into
+            # the contact database.  Location, Picture, Web Site
             account = self.twitter_account.GetUser(username)
 
         contacts = model.Contact.by_identity(self.dbs.contacts,
                                              key=['twitter', username])
         if len(contacts) == 0:
             # the contact does't exist, create it
             contact = model.Contact(
                 name=account.name,
                 identities=[{'kind': 'twitter', 'value': username }]
             )
             contact.store(self.dbs.contacts)
+        else:
+            contact = [model.Contact.load(self.dbs.contacts,contact.value['_id']) for contact in contacts.rows][0]
+
         return contact
 
     def sync(self):
         print '***** Fetching tweets'
         
         # -- find out about what message id's we already know about
         # this is really just the most primitive synchronization logic
         #  available!  but that's okay.
@@ -54,17 +59,17 @@ class JuniusAccount(object):
         for row in model.Message.by_header_id(self.dbs.messages).rows:
             print row
             known_uids.add(row.key)
         
         processed = 0
         skipped = 0
 
         for message in self.twitter_account.GetUserTimeline():
-            if message.id not in known_uids:
+            if str(message.id) not in known_uids:
                 self.grok_message(self.author, message)
                 processed += 1
             else:
                 skipped += 1
         print '  processed', processed, 'skipped', skipped
     
     def grok_message(self, author, imsg):
         involves = self.grok_involves(author, imsg)