Merge lp:~stefanor/ibid/remove-mlig-722675 into lp:~ibid-core/ibid/old-release-0.1-1.6

Proposed by Stefano Rivera
Status: Merged
Approved by: Stefano Rivera
Approved revision: 908
Merged at revision: 986
Proposed branch: lp:~stefanor/ibid/remove-mlig-722675
Merge into: lp:~ibid-core/ibid/old-release-0.1-1.6
Diff against target: 151 lines (+32/-63)
1 file modified
ibid/plugins/quotes.py (+32/-63)
To merge this branch: bzr merge lp:~stefanor/ibid/remove-mlig-722675
Reviewer Review Type Date Requested Status
Max Rabkin Approve
Jonathan Hitchcock Approve
marcog (community) Approve
Review via email: mp+50634@code.launchpad.net

Commit message

Remove MyLifeIsG.com support from MyLifeIsAverage Processor. The site has been down for around a year

Description of the change

Too invasive for 0.1 right now?

To post a comment you must log in.
Revision history for this message
marcog (marco-gallotta) :
review: Approve
Revision history for this message
Jonathan Hitchcock (vhata) :
review: Approve
Revision history for this message
Max Rabkin (max-rabkin) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/quotes.py'
2--- ibid/plugins/quotes.py 2011-01-12 14:16:31 +0000
3+++ ibid/plugins/quotes.py 2011-02-21 16:57:50 +0000
4@@ -249,115 +249,84 @@
5 'categories': ('fun', 'lookup', 'web',),
6 }
7 class MyLifeIsAverage(Processor):
8- usage = u"""mlia [(<number> | random | recent | today | yesterday | this week | this month | this year )]
9- mlig [(<number> | random | recent | today | yesterday | this week | this month | this year )]"""
10+ usage = (u"mlia [(<number> | random | recent | today | yesterday | "
11+ u"this week | this month | this year )]")
12
13 feature = ('mlia',)
14
15 public_browse = BoolOption('public_browse',
16 'Allow random quotes in public', True)
17
18- random_pool = {}
19- pages = {}
20+ random_pool = []
21+ pages = 1
22
23- def find_stories(self, url, site='mlia'):
24+ def find_stories(self, url):
25 if isinstance(url, basestring):
26 tree = get_html_parse_tree(url, treetype='etree')
27 else:
28 tree = url
29
30 stories = [div for div in tree.findall('.//div')
31- if div.get(u'class') in
32- (u'story s', # mlia
33- u'stories', u'stories-wide')] # mlig
34+ if div.get(u'class') == u'story s']
35
36 for story in stories:
37- if site == 'mlia':
38- body = story.findtext('div').strip()
39- else:
40- body = story.findtext('div/span/span').strip()
41+ body = story.findtext('div').strip()
42 id = story.findtext('.//a')
43 if isinstance(id, basestring) and id[1:].isdigit():
44 id = int(id[1:])
45 yield id, body
46
47- @match(r'^(mli[ag])(?:\s+this)?'
48+ @match(r'^mlia(?:\s+this)?'
49 r'(?:\s+(\d+|random|recent|today|yesterday|week|month|year))?$')
50- def mlia(self, event, site, query):
51+ def mlia(self, event, query):
52 query = query is None and u'random' or query.lower()
53
54 if query == u'random' and event.public and not self.public_browse:
55 event.addresponse(u'Sorry, not in public. PM me')
56 return
57
58- site = site.lower()
59- url = {
60- 'mlia': 'http://mylifeisaverage.com/',
61- 'mlig': 'http://mylifeisg.com/',
62- }[site]
63+ url = 'http://mylifeisaverage.com/'
64
65 if query == u'random' or query is None:
66- if not self.random_pool.get(site):
67- if site == 'mlia':
68- purl = url + str(randint(1, self.pages.get(site, 1)))
69- else:
70- purl = url + 'index.php?' + urlencode({
71- 'page': randint(1, self.pages.get(site, 1))
72- })
73+ if not self.random_pool:
74+ purl = url + str(randint(1, self.pages))
75 tree = get_html_parse_tree(purl, treetype='etree')
76- self.random_pool[site] = [story for story
77- in self.find_stories(tree, site=site)]
78- shuffle(self.random_pool[site])
79-
80- if site == 'mlia':
81- pagination = [ul for ul in tree.findall('.//ul')
82- if ul.get(u'class') == u'pages'][0]
83- self.pages[site] = int(
84- [li for li in pagination.findall('li')
85- if li.get(u'class') == u'last'][0]
86- .find(u'a').get(u'href'))
87- else:
88- pagination = [div for div in tree.findall('.//div')
89- if div.get(u'class') == u'pagination'][0]
90- self.pages[site] = sorted(int(a.text) for a
91- in pagination.findall('.//a')
92- if a.text.isdigit())[-1]
93-
94- story = self.random_pool[site].pop()
95+ self.random_pool = list(self.find_stories(tree))
96+ shuffle(self.random_pool)
97+
98+ pagination = [ul for ul in tree.findall('.//ul')
99+ if ul.get(u'class') == u'pages'][0]
100+ self.pages = int(
101+ [li for li in pagination.findall('li')
102+ if li.get(u'class') == u'last'][0]
103+ .find(u'a').get(u'href'))
104+
105+ story = self.random_pool.pop()
106
107 else:
108 try:
109- if site == 'mlia':
110- if query.isdigit():
111- surl = url + '/s/' + query
112- else:
113- surl = url + '/best/' + query
114+ if query.isdigit():
115+ surl = url + '/s/' + query
116 else:
117- if query.isdigit():
118- surl = url + 'story.php?' + urlencode({'id': query})
119- else:
120- surl = url + 'index.php?' + urlencode({'part': query})
121+ surl = url + '/best/' + query
122
123- story = self.find_stories(surl, site=site).next()
124+ story = self.find_stories(surl).next()
125
126 except StopIteration:
127 event.addresponse(u'No such quote')
128 return
129
130 id, body = story
131- if site == 'mlia':
132- url += 's/%i' % id
133- else:
134- url += 'story.php?id=%i' % id
135+ url += 's/%i' % id
136 event.addresponse(u'%(body)s\n- %(url)s', {
137 'url': url,
138 'body': body,
139 })
140
141- @match(r'^(?:http://)?(?:www\.)?mylifeis(average|g)\.com'
142- r'/story\.php\?id=(\d+)$')
143- def mlia_url(self, event, site, id):
144- self.mlia(event, 'mli' + site[0].lower(), id)
145+ @match(r'^(?:http://)?(?:www\.)?mylifeisaverage\.com'
146+ r'/s/(\d+)$')
147+ def mlia_url(self, event, id):
148+ self.mlia(event, id)
149
150 features['bible'] = {
151 'description': u'Retrieves Bible verses',

Subscribers

People subscribed via source and target branches