Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

http://developer.ubuntu.com/2012/04/how-to-create-a-wikipedia-unity-lens-for-ubuntu/

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 _
gettext.textdomain('wiktionary')

from singlet.lens import SingleScopeLens, IconViewCategory, ListViewCategory

from wiktionary import wiktionaryconfig

class WiktionaryLens(SingleScopeLens):
    wiki = "http://de.wiktionary.org"
    def wiktionary_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 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'
        search_on_blank=True

        # 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" % (self.wiki, article),
                    "http://upload.wikimedia.org/wikipedia/commons/f/f8/Wiktionary-logo-en.svg",
                    self.articles_category,
                    "text/html",
                    article,
                    "Wiktionary Article",
                    "%s/wiki/%s" % (self.wiki, article))
    pass

Thanks in advance.

share|improve this question
add comment

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

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 stacksearch.py file, located inside the stacklense folder. The rest are boilerplate files made by quickly. Repository located at Launchpad

share|improve this answer
add comment

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