Commits

Benoit Boissinot committed dd3b650

support new API for fmylife/vdm

Comments (0)

Files changed (1)

                     r'#\d*?</a>.*?<p>(?P<text>.*?)</p></td></tr>'
     _gkREDict = {'bash.org': re.compile(r'<p class="qt">(?P<text>.*?)</p>',
                     re.M | re.DOTALL),
-                'qdb.us': re.compile(_qdbReString, re.M | re.DOTALL),
-                'fmylife.com': re.compile(r'<div class="post"><p>(?P<text>.*?)</p><div class="date"',
-                    re.M | re.DOTALL),}
+                'qdb.us': re.compile(_qdbReString, re.M | re.DOTALL),}
+    _betacieUrl = ('http://api.betacie.com/view/'
+                   '%(id)s/nocomment?key=readonly&language=%(lang)s')
+
     def _gkBackend(self, irc, msg, site, id):
         if not id:
             id = 'random'
         irc.replies(quote.split(self._joiner), joiner=self._joiner)
 
     def _gkFetchData(self, site, id, random=False):
+        if site in ('viedemerde.fr', 'fmylife.com'):
+            if site == 'viedemerde.fr':
+                lang = 'fr'
+            else:
+                lang = 'en'
+            url = self._betacieUrl % {'id': id, 'lang': lang}
+        else:
+            url = 'http://%s/?%s' % (site, id)
         html = ''
         try:
-            if site == 'viedemerde.fr':
-                html = utils.web.getUrl('http://api.viedemerde.fr/1.0/view/%s/nocomment' % id)
-            elif site == 'fmylife.com':
-                html = utils.web.getUrl('http://%s/%s' % (site, id))
-            else:
-                html = utils.web.getUrl('http://%s/?%s' % (site, id))
+            html = utils.web.getUrl(url)
         except utils.web.Error, e:
             self.log.info('%u server returned the error: %s',
                           site, utils.web.strError(e))
         s = None
-        if site == 'viedemerde.fr':
-            dom = parseString(html).getElementsByTagName("vdm")[0]
-            t = dom.getElementsByTagName('texte')[0].firstChild.nodeValue.encode("utf-8")
-            up = dom.getElementsByTagName('je_valide')[0].firstChild.nodeValue.encode("utf-8")
-            down = dom.getElementsByTagName('bien_merite')[0].firstChild.nodeValue.encode("utf-8")
+        if site in ('viedemerde.fr', 'fmylife.com'):
+            dom = parseString(html).getElementsByTagName("item")[0]
+            t = dom.getElementsByTagName('text')[0].firstChild.nodeValue.encode("utf-8")
+            up = dom.getElementsByTagName('agree')[0].firstChild.nodeValue.encode("utf-8")
+            down = dom.getElementsByTagName('deserved')[0].firstChild.nodeValue.encode("utf-8")
             id = dom.getAttribute('id').encode("utf-8")
             s = "%s #%s (+%s,-%s)" % (t, id, up, down)
             if random and s and s not in self.randomData[site]: