~sdague/onehundredscopes/unity-lens-pidgin

« back to all changes in this revision

Viewing changes to src/unity-lens-pidgin

  • Committer: Sean Dague
  • Date: 2012-05-14 23:29:10 UTC
  • Revision ID: sean@dague.net-20120514232910-fie9a0qqrsne4wz7
make sorting and scoring of buddies make more sense 

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import datetime
29
29
import urlparse
30
30
 
 
31
from operator import attrgetter
 
32
 
31
33
import pprint
32
34
import xml.etree.ElementTree
33
35
 
108
110
 
109
111
class Buddy:
110
112
    icon = None
 
113
    score = 1000
111
114
 
112
115
    def __init__(self, bid, account, name, alias):
113
116
        self.id = bid
162
165
    def search(self,  string):
163
166
        buddies = self._gather_buddies()
164
167
        results = []
165
 
        active = []
166
 
        rest = []
 
168
 
167
169
        for buddy in buddies:
168
 
            if ((buddy.name.lower().find(string) >=0) or
169
 
                (buddy.alias.lower().find(string) >=0) ):
 
170
            scorename = buddy.name.split('@')[0].lower().find(string)
 
171
            scorealias = buddy.alias.lower().find(string)
 
172
            if ((scorename >= 0) or (scorealias >= 0)):
 
173
                if scorename < 0:
 
174
                    scorename = 100
 
175
                if scorealias < 0:
 
176
                    scorealias = 100
 
177
 
170
178
                self.fill(buddy)
171
179
 
172
180
                if self.is_active(buddy):
173
 
                    active.append(buddy)
 
181
                    buddy.score = 0
174
182
                else:
175
 
                    rest.append(buddy)
176
 
 
177
 
        active.extend(rest)
178
 
        return active
 
183
                    buddy.score = 100
 
184
 
 
185
                buddy.score += min(scorename, scorealias)
 
186
                results.append(buddy)
 
187
 
 
188
        return sorted(results, key=attrgetter('score'))
179
189
 
180
190
 
181
191
if __name__ == "__main__":