def BuildRecommendation(self, lRules): """Build recommendations from list of returned rules. lRules is a list of lists of rules Rank etc. in this method. """ lClicks = [] for lAnswers in lRules: for rule in lAnswers: click = cClick.cClick() tUrl = rule.GetConsequent() # we don't want double hits hasit = 0 for c in lClicks: if c.HasUrl(tUrl): hasit = 1 if hasit == 0: click.SetClick(tUrl, 'text/html', '200', '4625', \ urlparse.urlunparse(tUrl), '') lClicks.append(click) # recommendation, list of clicks return lClicks
def SetElements(self, lEls): """Read elements into internal representation. lEls -- elements <click content_type="text/html" referer="http://harth.org/" status="200" timestamp="11:49:34" title="das ist eine html seite">http://slashdot.org/</click></session> """ for el in lEls: click = cClick.cClick() click.SetElement(el) self.lData.append(click)
def test(): """Built-in test method for this class.""" sess = cSession() sess.OpenFile('/tmp/foo.xml') urltuple = urlparse.urlparse("http://slashdot.org") urltuple2 = urlparse.urlparse("http://harth.org") click = cClick.cClick() click.SetClick(urltuple, 'text/html', '200', '134352234', 'das ist eine html seite', urltuple2) click2 = cClick.cClick() click2.SetClick(urltuple2, 'text/html', '200', '21312321', 'das ist noch eine html seite', urltuple2) sess.Print() sess.AddClick(click) # sess.AddClick(click2) sess.Print() sess.file.Print() #sess.DeleteURL(urltuple2) sess.CloseFile() sess.file.Print() return sess2 = cSession() sess2.OpenFile('/tmp/foo.xml') sess2.AddClick(click2) sess2.Print() sess2.file.Print() sess2.CloseFile()
def handle(self): """Get called by cProxyCore for each request""" # default: implicit click self.m_bIsExplicit = 0 try: # Parse request host, port, request = self.ParseRequest() # Check if this is a command for iOwl if self.IsCommand(host): # pass request to pGuiInterface self.HandleCommand() # command finished. close socket self.connection.close() return # init title string self.ClickHtml = '' # Build Timestamp for click self.ClickTimestamp = time.time() # Connect to host and get handles server, client = self.Connect(host, port) # Send request to server self.SendRequest(client, request) # Handle response try: self.HandleResponse(server) # except IOError: except IOError: self.connection.close() return except socket.error: # request could not be fulfilled, most probably because user interrupted his browser # close socket self.connection.close() return # close socket self.connection.close() # finished request # Now pass click to pClickstreamINterface, if it is an explicit one if self.m_bIsExplicit: # Add Click to Clickstream ClickstreamInterface = pManager.manager.GetClickstreamInterface() pManager.manager.DebugStr('cProxyHandler '+ __version__ +': Detected explicit click. Url: '+str(self.ClickUrl)+' Status: '+str(self.ClickStatus), 3) click = cClick.cClick() click.SetClick(urlparse.urlparse(self.ClickUrl), \ self.ClickContent, self.ClickStatus, \ self.ClickTimestamp, '', \ urlparse.urlparse(self.ClickReferer)) ClickstreamInterface.AddClick(click, self.ClickHtml)