1111from pathlib import Path
1212
1313md_iid = '2.0'
14- md_version = "1.9 "
14+ md_version = "1.10 "
1515md_name = "Wikipedia"
1616md_description = "Search Wikipedia articles"
1717md_license = "BSD-3"
@@ -47,7 +47,6 @@ def __init__(self):
4747 self .wiki_fb = WikiFallbackHandler ()
4848 PluginInstance .__init__ (self , extensions = [self , self .wiki_fb ])
4949
50-
5150 params = {
5251 'action' : 'query' ,
5352 'meta' : 'siteinfo' ,
@@ -56,7 +55,12 @@ def __init__(self):
5655 'format' : 'json'
5756 }
5857
59- Plugin .local_lang_code = getdefaultlocale ()[0 ][0 :2 ]
58+ Plugin .local_lang_code = getdefaultlocale ()[0 ]
59+ if Plugin .local_lang_code :
60+ Plugin .local_lang_code = Plugin .local_lang_code [0 :2 ]
61+ else :
62+ Plugin .local_lang_code = 'en'
63+ warning ("Failed getting language code. Using 'en'." )
6064
6165 get_url = "%s?%s" % (self .baseurl , parse .urlencode (params ))
6266 req = request .Request (get_url , headers = {'User-Agent' : self .user_agent })
@@ -67,15 +71,15 @@ def __init__(self):
6771 if self .local_lang_code in languages :
6872 self .baseurl = self .baseurl .replace ("en" , self .local_lang_code )
6973 except timeout :
70- critical ('Error getting languages - socket timed out. Defaulting to EN.' )
74+ warning ('Error getting languages - socket timed out. Defaulting to EN.' )
7175 except Exception as error :
72- critical ('Error getting languages (%s). Defaulting to EN.' % error )
76+ warning ('Error getting languages (%s). Defaulting to EN.' % error )
7377
7478 def handleTriggerQuery (self , query ):
7579 stripped = query .string .strip ()
7680 if stripped :
7781 # avoid rate limiting
78- for number in range (50 ):
82+ for _ in range (50 ):
7983 sleep (0.01 )
8084 if not query .isValid :
8185 return
@@ -99,17 +103,22 @@ def handleTriggerQuery(self, query):
99103 title = data [1 ][i ]
100104 summary = data [2 ][i ]
101105 url = data [3 ][i ]
106+ results .append (
107+ StandardItem (
108+ id = md_id ,
109+ text = title ,
110+ subtext = summary if summary else url ,
111+ iconUrls = self .iconUrls ,
112+ actions = [
113+ Action ("open" , "Open article on Wikipedia" , lambda u = url : openUrl (u )),
114+ Action ("copy" , "Copy URL to clipboard" , lambda u = url : setClipboardText (u ))
115+ ]
116+ )
117+ )
102118
103- results .append (StandardItem (id = md_id ,
104- text = title ,
105- subtext = summary if summary else url ,
106- iconUrls = self .iconUrls ,
107- actions = [
108- Action ("open" , "Open article on Wikipedia" , lambda u = url : openUrl (u )),
109- Action ("copy" , "Copy URL to clipboard" , lambda u = url : setClipboardText (u ))
110- ]))
111119 if not results :
112120 results .append (Plugin .createFallbackItem (stripped ))
121+
113122 query .add (results )
114123 else :
115124 query .add (
0 commit comments