progval / Supybot-plugins

Collection of plugins for Supybot/Limnoria I wrote or forked.
https://github.com/ProgVal/Limnoria/
107 stars 63 forks source link

Wikipedia doesn't work with Finnish Wikipedia. #226

Closed Mikaela closed 10 years ago

Mikaela commented 10 years ago

Might also affect other languages.

2014-09-09 19:19:08+0300 < Mikaela> hau:config help plugins.wikipedia.url
2014-09-09 19:19:12+0300 < Tessu> URL of the website from where you want to pull pages (usually: your language's wikipedia) (Nykyinen arvo: en.wikipedia.org)
2014-09-09 19:19:21+0300 < Mikaela> hau:config plugins.wikipedia.url fi.wikipedia.org
2014-09-09 19:19:22+0300 < Tessu> OK!
2014-09-09 19:19:57+0300 < Mikaela> hau:wiki yukata
2014-09-09 19:20:00+0300 < Tessu> Virhe: AttributeError: 'NoneType' object has no attribute 'group'
INFO 2014-09-09T19:19:58 supybot wiki called on #limnoria-bots by "Mikaela!mkaysi@unaffiliated/mikaela".
ERROR 2014-09-09T19:19:59 supybot Uncaught exception in ['wiki'].
Traceback (most recent call last):
  File "/home/users/mkaysi/.local/lib/python2.7/site-packages/supybot/callbacks.py", line 1268, in _callCommand
    self.callCommand(command, irc, msg, *args, **kwargs)
  File "/home/users/mkaysi/.local/lib/python2.7/site-packages/supybot/utils/python.py", line 91, in g
    f(self, *args, **kwargs)
  File "/home/users/mkaysi/.local/lib/python2.7/site-packages/supybot/callbacks.py", line 1249, in callCommand
    method(irc, msg, *args, **kwargs)
  File "/home/users/mkaysi/.local/lib/python2.7/site-packages/supybot/commands.py", line 1079, in newf
    f(self, irc, msg, args, *state.args, **state.kwargs)
  File "/home/users/mkaysi/Tessu/plugins/Wikipedia/plugin.py", line 137, in wiki
    addr = addr.group(1)
AttributeError: 'NoneType' object has no attribute 'group'
ERROR 2014-09-09T19:19:59 supybot Exception id: 0x5bfd5
INFO 2014-09-09T19:20:05 supybot flush called on #limnoria-bots by "Mikaela!mkaysi@unaffiliated/mikaela".

Supybot 0.83.4.1+limnoria 2014.08.30 running on Python2.7.6 (default, May 17 2014, 12:03:36) [GCC 4.7.2]

jlu5 commented 10 years ago

I think this is the same error as #186, which has already been fixed. Try updating your copy of the Wikipedia plugin.

Mikaela commented 10 years ago
mkaysi@hilla ~/Tessu/plugins
% pwd && ll Wikipedia 
/home/users/mkaysi/Tessu/plugins
lrwxrwxrwx 1 mkaysi users 60 kesä  30 16:04 Wikipedia -> /home/users/mkaysi/src/git/ProgVal/Supybot-plugins/Wikipedia/
mkaysi@hilla ~/src/git/ProgVal/Supybot-plugins/Wikipedia
% git pull
Already up-to-date.

and the bot has been last restarted 2 ½ days ago and there haven't been changes in the Wikipedia plugin after that , so that cannot be it.

jlu5 commented 10 years ago

Try this patch; there seems to be some minor inconsistencies in the formatting Wikipedia uses, which causes the regex matching being used in the plugin to break.

diff --git a/Wikipedia/locales/fr.po b/Wikipedia/locales/fr.po
index 8b0d66a..765e551 100644
--- a/Wikipedia/locales/fr.po
+++ b/Wikipedia/locales/fr.po
@@ -7,7 +7,7 @@ msgstr ""
 "Project-Id-Version: Supybot-fr\n"
 "POT-Creation-Date: 2011-03-02 11:00+CET\n"
 "PO-Revision-Date: 2011-03-02 11:06+0100\n"
-"Last-Translator: Valentin Lorentz <progval@gmail.com>\n"
+"Last-Translator: James Lu <glolol1@hotmail.com>\n"
 "Language-Team: ProgVal <progval@gmail.com>\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
@@ -55,10 +55,6 @@ msgstr "Je ne peux rien trouver pour \"%s\", mais voici le résultat de \"%s\" :
 msgid "Redirected from"
 msgstr "Redirigé de"

-#: plugin.py:109
-msgid "Retrieved from"
-msgstr "Recu de"
-
 #: plugin.py:118
 msgid "%s is a disambiguation page. Possible results are: %s"
 msgstr "%s est une page de désambiguation. Les résultats possibles son : %s"
@@ -75,3 +71,6 @@ msgstr "\"%s\" est une page pleine d'évènement qui se sont produits cette ann
 msgid "Not found, or page bad formed."
 msgstr "Non trouvé, ou page mal formée."

+#: plugin.py:168
+msgid "Retrieved from"
+msgstr "Recu de"
diff --git a/Wikipedia/locales/it.po b/Wikipedia/locales/it.po
index 0a02c27..d686830 100644
--- a/Wikipedia/locales/it.po
+++ b/Wikipedia/locales/it.po
@@ -3,7 +3,7 @@ msgstr ""
 "Project-Id-Version: Supybot-fr\n"
 "POT-Creation-Date: 2011-02-26 09:49+CET\n"
 "PO-Revision-Date: 2011-07-29 17:43+0200\n"
-"Last-Translator: skizzhg <skizzhg@gmx.com>\n"
+"Last-Translator: James Lu <glolol1@hotmail.com>\n"
 "Language-Team: Italian <skizzhg@gmx.com>\n"
 "Language: it\n"
 "MIME-Version: 1.0\n"
@@ -53,10 +53,6 @@ msgstr "Non trovo nulla per \"%s\", ma questi sono i risultati per \"%s\": "
 msgid "Redirected from"
 msgstr "Rediretto da"

-#: plugin.py:109
-msgid "Retrieved from"
-msgstr "Recuperato da"
-
 #: plugin.py:118
 msgid "%s is a disambiguation page. Possible results are: %s"
 msgstr "%s è una pagina di disambiguazione; i possibili risultati sono: %s"
@@ -73,3 +69,6 @@ msgstr "\"%s\" è una pagina piena di eventi accaduti quest'anno. Se stavi cerca
 msgid "Not found, or page bad formed."
 msgstr "Non trovato, o pagina non valida."

+#: plugin.py:168
+msgid "Retrieved from"
+msgstr "Recuperato da"
diff --git a/Wikipedia/plugin.py b/Wikipedia/plugin.py
index 51bbe1d..ebd778b 100644
--- a/Wikipedia/plugin.py
+++ b/Wikipedia/plugin.py
@@ -133,7 +133,7 @@ class Wikipedia(callbacks.Plugin):
                         redirect = redirect.encode('utf-8','replace')
                 reply += '"%s" (Redirect from "%s"): ' % (title, redirect)
         # extract the address we got it from
-        addr = re.search(_('Retrieved from') + ' "<a dir="ltr" href="([^"]*)">', article)
+        addr = re.search(' "?<a dir="ltr" href="([^"]*)"?>', article)
         addr = addr.group(1)
         # check if it's a disambiguation page
         disambig = tree.xpath('//table[@id="disambigbox"]')
@@ -165,7 +165,7 @@ class Wikipedia(callbacks.Plugin):
                         p = p.encode('utf-8', 'replace')
                     if isinstance(reply, unicode):
                         reply = reply.encode('utf-8','replace')
-                reply += '%s %s' % (p, ircutils.bold(addr))
+                reply += '%s %s %s' % (p, _('Retrieved from'), ircutils.bold(addr))
         reply = reply.replace('&amp;','&')
         irc.reply(reply)
     wiki = wrap(wiki, ['text'])
Mikaela commented 10 years ago

Ignore removed comment, I used wikipedia instead of wiki.

The patch works.