TrollParty::Caracas (v4)

Edit Page
Text Search
 Page Search
Identification
Language: en

HackSupy

print

Hack Supybot



The first plugin prove that shows the ranking top pages at TikiWiki in the irc whit the command tikitoppages (a modification on http://supybot.com/documentation/help/tutorial/plugin-author-tutorial/tutorial-all-pages):

TikiTopPages$ ls
config.py   __init__.py   plugin.py   README.txt
test.py


TikiTopPages/config.py

import supybot.conf as conf
import supybot.registry as registry

def configure(advanced):
    from supybot.questions import expect, anything, something, yn
    conf.registerPlugin('TikiTopPages', True)
    
TikiTopPages = conf.registerPlugin('TikiTopPages')


TikiTopPages/plugin.py

plugin.pyimport supybot.utils as utils
from supybot.commands import *
import supybot.plugins as plugins
import supybot.ircutils as ircutils
import supybot.callbacks as callbacks
import MySQLdb
class Tdb:
    """Helper class to connect to database."""
    def __init__(self):
        try:
            connection = MySQLdb.connect(host="localhost",
            user="tikiwiki", passwd="xxxxxxx", db="tikidb" )
            cursor = connection.cursor()
            cursor.execute( "select `pageName`, `hits` from `tiki_pages` order by `hits` desc " )
        except MySQLdb.OperationalError, message:
                errorMessage = "Error %d:\n%s" % (message[ 0 ], message[ 1 ] )
                return
        else:
            self.data =    cursor.fetchall()                                                                          
            self.fields = cursor.description
            cursor.close()
            connection.close()

class TikiTopPages(callbacks.Plugin):
    """This plugin shows the top pages at TikiWiki."""
    def __init__(self, irc):
        self.__parent = super(TikiTopPages, self)
        self.__parent.__init__(irc)
        db = Tdb()
        lineas=""
        for row in range(len(db.data)):
            self.lineas=lineas+db.data[row][0]+"-->"+str(db.data[row][1])+"\n"

    def tikitoppages(self, irc, msg, args):
        """Returns the top pages."""
        irc.reply(self.lineas)
    tikitoppages = wrap(tikitoppages)

Class = TikiTopPages


version 2

I used your code but ran the supy-newplugin command, that generated a TikiTop.py file with everything in it. So I made a one-file plugin instead of a dir.

###
# Copyright (c) 2005, Dankajh, Mose
# 
# 
###

"""
Experimental plugin too request a tikiwiki database.
"""

import supybot

__revision__ = "1.0"
__author__ = "dankajh"
__contributors__ = { }


import supybot.conf as conf
import supybot.utils as utils
from supybot.commands import *
import supybot.plugins as plugins
import supybot.ircutils as ircutils
import supybot.privmsgs as privmsgs
import supybot.registry as registry
import supybot.callbacks as callbacks
import MySQLdb

def configure(advanced): 
  from supybot.questions import expect, anything, something, yn
  conf.registerPlugin('TikiTop', True)

conf.registerPlugin('TikiTop')
# This is where your configuration variables (if any) should go.

class Tdb:
  """Helper class to connect to database."""
  def __init__(self, irc):
    try:
      connection = MySQLdb.connect(host="localhost", user="xxx", passwd="xxx", db="tiki_xxx" )
      cursor = connection.cursor()
      cursor.execute( "select `pageName`, `hits` from `tiki_pages` order by `hits` desc limit 5" )
    except MySQLdb.OperationalError, message:
      errorMessage = "Error %d:\n%s" % (message[ 0 ], message[ 1 ] )
      return
    else:
      self.data = cursor.fetchall()
      self.fields = cursor.description
      cursor.close()
      connection.close()

class TikiTop(callbacks.Privmsg):
  def tikitop(self, irc, msg, args):
    """Returns the top pages."""
    db = Tdb(irc)
    lineas=""
    for row in range(len(db.data)):
      lineas = lineas + db.data[row][0] + " (" + str(db.data[row][1]) + ") - "
    irc.reply(lineas)
  tikitop = wrap(tikitop)

Class = TikiTop

# vim:set shiftwidth=2 tabstop=2 textwidth=120:



Version 3

I hacked further and reached some dirty result. That code should be enhanced it's noob work.
plugins/Tiki.py
###
# Copyright (c) 2005, Dankajh, Mose
# 
# 
###

"""
Experimental plugin to request a tikiwiki database.
"""

import supybot

__revision__ = "1.0"
__author__ = "dankajh"
__contributors__ = { }


import supybot.conf as conf
import supybot.utils as utils
from supybot.commands import *
import supybot.plugins as plugins
import supybot.ircutils as ircutils
import supybot.privmsgs as privmsgs
import supybot.registry as registry
import supybot.callbacks as callbacks
import supybot.webutils as webutils

import MySQLdb

def configure(advanced):
  from supybot.questions import expect, output, anything, something, yn
  conf.registerPlugin('Tiki', True)

conf.registerPlugin('Tiki')

class Tiki(callbacks.Privmsg):

  threaded = True

  def tiki(self, irc, msg, args, word):
    """Returns pages found."""
    try:
      connection = MySQLdb.connect(host="localhost", user="xxx", passwd="xxx", db="tiki_xxx" )
      cursor = connection.cursor()
      cursor.execute("select pageName, hits from tiki_pages where pageName like '%" + word + "%' order by pageName limit 3")
    except MySQLdb.OperationalError, message:
      irc.reply(errorMessage)
    else:
      data = cursor.fetchall()
      for row in range(len(data)):
        irc.reply( "http://caracas.trollparty.org/" + webutils.urlquote(data[row][0]) + " (" + str(data[row][1]) + " hits)")

  tiki = wrap(tiki, ['text'])

Class = Tiki

# vim:set shiftwidth=2 tabstop=2 textwidth=120:



Requirements

Items' list that should be implemented as Tiki class' methods and corresponds to different queries to the TikiWiki DB:
  • who's online
  • the last page changed
  • the personal page (in tiki) of someone (already implemented)
  • the translation of a word (already implemented)
  • the time in different places of the planet
  • links to the google maps
  • to say to Stallman: fuck



Who works on it ?


Contributors to this page: dankajh and mose .
Page last modified on Wednesday 25 January, 2006 [17:21:04 UTC] by dankajh.

Upcoming events
RSS Wiki RSS Image Galleries
[ Execution time: 0.27 secs ]   [ Memory usage: 1.36MB ]   [ 230 database queries used ]   [ GZIP Enabled ]   [ Server load: 0.03 ]
Last update from CVS: Sunday 02 March, 2008 [10:53:28 UTC]