How do I compile a Wikipedia lens and install?

Posted by user49523 on Ask Ubuntu See other posts from Ask Ubuntu or by user49523
Published on 2012-04-14T20:41:41Z Indexed on 2012/04/15 11:48 UTC
Read the original article Hit count: 395

Filed under:
|
|
|

I read a tutorial about how to compile and install a Wikipedia lens, but it didn't work.

The tutorial sounds easy - i just copied and pasted to the file that was suppose to edit.

I have tried some times and here are 2 edits

edit 1:

import logging
import optparse

import gettext
from gettext import gettext as _
gettext.textdomain('wikipedia')

from singlet.lens import SingleScopeLens, IconViewCategory, ListViewCategory

from wikipedia import wikipediaconfig
import urllib2
import simplejson

class WikipediaLens(SingleScopeLens):

wiki = "http://en.wikipedia.org"
def wikipedia_query(self,search):
    try:
        search = search.replace(" ", "|")
        url = ("%s/w/api.php?action=opensearch&limit=25&format=json&search=%s" % (self.wiki, search))
        results = simplejson.loads(urllib2.urlopen(url).read())
        print "Searching Wikipedia"
        return results[1]
    except (IOError, KeyError, urllib2.URLError, urllib2.HTTPError, simplejson.JSONDecodeError):
        print "Error : Unable to search Wikipedia"
        return []

   class Meta:
    name = 'Wikipedia'
    description = 'Wikipedia Lens'
    search_hint = 'Search Wikipedia'
    icon = 'wikipedia.svg'
    search_on_blank=True

    # TODO: Add your categories
   articles_category = ListViewCategory("Articles", "dialog-information-symbolic")

  def search(self, search, results):
    for article in self.wikipedia_query(search):
        results.append("%s/wiki/%s" % (self.wiki, article),
                    "http://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png",
                    self.articles_category,
                    "text/html",
                    article,
                    "Wikipedia Article",
                    "%s/wiki/%s" % (self.wiki, article))
    pass

edit 2:

import urllib2
import simplejson


import logging
import optparse

import gettext
from gettext import gettext as _
gettext.textdomain('wikipediaa')

from singlet.lens import SingleScopeLens, IconViewCategory, ListViewCategory

from wikipediaa import wikipediaaconfig

class WikipediaaLens(SingleScopeLens):

wiki = "http://en.wikipedia.org"

def wikipedia_query(self,search):
    try:
        search = search.replace(" ", "|")
        url = ("%s/w/api.php?action=opensearch&limit=25&format=json&search=%s" % (self.wiki, search))
        results = simplejson.loads(urllib2.urlopen(url).read())
        print "Searching Wikipedia"
        return results[1]

    except (IOError, KeyError, urllib2.URLError, urllib2.HTTPError, simplejson.JSONDecodeError):
        print "Error : Unable to search Wikipedia"
        return []
def search(self, search, results):
    for article in self.wikipedia_query(search):
        results.append("%s/wiki/%s" % (self.wiki, article),
                    "http://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png",
                    self.articles_category,
                    "text/html",
                    article,
                    "Wikipedia Article",
                    "%s/wiki/%s" % (self.wiki, article))
    pass

    class Meta:
    name = 'Wikipedia'
    description = 'Wikipedia Lens'
    search_hint = 'Search Wikipedia'
    icon = 'wikipedia.svg'
    search_on_blank=True

    # TODO: Add your categories
   articles_category = ListViewCategory("Articles", "dialog-information-symbolic")

    def search(self, search, results):
    # TODO: Add your search results
    results.append('https://wiki.ubuntu.com/Unity/Lenses/Singlet',
                'ubuntu-logo',
                self.example_category,
                "text/html",
                'Learn More',
                'Find out how to write your Unity Lens',
                'https://wiki.ubuntu.com/Unity/Lenses/Singlet')
    pass

so .. what can i change in the edit ? (if anybody give me the entire edit file edited i will appreciate)

© Ask Ubuntu or respective owner

Related posts about unity

Related posts about 12.04