diff options
author | Santhosh Thottingal <santhosh.thottingal@gmail.com> | 2009-05-12 20:40:32 +0530 |
---|---|---|
committer | Santhosh Thottingal <santhosh.thottingal@gmail.com> | 2009-05-12 20:40:32 +0530 |
commit | f1182c8bc123e9b6690f3fbdc0021468e60ba05d (patch) | |
tree | 73acf5ce6f6f0a4046f587fdb28be4e97f49302a /silpa/modules/fortune/fortune.py | |
parent | ee0f42962618bb4d3b607cc18248957c72f18961 (diff) | |
download | Rachana.git-f1182c8bc123e9b6690f3fbdc0021468e60ba05d.tar.gz Rachana.git-f1182c8bc123e9b6690f3fbdc0021468e60ba05d.tar.xz Rachana.git-f1182c8bc123e9b6690f3fbdc0021468e60ba05d.zip |
Various fixes on silpa and new modules-Inexact search
Diffstat (limited to 'silpa/modules/fortune/fortune.py')
-rw-r--r-- | silpa/modules/fortune/fortune.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/silpa/modules/fortune/fortune.py b/silpa/modules/fortune/fortune.py index cf31aad..bc83b51 100644 --- a/silpa/modules/fortune/fortune.py +++ b/silpa/modules/fortune/fortune.py @@ -1,7 +1,7 @@ # Fortune # -*- coding: utf-8 -*- # -# Copyright © 2008 Santhosh Thottingal +# Copyright © 2009 Santhosh Thottingal <santhosh.thottingal@gmai.com> # Released under the GPLV3+ license import os,random @@ -13,24 +13,24 @@ class Fortune(SilpaModule): for line in infile: line=line.decode("utf-8") if line == "%\n": - yield result - result = [] + continue else: if(pattern==None): result.append(line) else: - if(line.find(pattern)==-1): + if(line.find(pattern)>0): result.append(line) if result: - yield result + return result + - def fortune_ml(self, word): - filename="./modules/fortune/database/fortune-ml" + def fortune_ml(self, pattern): + filename = os.path.join(os.path.dirname(__file__), 'database/fortune-ml') """ Pick a random fortune from a file """ - for index, fortune in enumerate(self.fortunes(file(filename),None)): - if random.random() < (1.0 / (index+1)): - chosen = fortune - + fortunes_list=self.fortunes(file(filename),pattern) + chosen="" + if fortunes_list: + chosen= random.choice(fortunes_list) return "".join(chosen) def process(self, form): @@ -46,9 +46,10 @@ class Fortune(SilpaModule): """ if(form.has_key('input_text')): text = form['input_text'].value .decode('utf-8') + response=response % text else: - text="" - response=response % text + text= None + response=response % "" result = self.fortune_ml(text) response = response+"<h2>Random Quote</h2></hr>" response = response+"<b>"+result+"</b>" |