Merge lp:~vhata/ibid/feeds-747635 into lp:ibid

Proposed by Stefano Rivera on 2011-10-24
Status: Merged
Approved by: Stefano Rivera on 2011-10-30
Approved revision: 1029
Merged at revision: 1038
Proposed branch: lp:~vhata/ibid/feeds-747635
Merge into: lp:ibid
Diff against target: 72 lines (+32/-9)
1 file modified
ibid/plugins/feeds.py (+32/-9)
To merge this branch: bzr merge lp:~vhata/ibid/feeds-747635
Reviewer Review Type Date Requested Status
Keegan Carruthers-Smith Approve on 2011-10-31
Stefano Rivera Approve on 2011-10-24
Max Rabkin 2011-10-24 Pending
Jonathan Hitchcock 2011-10-24 Pending
Review via email: mp+80198@code.launchpad.net

This proposal supersedes a proposal from 2011-10-24.

Commit message

Make feeds syntax more intuitive/responsive.

Description of the change

Adds the ability to specify 'headlines' or 'articles' when fetching a bunch (and fixes the syntax so that if you just say 'latest article' it only fetches one).

To post a comment you must log in.
Max Rabkin (max-rabkin) : Posted in a previous version of this proposal
review: Approve
Stefano Rivera (stefanor) wrote : Posted in a previous version of this proposal

We don't use "starting at" any where else, we use "from" or "#".

Should we not standardise a bit?

Otherwise I quite like it. My initial response was that this should have been fixed by changing article(), but this does seem more user-friendly.

review: Needs Fixing
Jonathan Hitchcock (vhata) wrote : Posted in a previous version of this proposal

This syntax already has "from" in it - "latest articles from bbc from 3" is weird. Also, that's not how people speak, whether the other ibid plugins think so or not.

review: Resubmit
Stefano Rivera (stefanor) wrote :

ok, successfully convinced me.

review: Approve
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/feeds.py'
2--- ibid/plugins/feeds.py 2010-11-07 15:10:58 +0000
3+++ ibid/plugins/feeds.py 2011-10-24 11:29:27 +0000
4@@ -225,7 +225,7 @@
5 broken_lock = Lock()
6
7 class Retrieve(Processor):
8- usage = u"""latest [ <count> ] articles from <name> [ starting at <number> ]
9+ usage = u"""latest [ <count> ] ( articles | headlines ) from <name> [ starting at <number> ]
10 article ( <number> | /<pattern>/ ) from <name>"""
11 features = ('feeds',)
12
13@@ -236,10 +236,16 @@
14 'The slowdown ratio to back off from broken feeds', 2.0)
15
16
17- @match(r'^(?:latest|last)\s+(?:(\d+)\s+)?articles\s+from\s+(.+?)'
18+ @match(r'^(?:latest|last)\s+(?:(\d+)\s+)?(article|headline)(s)?\s+from\s+(.+?)'
19 r'(?:\s+start(?:ing)?\s+(?:at\s+|from\s+)?(\d+))?$')
20- def list(self, event, number, name, start):
21- number = number and int(number) or 10
22+ def list(self, event, number, full, plurality, name, start):
23+ full = full == 'article'
24+ if number:
25+ number = int(number)
26+ elif not plurality:
27+ number = 1
28+ else:
29+ number = 10
30 start = start and int(start) or 0
31
32 feed = event.session.query(Feed).filter_by(name=name).first()
33@@ -254,10 +260,27 @@
34 return
35
36 articles = feed.entries[start:number+start]
37- articles = [u'%s: "%s"' % (feed.entries.index(entry) + 1,
38- html2text_file(entry.title, None).strip())
39- for entry in articles]
40- event.addresponse(u', '.join(articles))
41+ entries = []
42+ for article in articles:
43+ if full:
44+ if 'summary' in article:
45+ summary = html2text_file(article.summary, None)
46+ else:
47+ if article.content[0].type in \
48+ ('application/xhtml+xml', 'text/html'):
49+ summary = html2text_file(article.content[0].value, None)
50+ else:
51+ summary = article.content[0].value
52+
53+ entries.append(u'%(number)s: "%(title)s"%(link)s : %(summary)s' % {
54+ 'number': articles.index(article) + 1,
55+ 'title': html2text_file(article.title, None).strip(),
56+ 'link': get_link(article),
57+ 'summary': summary,
58+ })
59+ else:
60+ entries.append(u'%s: "%s"' % (feed.entries.index(article) + 1, html2text_file(article.title, None).strip()))
61+ event.addresponse(u', '.join(entries))
62
63 @match(r'^article\s+(?:(\d+)|/(.+?)/)\s+from\s+(.+?)$')
64 def article(self, event, number, pattern, name):
65@@ -269,7 +292,7 @@
66
67 feed.update()
68 if not feed.entries:
69- event.addresponse(u"I can't access that feed")
70+ event.addresponse(u"I can't find any articles in that feed")
71 return
72 article = None
73

Subscribers

People subscribed via source and target branches