#NEWLINE# def _fav_site_calc( self , user ) : #NEWLINE# #INDENT# '\n            Helper to compute what the most commonly used\n            site is for a given set of history items.\n            Returns a url (domain) that is computed\n            to be the favorite and the associated favicon\n        ' #NEWLINE# item_meta = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# ( hist_type , history_items ) = history_search ( user , sort = 'time' , filter = '' , username = user . username ) #NEWLINE# if ( not history_items ) : #NEWLINE# #INDENT# ( fav_data , created ) = FavData . objects . get_or_create ( user = user ) #NEWLINE# self . stdout . write ( ( 'Updated user %s, no history.\n' % user . username ) ) #NEWLINE# return #NEWLINE# #UNINDENT# for item in history_items : #NEWLINE# #INDENT# domain = item . domain #NEWLINE# if ( domain in item_meta ) : #NEWLINE# #INDENT# data = item_meta [ domain ] #NEWLINE# data [ 'count' ] += 1 #NEWLINE# data [ 'total_time' ] += item . total_time #NEWLINE# item_meta [ domain ] = data #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# item_meta [ domain ] = { #NEWLINE# #INDENT# 'favicon' : item . favicon_url , #NEWLINE# 'count' : 1 , #NEWLINE# 'total_time' : item . total_time , #NEWLINE# 'domain' : domain , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# #UNINDENT# max_count = 0 #NEWLINE# max_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( k , v ) in item_meta . items ( ) : #NEWLINE# #INDENT# if ( v [ 'count' ] > max_count ) : #NEWLINE# #INDENT# max_count = v [ 'count' ] #NEWLINE# max_dict = v #NEWLINE# #UNINDENT# #UNINDENT# self . stdout . write ( ( 'Updated user %s, favorite: %s\n' % ( user . username , max_dict [ 'domain' ] ) ) ) #NEWLINE# ( fav_data , created ) = FavData . objects . get_or_create ( user = user ) #NEWLINE# fav_data . domain = max_dict [ 'domain' ] #NEWLINE# fav_data . favicon_url = max_dict [ 'favicon' ] #NEWLINE# fav_data . total_time = max_dict [ 'total_time' ] #NEWLINE# fav_data . visit_count = max_dict [ 'count' ] #NEWLINE# fav_data . save ( )