11
11
from pathlib import Path
12
12
13
13
md_iid = '2.0'
14
- md_version = "1.9 "
14
+ md_version = "1.10 "
15
15
md_name = "Wikipedia"
16
16
md_description = "Search Wikipedia articles"
17
17
md_license = "BSD-3"
@@ -47,7 +47,6 @@ def __init__(self):
47
47
self .wiki_fb = WikiFallbackHandler ()
48
48
PluginInstance .__init__ (self , extensions = [self , self .wiki_fb ])
49
49
50
-
51
50
params = {
52
51
'action' : 'query' ,
53
52
'meta' : 'siteinfo' ,
@@ -56,7 +55,12 @@ def __init__(self):
56
55
'format' : 'json'
57
56
}
58
57
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'." )
60
64
61
65
get_url = "%s?%s" % (self .baseurl , parse .urlencode (params ))
62
66
req = request .Request (get_url , headers = {'User-Agent' : self .user_agent })
@@ -67,15 +71,15 @@ def __init__(self):
67
71
if self .local_lang_code in languages :
68
72
self .baseurl = self .baseurl .replace ("en" , self .local_lang_code )
69
73
except timeout :
70
- critical ('Error getting languages - socket timed out. Defaulting to EN.' )
74
+ warning ('Error getting languages - socket timed out. Defaulting to EN.' )
71
75
except Exception as error :
72
- critical ('Error getting languages (%s). Defaulting to EN.' % error )
76
+ warning ('Error getting languages (%s). Defaulting to EN.' % error )
73
77
74
78
def handleTriggerQuery (self , query ):
75
79
stripped = query .string .strip ()
76
80
if stripped :
77
81
# avoid rate limiting
78
- for number in range (50 ):
82
+ for _ in range (50 ):
79
83
sleep (0.01 )
80
84
if not query .isValid :
81
85
return
@@ -99,17 +103,22 @@ def handleTriggerQuery(self, query):
99
103
title = data [1 ][i ]
100
104
summary = data [2 ][i ]
101
105
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
+ )
102
118
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
- ]))
111
119
if not results :
112
120
results .append (Plugin .createFallbackItem (stripped ))
121
+
113
122
query .add (results )
114
123
else :
115
124
query .add (
0 commit comments