예제 #1
0
    def __init__(self, JID, Password):
        """ Create a new bot. Connect to the server and log in. """

        # connect...
        jid = xmpp.JID(JID)
        self.connection = xmpp.Client(jid.getDomain(), debug=[])
        self.en_ml_db = None
        result = self.connection.connect()

        if result is None:
            raise ConnectionError

        # authorize
        result = self.connection.auth(jid.getNode(), Password)

        if result is None:
            raise AuthorizationError

        self.connection.RegisterHandler('presence', self.presenceHandler)
        self.connection.RegisterHandler('message', self.messageHandler)
        # ...become available
        self.connection.sendInitPresence()
        # presence
        #self.connection.sendInitPresence(requestRoster=0)
        try:
            #search the dictionary in same directory of program
            self.en_ml_db = DictDB("freedict-eng-mal")
        except:
            #retry in standard directory of dictd
            self.en_ml_db = DictDB("/usr/share/dictd/freedict-eng-mal")
예제 #2
0
 def getdef(self, word):
     en_hi_db = None
     hi_en_db = None
     meaning_str = ""
     #search the dictionary in same directory of program
     en_hi_db = DictDB("/usr/share/dictd/freedict-eng-hin")
     hi_en_db = DictDB("/usr/share/dictd/freedict-hin-eng")
     if en_hi_db == None or hi_en_db == None:
         return "[FATAL ERROR] Dictionary not found."    
     try:
         meanings = en_hi_db.getdef(word)
         for meaning in meanings:
             meaning_str+=meaning
         meanings = hi_en_db.getdef(word.encode("utf-8"))
         for meaning in meanings:
             meaning_str+=meaning
         if meaning_str == ""    :
             return "Sorry, No definition found."
         else:
             return meaning_str
     except:
         return "Sorry, No definition found."
예제 #3
0
파일: dictionary.py 프로젝트: stultus/silpa
 def getdef(self, word, dictionary):
     meaningstring= ""
     src = dictionary.split("-")[0]
     dest = dictionary.split("-")[1]
     dictdata = self.get_free_dict(src,dest)
     if dictdata:
         dict = DictDB(dictdata)
         meanings =  dict.getdef(word)
         for meaning in meanings:
             meaningstring += meaning
     if meaningstring == "None":
         meaningstring = "No definition found"
         return meaningstring
     return meaningstring.decode("utf-8")
예제 #4
0
        tweet = s.user.name + "\t" + s.text
        dict_keyword_find = tweet.find(username + "dict")

        if dict_keyword_find > 0:
            fin = open('dataFile', 'r')
            fin_contents = fin.read()
            check_duplicate = fin_contents.find(str(s.id))
            print check_duplicate
            fin.close()

        if check_duplicate < 0:
            print "%s --> %s" % (s.user.name, s.text)
            word = s.text[13:]
            print word  #for debugging
            en_ml_db = DictDB("freedict-eng-mal")
            try:
                definition = en_ml_db.getdef(word)[0]
            except:
                definition = "No definitions found"
            print definition
            defi = definition[0:110]

            output = '@' + s.user.screen_name + ' ' + defi
            #print len(output)
            print output
            api.PostUpdate(output.decode("utf-8", 'ignore'))
            sleep_time = 30  #Adjusting time to make the bot twitter-server friendly
            fout = open('dataFile', 'a')
            text = '\n'  #To write each status id in a new line
            text = text + str(s.id)
예제 #5
0
파일: dictclient.py 프로젝트: stultus/silpa
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Dictionary Client
# Copyright 2008 Santhosh Thottingal <*****@*****.**>
# http://www.smc.org.in
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# If you find any bugs or have any suggestions email: [email protected]
# URL: http://www.smc.org.in

from dictdlib import DictDB
en_ml_db = DictDB("/usr/share/dictd/freedict-eng-mal")
print en_ml_db.getdef('help')[0]
ml_ml_db = DictDB("/usr/share/dictd/dict-ml-ml")
print en_ml_db.getdef('ഭയങ്കരം')