Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Hey guys I tried to create a Wiktionary Lens using this template, apparently it isn't as easy as I thought i would be.

I'm trying to create a lens that allows me to search on the HUD for a definition on the German Wiktionary, or any Wiktionary using the locale option. I'm not a Python Programmer, but I'd appreciate any asistance on the subject.

By the way, here's the code if you're interested, It installed well, but it doesn't work.

import logging
import optparse

import urllib2
import simplejson

import gettext
from gettext import gettext as _

from singlet.lens import SingleScopeLens, IconViewCategory, ListViewCategory

from wiktionary import wiktionaryconfig

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

    class Meta:
        name = 'wiktionary'
        description = 'Wiktionary Lens'
        search_hint = 'Search Wiktionary'
        icon = 'wiktionary.svg'

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

    def search(self, search, results):
        for article in self.wiktionary_query(search):
            results.append("%s/wiki/%s" % (, article),
                    "Wiktionary Article",
                    "%s/wiki/%s" % (, article))

Thanks in advance.

share|improve this question

closed as not constructive by Luis Alvarado Apr 10 '13 at 16:11

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

You may be able to follow make it work by following the code for a lense i've made to seach Stack Exchange sites. Especially the code in file, located inside the stacklense folder. The rest are boilerplate files made by quickly. Repository located at Launchpad

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.