Merge lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote into lp:~cairo-dock-team/cairo-dock-plug-ins-extras/third-party
- Quote
- Merge into third-party
Proposed by
Eduardo Mucelli Rezende Oliveira
Status: | Merged |
---|---|
Merged at revision: | 265 |
Proposed branch: | lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote |
Merge into: | lp:~cairo-dock-team/cairo-dock-plug-ins-extras/third-party |
Diff against target: |
399 lines (+177/-23) 14 files modified
Quote/ChangeLog (+1/-0) Quote/DanstonchatParser.py (+1/-0) Quote/FmylifeParser.py (+42/-0) Quote/HundredblaguesParser.py (+51/-0) Quote/JokestogoParser.py (+1/-0) Quote/QdbParser.py (+1/-0) Quote/QuotationspageParser.py (+1/-0) Quote/Quote (+30/-19) Quote/Quote.conf (+2/-2) Quote/VidademerdaParser.py (+1/-0) Quote/ViedemerdeParser.py (+1/-0) Quote/VitadimerdaParser.py (+42/-0) Quote/XkcdbParser.py (+1/-0) Quote/auto-load.conf (+2/-2) |
To merge this branch: | bzr merge lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Cairo-Dock Devs | Pending | ||
Review via email: mp+105717@code.launchpad.net |
Commit message
Description of the change
Quote: Added Fmylife.com, Vitadimerda.it, and 100blagues.com.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Quote/ChangeLog' |
2 | --- Quote/ChangeLog 2012-05-13 12:19:19 +0000 |
3 | +++ Quote/ChangeLog 2012-05-14 20:28:17 +0000 |
4 | @@ -1,3 +1,4 @@ |
5 | +0.1.3:(May/13/2012): Added Fmylife.com, Vitadimerda.it, and 100blagues.com. |
6 | 0.1:(May/13/2012): Added Viedemerde.fr, and more documentation on the code |
7 | 0.0.9:(March/28/2012): Removed Grouphug.us because it is not offering the random quote anymore. Fixing the return from Bash and Qdb. |
8 | 0.0.8:(March/17/2010): Added Grouphug.us. |
9 | |
10 | === modified file 'Quote/DanstonchatParser.py' |
11 | --- Quote/DanstonchatParser.py 2011-02-22 02:08:47 +0000 |
12 | +++ Quote/DanstonchatParser.py 2012-05-14 20:28:17 +0000 |
13 | @@ -9,6 +9,7 @@ |
14 | |
15 | def reset(self): |
16 | SGMLParser.reset(self) |
17 | + self.name = "Danstonchat.com" |
18 | self.url = "http://danstonchat.com/random.html" |
19 | self.quote = [] |
20 | self.inside_div_element = False # indica se o parser esta dentro de <span></span> tag |
21 | |
22 | === added file 'Quote/FmylifeParser.py' |
23 | --- Quote/FmylifeParser.py 1970-01-01 00:00:00 +0000 |
24 | +++ Quote/FmylifeParser.py 2012-05-14 20:28:17 +0000 |
25 | @@ -0,0 +1,42 @@ |
26 | +# This is a part of the external Quote applet for Cairo-Dock |
27 | +# |
28 | +# Author: Eduardo Mucelli Rezende Oliveira |
29 | +# E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br |
30 | + |
31 | +from sgmllib import SGMLParser |
32 | + |
33 | +class FmylifeParser(SGMLParser): |
34 | + |
35 | + def reset(self): |
36 | + SGMLParser.reset(self) |
37 | + self.url = "http://www.fmylife.com/random" |
38 | + self.quote = [] # list of quotes to be filled |
39 | + self.inside_div_element = False # indicates if the parser is inside the <div></div> tag |
40 | + self.inside_div_p_element = False |
41 | + self.current_quote = "" |
42 | + |
43 | + def start_div(self, attrs): |
44 | + for name, value in attrs: |
45 | + if name == "class" and value == "post article": # <div class="post article">...</div> |
46 | + self.inside_div_element = True |
47 | + |
48 | + def end_div(self): |
49 | + self.inside_div_element = False |
50 | + |
51 | + def start_p(self, attrs): |
52 | + if self.inside_div_element: |
53 | + self.inside_div_p_element = True # Parser is inside <div><p>...</p></div> |
54 | + |
55 | + def end_p(self): |
56 | + if self.inside_div_p_element: # if this is the end of our specific <div><p> tag, |
57 | + self.quote.append(self.current_quote) # append the whole content found inside <div><p>...</p></div>, |
58 | + self.current_quote = "" # clear it for the next quote, |
59 | + self.inside_div_p_element = False # and mark as finished tag |
60 | + |
61 | + def handle_data(self, text): |
62 | + if self.inside_div_p_element: # Concatenate all the content inside <div><p>...</p></div> |
63 | + self.current_quote += text |
64 | + |
65 | + def parse(self, page): |
66 | + self.feed(page) # feed the parser with the page's html |
67 | + self.close() |
68 | |
69 | === added file 'Quote/HundredblaguesParser.py' |
70 | --- Quote/HundredblaguesParser.py 1970-01-01 00:00:00 +0000 |
71 | +++ Quote/HundredblaguesParser.py 2012-05-14 20:28:17 +0000 |
72 | @@ -0,0 +1,51 @@ |
73 | +# This is a part of the external Quote applet for Cairo-Dock |
74 | +# |
75 | +# Author: Eduardo Mucelli Rezende Oliveira |
76 | +# E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br |
77 | + |
78 | +from sgmllib import SGMLParser |
79 | + |
80 | +class HundredblaguesParser(SGMLParser): |
81 | + |
82 | + def reset(self): |
83 | + SGMLParser.reset(self) |
84 | + self.url = "http://www.100blagues.com/random" |
85 | + self.quote = [] # list of quotes to be filled |
86 | + self.inside_div_element = False # indicates if the parser is inside the <div></div> tag |
87 | + self.inside_div_p_element = False |
88 | + self.inside_div_p_a_element = False |
89 | + self.current_quote = "" |
90 | + |
91 | + def start_div(self, attrs): |
92 | + for name, value in attrs: |
93 | + if name == "class" and value == "post": # <div class="post">...</div> |
94 | + self.inside_div_element = True |
95 | + |
96 | + def end_div(self): |
97 | + self.inside_div_element = False |
98 | + |
99 | + def start_p(self, attrs): |
100 | + if self.inside_div_element: |
101 | + self.inside_div_p_element = True # Parser is inside <div><p>...</p></div> |
102 | + |
103 | + def end_p(self): |
104 | + if self.inside_div_p_element: # if this is the end of our specific <div><p> tag, |
105 | + self.inside_div_p_element = False |
106 | + |
107 | + def start_a(self, attrs): |
108 | + if self.inside_div_p_element: |
109 | + self.inside_div_p_a_element = True |
110 | + |
111 | + def end_a(self): |
112 | + if self.inside_div_p_a_element: |
113 | + self.quote.append(self.current_quote) # append the whole content found inside <div><p><a>...</a></p></div>, |
114 | + self.current_quote = "" # clear it for the next quote, |
115 | + self.inside_div_p_a_element = False # and mark as finished tag |
116 | + |
117 | + def handle_data(self, text): |
118 | + if self.inside_div_p_a_element: # Concatenate all the content inside <div><p><a>...</a></p></div> |
119 | + self.current_quote += text |
120 | + |
121 | + def parse(self, page): |
122 | + self.feed(page) # feed the parser with the page's html |
123 | + self.close() |
124 | |
125 | === modified file 'Quote/JokestogoParser.py' |
126 | --- Quote/JokestogoParser.py 2010-12-02 10:17:59 +0000 |
127 | +++ Quote/JokestogoParser.py 2012-05-14 20:28:17 +0000 |
128 | @@ -9,6 +9,7 @@ |
129 | |
130 | def reset(self): |
131 | SGMLParser.reset(self) |
132 | + self.name = "Jokes2go.com" |
133 | self.url = "http://www.jokes2go.com/cgi-perl/randjoke.cgi?type=j" |
134 | self.quote = [] |
135 | self.inside_pre_element = False # indica se o parser esta dentro de <pre></pre> tag |
136 | |
137 | === modified file 'Quote/QdbParser.py' |
138 | --- Quote/QdbParser.py 2012-03-28 20:50:03 +0000 |
139 | +++ Quote/QdbParser.py 2012-05-14 20:28:17 +0000 |
140 | @@ -9,6 +9,7 @@ |
141 | |
142 | def reset(self): |
143 | SGMLParser.reset(self) |
144 | + self.name = "Qdb.us" |
145 | self.url = "http://www.qdb.us/random" |
146 | self.quote = [] |
147 | self.inside_span_element = False # indica se o parser esta dentro de <span></span> tag |
148 | |
149 | === modified file 'Quote/QuotationspageParser.py' |
150 | --- Quote/QuotationspageParser.py 2010-11-23 21:01:19 +0000 |
151 | +++ Quote/QuotationspageParser.py 2012-05-14 20:28:17 +0000 |
152 | @@ -9,6 +9,7 @@ |
153 | |
154 | def reset(self): |
155 | SGMLParser.reset(self) |
156 | + self.name = "Quotationspage.com" |
157 | self.url = "http://www.quotationspage.com/qotd.html" |
158 | self.quote = [] |
159 | self.author = [] |
160 | |
161 | === modified file 'Quote/Quote' |
162 | --- Quote/Quote 2012-05-13 12:19:19 +0000 |
163 | +++ Quote/Quote 2012-05-14 20:28:17 +0000 |
164 | @@ -46,9 +46,12 @@ |
165 | from JokestogoParser import JokestogoParser # Jokes2go.com |
166 | from VidademerdaParser import VidademerdaParser # Vidademerda.com.br |
167 | from ViedemerdeParser import ViedemerdeParser # Viedemerde.fr |
168 | +from FmylifeParser import FmylifeParser # Fmylife.com |
169 | +from VitadimerdaParser import VitadimerdaParser # VitadimerdaParser.it |
170 | +from HundredblaguesParser import HundredblaguesParser # HundredblaguesParser.com |
171 | |
172 | -# quotationspage = 0, bash = 1, xkcdb = 2, qdb = 3, danstonchat = 4, jokestogo = 5, vidademerda = 6, viedemerde = 7 |
173 | -quotationspage, bash, xkcdb, qdb, danstonchat, jokestogo, vidademerda, viedemerde = range(8) |
174 | +# quotationspage = 0, bash = 1, xkcdb = 2, qdb = 3, danstonchat = 4, jokestogo = 5, vidademerda = 6, viedemerde = 7, fmylife = 8, vitadimerda = 9, hundredblagues = 10 |
175 | +quotationspage, bash, xkcdb, qdb, danstonchat, jokestogo, vidademerda, viedemerde, fmylife, vitadimerda, hundredblagues = range(11) |
176 | |
177 | class AgentOpener(FancyURLopener): |
178 | """Masked user-agent otherwise the access would be forbidden""" |
179 | @@ -62,22 +65,28 @@ |
180 | self.quote = [] # List of quotes of the current source |
181 | |
182 | def fetch(self): |
183 | - if (self.source == quotationspage): |
184 | + if self.source == quotationspage: |
185 | parser = QuotationspageParser() # QuotationspageParser.py |
186 | - elif (self.source == bash): |
187 | + elif self.source == bash: |
188 | parser = BashParser() # BashParser.py |
189 | - elif (self.source == xkcdb): |
190 | + elif self.source == xkcdb: |
191 | parser = XkcdbParser() # XkcdbParser.py |
192 | - elif (self.source == qdb): |
193 | + elif self.source == qdb: |
194 | parser = QdbParser() # QdbParser.py |
195 | - elif (self.source == danstonchat): |
196 | + elif self.source == danstonchat: |
197 | parser = DanstonchatParser() # DanstonchatParser.py |
198 | - elif (self.source == jokestogo): |
199 | + elif self.source == jokestogo: |
200 | parser = JokestogoParser() |
201 | - elif (self.source == vidademerda): # VidademerdaParser.py |
202 | + elif self.source == vidademerda: # VidademerdaParser.py |
203 | parser = VidademerdaParser() |
204 | - else: # ViedemerdeParser.py |
205 | - parser = ViedemerdeParser() |
206 | + elif self.source == viedemerde: |
207 | + parser = ViedemerdeParser() # ViedemerdeParser.py |
208 | + elif self.source == fmylife: |
209 | + parser = FmylifeParser() # FmylifeParser.py |
210 | + elif self.source == vitadimerda: |
211 | + parser = VitadimerdaParser() # VitadimerdaParser.py |
212 | + else: |
213 | + parser = HundredblaguesParser() |
214 | |
215 | opener = AgentOpener() # opens the web connection with masked user-agent |
216 | |
217 | @@ -88,13 +97,14 @@ |
218 | else: |
219 | parser.parse(page.read()) # feed the parser with the page's content |
220 | page.close() # close the page connection |
221 | - |
222 | + |
223 | # Handle different kind of returns from the parser. It is necessary because some sources return quotes with extra |
224 | # characters that we need to filter here. Some come with extra '', others come with linebreaks, etc. |
225 | + |
226 | if (self.source == quotationspage): |
227 | self.quote = parser.quote |
228 | self.author = parser.author |
229 | - elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat or self.source == viedemerde): |
230 | + elif self.source in [bash, xkcdb, qdb, danstonchat, viedemerde, fmylife, vitadimerda, hundredblagues]: |
231 | self.quote = filter(None, parser.quote) # remove the '' from the array |
232 | elif self.source == jokestogo: # jokestogo |
233 | self.quote = filter(self.linebreak, parser.quote) # remove linebreak from the array |
234 | @@ -116,7 +126,8 @@ |
235 | self.copy_current_quote_key = 0 |
236 | self.go_next_quote_key = 1 |
237 | self.source = quotationspage |
238 | - self.cSiteNames = ['Quotationspage.com','Bash.org','Xkcdb.com','Qdb.us','Danstonchat.com','Jokes2go.com','Vidademerda.com.br', 'Viedemerde.fr'] |
239 | + self.names = ["Quotationspage.com","Bash.org","Xkcdb.com","Qdb.us","Danstonchat.com","Jokes2go.com", |
240 | + "Vidademerda.com.br","Viedemerde.fr","Fmylife.com", "Vitadimerda.it", "100blagues.com"] |
241 | |
242 | CDApplet.__init__(self) # call high-level init |
243 | |
244 | @@ -141,7 +152,7 @@ |
245 | def show_quote(self): |
246 | if (self.source == quotationspage): |
247 | self.quotation = "\"%s\" ~ %s" % (self.quotes.next(), self.authors.next()) # quote[x] ~ author[x] |
248 | - elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat or self.source == viedemerde): |
249 | + elif self.source in [bash, xkcdb, qdb, danstonchat, viedemerde, fmylife, vitadimerda, hundredblagues]: |
250 | try: # check if it is possible to show the already stored quotes |
251 | current = self.quotes.next() |
252 | except StopIteration: # all were already shown |
253 | @@ -162,14 +173,14 @@ |
254 | def inform_end_of_waiting_process(self): |
255 | self.icon.SetQuickInfo("") |
256 | |
257 | - def _display_site_name(self): |
258 | + def display_source_name(self): |
259 | if self.config['default title'] == "": |
260 | - self.icon.SetLabel(self.cSiteNames[self.source]) |
261 | + self.icon.SetLabel(self.names[self.source]) |
262 | |
263 | # Inherited methods from CDApplet |
264 | def begin(self): |
265 | self.get_quotes_from_web() |
266 | - self._display_site_name() |
267 | + self.display_source_name() |
268 | |
269 | def get_config(self, keyfile): |
270 | self.source = keyfile.getint('Configuration', 'source') # get the source of quotations |
271 | @@ -177,7 +188,7 @@ |
272 | |
273 | def reload(self): |
274 | self.get_quotes_from_web() # refresh the quotations |
275 | - self._display_site_name() |
276 | + self.display_source_name() |
277 | |
278 | # Callbacks |
279 | def on_click(self, key): |
280 | |
281 | === modified file 'Quote/Quote.conf' |
282 | --- Quote/Quote.conf 2012-05-13 12:19:19 +0000 |
283 | +++ Quote/Quote.conf 2012-05-14 20:28:17 +0000 |
284 | @@ -1,4 +1,4 @@ |
285 | -#0.1 |
286 | +#0.1.3 |
287 | |
288 | #[gtk-about] |
289 | [Icon] |
290 | @@ -102,5 +102,5 @@ |
291 | |
292 | #[gtk-preferences] |
293 | [Configuration] |
294 | -#l[Quotationspage.com;Bash.org;Xkcdb.com;Qdb.us;Danstonchat.com;Jokes2go.com;Vidademerda.com.br;Viedemerde.fr] Quote source: |
295 | +#l[Quotationspage.com;Bash.org;Xkcdb.com;Qdb.us;Danstonchat.com;Jokes2go.com;Vidademerda.com.br;Viedemerde.fr;Fmylife.com;Vitadimerda.it;100blagues.com] Quote source: |
296 | source = 1 |
297 | |
298 | === modified file 'Quote/VidademerdaParser.py' |
299 | --- Quote/VidademerdaParser.py 2011-01-27 16:46:43 +0000 |
300 | +++ Quote/VidademerdaParser.py 2012-05-14 20:28:17 +0000 |
301 | @@ -9,6 +9,7 @@ |
302 | |
303 | def reset(self): |
304 | SGMLParser.reset(self) |
305 | + self.name = "Vidademerda.com.br" |
306 | self.url = "http://vidademerda.com.br/aleatorias" |
307 | self.quote = [] |
308 | self.author = [] |
309 | |
310 | === modified file 'Quote/ViedemerdeParser.py' |
311 | --- Quote/ViedemerdeParser.py 2012-05-14 16:32:42 +0000 |
312 | +++ Quote/ViedemerdeParser.py 2012-05-14 20:28:17 +0000 |
313 | @@ -9,6 +9,7 @@ |
314 | |
315 | def reset(self): |
316 | SGMLParser.reset(self) |
317 | + self.name = "Viedemerde.fr" |
318 | self.url = "http://www.viedemerde.fr/aleatoire" |
319 | self.quote = [] # list of quotes to be filled |
320 | self.inside_div_element = False # indicates if the parser is inside the <div></div> tag |
321 | |
322 | === added file 'Quote/VitadimerdaParser.py' |
323 | --- Quote/VitadimerdaParser.py 1970-01-01 00:00:00 +0000 |
324 | +++ Quote/VitadimerdaParser.py 2012-05-14 20:28:17 +0000 |
325 | @@ -0,0 +1,42 @@ |
326 | +# This is a part of the external Quote applet for Cairo-Dock |
327 | +# |
328 | +# Author: Eduardo Mucelli Rezende Oliveira |
329 | +# E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br |
330 | + |
331 | +from sgmllib import SGMLParser |
332 | + |
333 | +class VitadimerdaParser(SGMLParser): |
334 | + |
335 | + def reset(self): |
336 | + SGMLParser.reset(self) |
337 | + self.url = "http://www.vitadimerda.it/aleatorie" |
338 | + self.quote = [] # list of quotes to be filled |
339 | + self.inside_div_element = False # indicates if the parser is inside the <div></div> tag |
340 | + self.inside_div_p_element = False |
341 | + self.current_quote = "" |
342 | + |
343 | + def start_div(self, attrs): |
344 | + for name, value in attrs: |
345 | + if name == "class" and value == "post article": # <div class="post article">...</div> |
346 | + self.inside_div_element = True |
347 | + |
348 | + def end_div(self): |
349 | + self.inside_div_element = False |
350 | + |
351 | + def start_p(self, attrs): |
352 | + if self.inside_div_element: |
353 | + self.inside_div_p_element = True # Parser is inside <div><p>...</p></div> |
354 | + |
355 | + def end_p(self): |
356 | + if self.inside_div_p_element: # if this is the end of our specific <div><p> tag, |
357 | + self.quote.append(self.current_quote) # append the whole content found inside <div><p>...</p></div>, |
358 | + self.current_quote = "" # clear it for the next quote, |
359 | + self.inside_div_p_element = False # and mark as finished tag |
360 | + |
361 | + def handle_data(self, text): |
362 | + if self.inside_div_p_element: # Concatenate all the content inside <div><p>...</p></div> |
363 | + self.current_quote += text |
364 | + |
365 | + def parse(self, page): |
366 | + self.feed(page) # feed the parser with the page's html |
367 | + self.close() |
368 | |
369 | === modified file 'Quote/XkcdbParser.py' |
370 | --- Quote/XkcdbParser.py 2010-11-23 21:01:19 +0000 |
371 | +++ Quote/XkcdbParser.py 2012-05-14 20:28:17 +0000 |
372 | @@ -9,6 +9,7 @@ |
373 | |
374 | def reset(self): |
375 | SGMLParser.reset(self) |
376 | + self.name = "Xkcdb.com" |
377 | self.url = "http://www.xkcdb.com/?random" |
378 | self.quote = [] |
379 | self.inside_span_element = False # indica se o parser esta dentro de <p></p> tag |
380 | |
381 | === modified file 'Quote/auto-load.conf' |
382 | --- Quote/auto-load.conf 2012-05-13 12:19:19 +0000 |
383 | +++ Quote/auto-load.conf 2012-05-14 20:28:17 +0000 |
384 | @@ -4,13 +4,13 @@ |
385 | author = Eduardo Mucelli Rezende Oliveira |
386 | |
387 | # A short description of the applet and how to use it. |
388 | -description = This applet provides a "Quote of the day" feature from some internet sources such as:\n Quotationspage.com, Bash.org, Xkcdb.com, Qdb.us, Danstonchat.com, Jokes2go.com, Vidademerda.com.br, and Viedemerde.fr |
389 | +description = This applet provides a "Quote of the day" feature from some internet sources such as:\n Quotationspage.com, Bash.org, Xkcdb.com, Qdb.us, Danstonchat.com, Jokes2go.com, Vidademerda.com.br, Viedemerde.fr, Fmylife.com, Vitadimerda.it, and 100blagues.com. |
390 | |
391 | # Category of the applet : 2 = files, 3 = internet, 4 = Desktop, 5 = accessory, 6 = system, 7 = fun |
392 | category = 7 |
393 | |
394 | # Version of the applet; change it everytime you change something in the config file. Don't forget to update the version both in this file and in the config file. |
395 | -version = 0.1 |
396 | +version = 0.1.3 |
397 | |
398 | # Whether the applet can be instanciated several times or not. |
399 | multi-instance = true |