Codigo fuente plugin emesene wikipedia.py


Este codigo esta escrito en python

# This file is part of emesene.
#
# Emesene is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# emesene 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with emesene; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

VERSION = ‘0.1’

import Plugin
import urllib2

ERROR = ”

ARTICLE_START=’/td>\n

\n

\n

ARTICLE_END = ‘

NOT_FOUND=’

WIKI_URL = ‘http://%s.wikipedia.org/wiki/%s’

AMBIG = ‘

class Wiki(object):
def __init__(self,lang):
self.lang = lang

def request(self,url):
req= urllib2.Request(url)
req.add_header(‘User-Agent’, ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0’)
req.add_header(‘Accept-Charset’, ‘ISO-8859-1,utf-8;q=0.7,*;q=0.7’)
req.add_header(‘Accept’, ‘text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5’)
req.add_header(‘Accept-Language’, ‘es-ar,es;q=0.5’)
o=urllib2.urlopen(req)
return o.read()

def stripTags(self,s):
intag = [False]

def chk(c):
if intag[0]:
intag[0] = (c != ‘>’)
return False
elif c == ‘ 500:
data=data[:500]+’… ‘+_(‘Read more in ‘)+self.wiki.getUrl(wikiword)
slashAction.outputText(data)

def action( self ):
pass

def check( self ):
”’
check if everything is OK to start the plugin
return a tuple whith a boolean and a message
if OK -> ( True , ‘some message’ )
else -> ( False , ‘error message’ )
”’
if ERROR != ”:
return ( False, ERROR )

return ( True, ‘Ok’ )

def configure( self ):
l=[]
l.append( Plugin.Option( ‘lang’, str, _(‘Language:’), ”, self.config.getPluginValue( self.name, ‘lang’, self.lang )) )

response = Plugin.ConfigWindow( _( ‘Wikipedia plugin config’ ), l ).run()
if response != None:
self.lang = response[‘lang’].value
self.wiki.lang = self.lang

self.config.setPluginValue( self.name,’lang’, self.lang )
return True

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s