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)
Your issue is a case of formatting and indentation issues.
The first edit got the import items placement wrong. And the indentation wasn't correct. Python is very specific about indentation and if it isn't accurate, you won't get anywhere.
The second edit has an extra
a
after Wikipedia. It is wikipediaa everywhere in the code which messes things up. It also has some indentation and formatting problems.Here is a very basic working version of the file from the tutorial. It works for me. You can go on and add other features like the customized images and the locales.
The best practise to learn how to program is not to ask for a completed file but to ask where you did it wrong. I am giving a leeway in that by giving you a sample file.
I guess you are not very much interested in developing a lens on your own. For your sake, I have added the lens to my PPA so that you can install it and use it without much of a chore.
Enter the following commands in a terminal:
After installing the lens, log out of Unity and then back in. You should now be ready to use the Wikipedia lens.
Note: The lens in my PPA is just functional. Don't expect it to have stylish images, error messages or the localized versions. If you want all of those, I recommend you to try the tutorial yourself and add them for your delight.