# Fortune # -*- coding: utf-8 -*- # # Copyright © 2009 Santhosh Thottingal # Released under the GPLV3+ license import os,random from common import * class Fortune(SilpaModule): def fortunes(self,infile,pattern=None): """ Yield fortunes as lists of lines """ result = [] for line in infile: line=line.decode("utf-8") if line == "%\n": continue else: if(pattern==None): result.append(line) else: if(line.find(pattern)>0): result.append(line) if result: return result @ServiceMethod def fortune_ml(self, pattern=None): filename = os.path.join(os.path.dirname(__file__), 'database/fortune-ml') """ Pick a random fortune from a file """ fortunes_list=self.fortunes(file(filename),pattern) chosen="" if fortunes_list: chosen= random.choice(fortunes_list) return "".join(chosen) def process(self, form): htmlform = """

Fortune Malayalam

Enter the text for getting a random quote with the given string in the below text area.


""" response=htmlform text=None if(form.has_key('input_text')): text = form['input_text'].value .decode('utf-8') response =response % text else: response=htmlform % s result = self.fortune_ml(text) response =response+ "

Random Quote

" response = response+""+result+"" return response def get_form(): htmlform = """

Fortune Malayalam

Enter the text for getting a random quote with the given string in the below text area.


""" def get_module_name(self): return "Fortune Malayalam" def get_info(self): return "Get/Search a random Malayalam quote " def getInstance(): return Fortune()