1010import json
1111from pathlib import Path
1212
13- md_iid = '2.3'
14- md_version = "2 .0"
13+ md_iid = "3.0"
14+ md_version = "3 .0"
1515md_name = "Wikipedia"
1616md_description = "Search Wikipedia articles"
1717md_license = "MIT"
1818md_url = "https://github.com/albertlauncher/python/tree/main/wikipedia"
1919md_authors = "@manuelschneid3r"
2020
21-
2221class Plugin (PluginInstance , TriggerQueryHandler ):
2322
2423 baseurl = 'https://en.wikipedia.org/w/api.php'
@@ -29,10 +28,9 @@ class Plugin(PluginInstance, TriggerQueryHandler):
2928
3029 def __init__ (self ):
3130 PluginInstance .__init__ (self )
32- TriggerQueryHandler .__init__ (
33- self , self .id , self .name , self .description ,
34- defaultTrigger = 'wiki ' , supportsFuzzyMatching = True
35- )
31+ TriggerQueryHandler .__init__ (self )
32+
33+ self .fbh = FBH (self )
3634 self .fuzzy = False
3735
3836 self .local_lang_code = getdefaultlocale ()[0 ]
@@ -42,9 +40,6 @@ def __init__(self):
4240 self .local_lang_code = 'en'
4341 warning ("Failed getting language code. Using 'en'." )
4442
45- self .fbh = FBH (self )
46- self .registerExtension (self .fbh )
47-
4843 params = {
4944 'action' : 'query' ,
5045 'meta' : 'siteinfo' ,
@@ -66,8 +61,14 @@ def __init__(self):
6661 except Exception as error :
6762 warning ('Error getting languages (%s). Defaulting to EN.' % error )
6863
69- def __del__ (self ):
70- self .deregisterExtension (self .fbh )
64+ def extensions (self ):
65+ return [self , self .fbh ]
66+
67+ def defaultTrigger (self ):
68+ return "wiki "
69+
70+ def supportsFuzzyMatching (self ):
71+ return True
7172
7273 def setFuzzyMatching (self , enabled : bool ):
7374 self .fuzzy = enabled
@@ -103,7 +104,7 @@ def handleTriggerQuery(self, query):
103104 url = data [3 ][i ]
104105 results .append (
105106 StandardItem (
106- id = self .id ,
107+ id = self .id () ,
107108 text = title ,
108109 subtext = summary if summary else url ,
109110 iconUrls = self .iconUrls ,
@@ -121,17 +122,17 @@ def handleTriggerQuery(self, query):
121122 else :
122123 query .add (
123124 StandardItem (
124- id = self .id ,
125- text = self .name ,
125+ id = self .id () ,
126+ text = self .name () ,
126127 subtext = "Enter a query to search on Wikipedia" ,
127128 iconUrls = self .iconUrls
128129 )
129130 )
130131
131132 def createFallbackItem (self , q : str ) -> Item :
132133 return StandardItem (
133- id = self .id ,
134- text = self .name ,
134+ id = self .id () ,
135+ text = self .name () ,
135136 subtext = "Search '%s' on Wikipedia" % q ,
136137 iconUrls = self .iconUrls ,
137138 actions = [
@@ -144,8 +145,17 @@ def createFallbackItem(self, q: str) -> Item:
144145class FBH (FallbackHandler ):
145146
146147 def __init__ (self , p : Plugin ):
147- FallbackHandler .__init__ (self , p . id + 'fb' , p . name , p . description )
148+ FallbackHandler .__init__ (self )
148149 self .plugin = p
149150
151+ def id (self ):
152+ return "wikipedia.fallbacks"
153+
154+ def name (self ):
155+ return md_name
156+
157+ def description (self ):
158+ return md_description
159+
150160 def fallbacks (self , q :str ):
151161 return [self .plugin .createFallbackItem (q )]
0 commit comments