Merge lp:~toote/lalita/url-rename into lp:lalita

Proposed by Matías Bellone
Status: Merged
Merged at revision: 168
Proposed branch: lp:~toote/lalita/url-rename
Merge into: lp:lalita
Diff against target: 61 lines (+36/-1)
1 file modified
lalita/plugins/url.py (+36/-1)
To merge this branch: bzr merge lp:~toote/lalita/url-rename
Reviewer Review Type Date Requested Status
Facundo Batista Approve
Review via email: mp+51390@code.launchpad.net

Description of the change

Agrega la opción de renombrar URLs en la base de datos.

Muy útil para poder buscar links sin título, en particular imágenes o páginas que no fueron parseadas correctamente.

También corrige un problema en la configuración por defecto al reportar una URL ya que el ":" al final de la misma pasa a ser parte de la URL

To post a comment you must log in.
Revision history for this message
Facundo Batista (facundo) wrote :

It's better to do...

  self.say(channel, u"%s: necesito un ID a renombrar válido", user)

...than using '%' there, to be able to build a translation table later.

Also, it's funny the comparison len(what) -1 == 0

You should include tests for this, but as the module is not tested at all, it could be ok.

review: Needs Fixing
lp:~toote/lalita/url-rename updated
171. By Matías Bellone <email address hidden>

Corrected funny conditional and .say invocations to be translation-friendly

Revision history for this message
Facundo Batista (facundo) wrote :

Like it

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lalita/plugins/url.py'
2--- lalita/plugins/url.py 2010-11-14 18:54:59 +0000
3+++ lalita/plugins/url.py 2011-03-01 21:55:37 +0000
4@@ -38,7 +38,7 @@
5 self.config= dict (
6 block_size=4096,
7 in_format=u'%(poster)s: [#%(id)d] %(title)s',
8- found_format=u'[#%(id)d] %(url)s: %(title)s [by %(poster)s, %(date)s, %(time)s]',
9+ found_format=u'[#%(id)d] %(url)s : %(title)s [by %(poster)s, %(date)s, %(time)s]',
10 guess_encoding=0.0,
11 )
12 self.config.update (config)
13@@ -49,6 +49,7 @@
14
15 self.register(self.events.COMMAND, self.dig, ['dig'])
16 self.register(self.events.COMMAND, self.delete, ['del'])
17+ self.register(self.events.COMMAND, self.rename, ['rename'])
18
19 self.urlsFound= 0
20 self.urlsFailed= 0
21@@ -169,6 +170,40 @@
22 promise.addErrback (self.failed, user, channel, url, date, time)
23 return promise
24
25+ def rename(self, user, channel, command, *what):
26+ u'''Renombra el título de una URL anterior'''
27+ self.logger.debug(u'renaming %s', what)
28+
29+ if len(what) < 2:
30+ # no arguments or missing new title
31+ self.say(channel,
32+ u"%s: necesito un ID y el nuevo título para poder renombrar", user)
33+ return
34+
35+ try:
36+ url_id = int(what[0])
37+ except ValueError:
38+ self.say(channel,
39+ u"%s: necesito un ID a renombrar válido", user)
40+ return
41+
42+ self.cursor.execute('''select title, poster from url where id = ?''', (url_id, ))
43+
44+ result= list (self.cursor.fetchone ())
45+
46+ if not result:
47+ self.say(channel,
48+ '%s: 404 ID %s not found', user, url_id)
49+ return
50+
51+ new_title = ' '.join(what[1:])
52+
53+ self.logger.debug('changing urlID %s from "%s" to "%s"', url_id, result[0], new_title)
54+ self.cursor.execute('''update url SET title = ? where id = ?''', (new_title, url_id))
55+ self.conn.commit()
56+ self.say(channel,
57+ '%s: [#%s] renamed to "%s"', user, url_id, new_title)
58+
59 ##### encoding detectors #####
60 def pageContentType(self, page):
61 encoding = None

Subscribers

People subscribed via source and target branches