Merge lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote into lp:~cairo-dock-team/cairo-dock-plug-ins-extras/third-party

Proposed by Eduardo Mucelli Rezende Oliveira
Status: Merged
Merged at revision: 102
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: 494 lines (+226/-158)
8 files modified
Quote/BashParser.py (+35/-0)
Quote/DanstonchatParser.py (+35/-0)
Quote/QdbParser.py (+35/-0)
Quote/QuotationspageParser.py (+63/-0)
Quote/Quote (+18/-154)
Quote/Quote.conf (+2/-2)
Quote/XkcdbParser.py (+36/-0)
Quote/auto-load.conf (+2/-2)
To merge this branch: bzr merge lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote
Reviewer Review Type Date Requested Status
Cairo-Dock Devs Pending
Review via email: mp+41657@code.launchpad.net

Description of the change

Added Danstonchat.com. Changed the icon, now the lamp was turned on :¬) Huge code modularization.

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=== added file 'Quote/BashParser.py'
2--- Quote/BashParser.py 1970-01-01 00:00:00 +0000
3+++ Quote/BashParser.py 2010-11-23 21:19:25 +0000
4@@ -0,0 +1,35 @@
5+# This is a part of the external Quote applet for Cairo-Dock
6+#
7+# Author: Eduardo Mucelli Rezende Oliveira
8+# E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br
9+
10+from sgmllib import SGMLParser
11+
12+class BashParser(SGMLParser):
13+
14+ def reset(self):
15+ SGMLParser.reset(self)
16+ self.url = "http://bash.org/?random"
17+ self.quote = []
18+ self.inside_p_element = False # indica se o parser esta dentro de <p></p> tag
19+ self.current_quote = ""
20+
21+ def start_p(self, attrs):
22+ for name, value in attrs:
23+ if name == "class" and value == "qt": # <p class="qt">...</p>
24+ self.inside_p_element = True
25+
26+ def end_p(self):
27+ self.inside_p_element = False
28+ self.quote.append(self.current_quote) # adiciona o conteudo completo da tag
29+ self.current_quote = "" # reinicia o armazenador do conteudo
30+
31+ def handle_data(self, text):
32+ if self.inside_p_element: # estamos dentro de <p>...</p>
33+ text = text.replace('<', '[') # se a string contem '<nome>', gera o erro na hora do ShowDialog
34+ text = text.replace('>', ']') # pango_layout_set_markup_with_accel: Unknown tag 'nome'
35+ self.current_quote += text # concatena tudo que tiver dentro da tag
36+
37+ def parse(self, page):
38+ self.feed(page) # feed the parser with the page's html
39+ self.close()
40
41=== added file 'Quote/DanstonchatParser.py'
42--- Quote/DanstonchatParser.py 1970-01-01 00:00:00 +0000
43+++ Quote/DanstonchatParser.py 2010-11-23 21:19:25 +0000
44@@ -0,0 +1,35 @@
45+# This is a part of the external Quote applet for Cairo-Dock
46+#
47+# Author: Eduardo Mucelli Rezende Oliveira
48+# E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br
49+
50+from sgmllib import SGMLParser
51+
52+class DanstonchatParser(SGMLParser):
53+
54+ def reset(self):
55+ SGMLParser.reset(self)
56+ self.url = "http://danstonchat.com/random.html"
57+ self.quote = []
58+ self.inside_div_element = False # indica se o parser esta dentro de <span></span> tag
59+ self.current_quote = ""
60+
61+ def start_div(self, attrs):
62+ for name, value in attrs:
63+ if name == "class" and value == "item-content": # <span class="qt">...</span>
64+ self.inside_div_element = True
65+
66+ def end_div(self):
67+ self.inside_div_element = False
68+ self.quote.append(self.current_quote) # adiciona o conteudo completo da tag
69+ self.current_quote = "" # reinicia o armazenador do conteudo
70+
71+ def handle_data(self, text):
72+ if self.inside_div_element: # estamos dentro de <span>...</span>
73+ text = text.replace('<', '[') # se a string contem '<nome>', gera o erro na hora do ShowDialog
74+ text = text.replace('>', ']') # pango_layout_set_markup_with_accel: Unknown tag 'nome'
75+ self.current_quote += text # concatena tudo que tiver dentro da tag
76+
77+ def parse(self, page):
78+ self.feed(page) # feed the parser with the page's html
79+ self.close()
80
81=== added file 'Quote/QdbParser.py'
82--- Quote/QdbParser.py 1970-01-01 00:00:00 +0000
83+++ Quote/QdbParser.py 2010-11-23 21:19:25 +0000
84@@ -0,0 +1,35 @@
85+# This is a part of the external Quote applet for Cairo-Dock
86+#
87+# Author: Eduardo Mucelli Rezende Oliveira
88+# E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br
89+
90+from sgmllib import SGMLParser
91+
92+class QdbParser(SGMLParser):
93+
94+ def reset(self):
95+ SGMLParser.reset(self)
96+ self.url = "http://www.qdb.us/random"
97+ self.quote = []
98+ self.inside_span_element = False # indica se o parser esta dentro de <span></span> tag
99+ self.current_quote = ""
100+
101+ def start_span(self, attrs):
102+ for name, value in attrs:
103+ if name == "class" and value == "qt": # <span class="qt">...</span>
104+ self.inside_span_element = True
105+
106+ def end_span(self):
107+ self.inside_span_element = False
108+ self.quote.append(self.current_quote) # adiciona o conteudo completo da tag
109+ self.current_quote = "" # reinicia o armazenador do conteudo
110+
111+ def handle_data(self, text):
112+ if self.inside_span_element: # estamos dentro de <span>...</span>
113+ text = text.replace('<', '[') # se a string contem '<nome>', gera o erro na hora do ShowDialog
114+ text = text.replace('>', ']') # pango_layout_set_markup_with_accel: Unknown tag 'nome'
115+ self.current_quote += text # concatena tudo que tiver dentro da tag
116+
117+ def parse(self, page):
118+ self.feed(page) # feed the parser with the page's html
119+ self.close()
120
121=== added file 'Quote/QuotationspageParser.py'
122--- Quote/QuotationspageParser.py 1970-01-01 00:00:00 +0000
123+++ Quote/QuotationspageParser.py 2010-11-23 21:19:25 +0000
124@@ -0,0 +1,63 @@
125+# This is a part of the external Quote applet for Cairo-Dock
126+#
127+# Author: Eduardo Mucelli Rezende Oliveira
128+# E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br
129+
130+from sgmllib import SGMLParser
131+
132+class QuotationspageParser(SGMLParser):
133+
134+ def reset(self):
135+ SGMLParser.reset(self)
136+ self.url = "http://www.quotationspage.com/qotd.html"
137+ self.quote = []
138+ self.author = []
139+ self.inside_dt_a_element = False # indica se o parser esta dentro de <dt><a></a></dt> tag
140+ self.inside_dt_element = False # indica se o parser esta dentro de <dt></dt> tag
141+
142+ self.inside_dd_element = False # indica se o parser esta dentro de <dd></dd> tag
143+ self.inside_dd_b_element = False # indica se o parser esta dentro de <dt><b><b></dt> tag
144+ self.inside_dd_b_a_element = False # indica se o parser esta dentro de <dt><b><a><a><b></dt> tag
145+
146+ def start_dt(self, attrs):
147+ for name, value in attrs:
148+ if name == "class" and value == "quote": # <dt class="quote">...</dt>
149+ self.inside_dt_element = True
150+
151+ def end_dt(self):
152+ self.inside_dt_element = False
153+
154+ def start_dd(self, attrs):
155+ for name, value in attrs:
156+ if name == "class" and value == "author": # <dd class="author">...</dd>
157+ self.inside_dd_element = True
158+
159+ def end_dd(self):
160+ self.inside_dd_element = False
161+
162+ def start_b(self, attrs):
163+ if self.inside_dd_element:
164+ self.inside_dd_b_element = True
165+
166+ def end_b(self):
167+ self.inside_dd_b_element = False
168+
169+ def start_a(self, attrs):
170+ if self.inside_dt_element:
171+ self.inside_dt_a_element = True # <dt class="quote"><a>Quote</a></dt>
172+ if self.inside_dd_b_element:
173+ self.inside_dd_b_a_element = True # <dd class="author"><b><a>Quote</a></b></dd>
174+
175+ def end_a(self):
176+ self.inside_dt_a_element = False
177+ self.inside_dd_b_a_element = False
178+
179+ def handle_data(self, text):
180+ if self.inside_dt_a_element: # estamos dentro de <dt><a>...</a></dt>
181+ self.quote.append(text)
182+ if self.inside_dd_b_a_element: # estamos dentro de <dd><b><a>...</a></b></dd>
183+ self.author.append(text)
184+
185+ def parse(self, page):
186+ self.feed(page) # feed the parser with the page's html
187+ self.close()
188
189=== modified file 'Quote/Quote'
190--- Quote/Quote 2010-11-23 14:24:56 +0000
191+++ Quote/Quote 2010-11-23 21:19:25 +0000
192@@ -16,7 +16,7 @@
193 # GNU General Public License for more details.
194
195 # This applet provides a "Quote of the day" feature from some internet sources
196-# such as Quotationspage.com, Bash.org, Xkcdb.com, and Qdb.us
197+# such as Quotationspage.com, Bash.org, Xkcdb.com, Qdb.us, and Danstonchat.fr
198
199 import gobject, dbus, os, urllib, gtk, ConfigParser, itertools
200 from dbus.mainloop.glib import DBusGMainLoop
201@@ -25,154 +25,20 @@
202 from urllib import FancyURLopener
203 from util import log
204
205+from BashParser import BashParser # Bash.org
206+from QdbParser import QdbParser # Qdb.us
207+from XkcdbParser import XkcdbParser # Xkcdb.com
208+from QuotationspageParser import QuotationspageParser # Quotationspage.com
209+from DanstonchatParser import DanstonchatParser # Danstonchat.fr
210+
211 DBusGMainLoop(set_as_default=True)
212
213-quotationspage, bash, xkcdb, qdb = range(4) # quotationspage = 0, bash = 1, xkcdb = 2, qdb = 3
214+quotationspage, bash, xkcdb, qdb, danstonchat = range(5) # quotationspage = 0, bash = 1, xkcdb = 2, qdb = 3, danstonchat = 4
215
216 class AgentOpener(FancyURLopener):
217 """Masked user-agent otherwise the access would be forbidden"""
218 version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'
219
220-class BashParser(SGMLParser):
221-
222- def reset(self):
223- SGMLParser.reset(self)
224- self.quote = []
225- self.inside_p_element = False # indica se o parser esta dentro de <p></p> tag
226- self.current_quote = ""
227-
228- def start_p(self, attrs):
229- for name, value in attrs:
230- if name == "class" and value == "qt": # <p class="qt">...</p>
231- self.inside_p_element = True
232-
233- def end_p(self):
234- self.inside_p_element = False
235- self.quote.append(self.current_quote) # adiciona o conteudo completo da tag
236- self.current_quote = "" # reinicia o armazenador do conteudo
237-
238- def handle_data(self, text):
239- if self.inside_p_element: # estamos dentro de <p>...</p>
240- text = text.replace('<', '[') # se a string contem '<nome>', gera o erro na hora do ShowDialog
241- text = text.replace('>', ']') # pango_layout_set_markup_with_accel: Unknown tag 'nome'
242- self.current_quote += text # concatena tudo que tiver dentro da tag
243-
244- def parse(self, page):
245- self.feed(page) # feed the parser with the page's html
246- self.close()
247-
248-class QdbParser(SGMLParser):
249-
250- def reset(self):
251- SGMLParser.reset(self)
252- self.quote = []
253- self.inside_span_element = False # indica se o parser esta dentro de <span></span> tag
254- self.current_quote = ""
255-
256- def start_span(self, attrs):
257- for name, value in attrs:
258- if name == "class" and value == "qt": # <span class="qt">...</span>
259- self.inside_span_element = True
260-
261- def end_span(self):
262- self.inside_span_element = False
263- self.quote.append(self.current_quote) # adiciona o conteudo completo da tag
264- self.current_quote = "" # reinicia o armazenador do conteudo
265-
266- def handle_data(self, text):
267- if self.inside_span_element: # estamos dentro de <span>...</span>
268- text = text.replace('<', '[') # se a string contem '<nome>', gera o erro na hora do ShowDialog
269- text = text.replace('>', ']') # pango_layout_set_markup_with_accel: Unknown tag 'nome'
270- self.current_quote += text # concatena tudo que tiver dentro da tag
271-
272- def parse(self, page):
273- self.feed(page) # feed the parser with the page's html
274- self.close()
275-
276-class XkcdbParser(SGMLParser):
277-
278- def reset(self):
279- SGMLParser.reset(self)
280- self.quote = []
281- self.inside_span_element = False # indica se o parser esta dentro de <p></p> tag
282- self.current_quote = ""
283-
284- def start_span(self, attrs):
285- for name, value in attrs:
286- if name == "class" and value == "quote": # <p class="qt">...</p>
287- self.inside_span_element = True
288-
289- def end_span(self):
290- self.inside_span_element = False
291- self.quote.append(self.current_quote) # adiciona o conteudo completo da tag
292- self.current_quote = "" # reinicia o armazenador do conteudo
293-
294- def handle_data(self, text):
295- if self.inside_span_element: # estamos dentro de <dt><a>...</a></dt>
296- text = text.replace('<', '[') # se a string contem '<nome>', gera o erro na hora do ShowDialog
297- text = text.replace('>', ']') # pango_layout_set_markup_with_accel: Unknown tag 'nome'
298- self.current_quote += text # concatena tudo que tiver dentro da tag
299-
300- def parse(self, page):
301- self.feed(page) # feed the parser with the page's html
302- self.close()
303-
304-class QuotationspageParser(SGMLParser):
305-
306- def reset(self):
307- SGMLParser.reset(self)
308- self.quote = []
309- self.author = []
310- self.inside_dt_a_element = False # indica se o parser esta dentro de <dt><a></a></dt> tag
311- self.inside_dt_element = False # indica se o parser esta dentro de <dt></dt> tag
312-
313- self.inside_dd_element = False # indica se o parser esta dentro de <dd></dd> tag
314- self.inside_dd_b_element = False # indica se o parser esta dentro de <dt><b><b></dt> tag
315- self.inside_dd_b_a_element = False # indica se o parser esta dentro de <dt><b><a><a><b></dt> tag
316-
317- def start_dt(self, attrs):
318- for name, value in attrs:
319- if name == "class" and value == "quote": # <dt class="quote">...</dt>
320- self.inside_dt_element = True
321-
322- def end_dt(self):
323- self.inside_dt_element = False
324-
325- def start_dd(self, attrs):
326- for name, value in attrs:
327- if name == "class" and value == "author": # <dd class="author">...</dd>
328- self.inside_dd_element = True
329-
330- def end_dd(self):
331- self.inside_dd_element = False
332-
333- def start_b(self, attrs):
334- if self.inside_dd_element:
335- self.inside_dd_b_element = True
336-
337- def end_b(self):
338- self.inside_dd_b_element = False
339-
340- def start_a(self, attrs):
341- if self.inside_dt_element:
342- self.inside_dt_a_element = True # <dt class="quote"><a>Quote</a></dt>
343- if self.inside_dd_b_element:
344- self.inside_dd_b_a_element = True # <dd class="author"><b><a>Quote</a></b></dd>
345-
346- def end_a(self):
347- self.inside_dt_a_element = False
348- self.inside_dd_b_a_element = False
349-
350- def handle_data(self, text):
351- if self.inside_dt_a_element: # estamos dentro de <dt><a>...</a></dt>
352- self.quote.append(text)
353- if self.inside_dd_b_a_element: # estamos dentro de <dd><b><a>...</a></b></dd>
354- self.author.append(text)
355-
356- def parse(self, page):
357- self.feed(page) # feed the parser with the page's html
358- self.close()
359-
360 class Interface:
361
362 def __init__(self, source):
363@@ -182,31 +48,29 @@
364
365 def fetch(self):
366 if (self.source == quotationspage):
367- parser = QuotationspageParser() # create the parser
368- url = "http://www.quotationspage.com/qotd.html"
369+ parser = QuotationspageParser() # QuotationspageParser.py
370 elif (self.source == bash):
371- parser = BashParser() # create the parser
372- url = "http://bash.org/?random"
373+ parser = BashParser() # BashParser.py
374 elif (self.source == xkcdb):
375- parser = XkcdbParser()
376- url = "http://www.xkcdb.com/?random"
377+ parser = XkcdbParser() # XkcdbParser.py
378+ elif (self.source == qdb):
379+ parser = QdbParser() # QdbParser.py
380 else:
381- parser = QdbParser() # create the parser
382- url = "http://www.qdb.us/random"
383+ parser = DanstonchatParser() # DanstonchatParser.py
384
385 opener = AgentOpener() # opens the web connection with masked user-agent
386
387 try:
388- page = opener.open(url) # get the HTML
389+ page = opener.open(parser.url) # get the HTML
390 except IOError:
391- print ("Problem to open %s" % (url))
392+ print ("Problem to open %s" % (parser.url))
393 else:
394 parser.parse(page.read()) # feed the parser to get the specific content: translated text
395 page.close() # lets close the page connection
396 if (self.source == quotationspage):
397 self.quote = parser.quote
398 self.author = parser.author
399- elif (self.source == bash or self.source == xkcdb or self.source == qdb):
400+ elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat):
401 self.quote = parser.quote
402 self.quote = filter(None, self.quote) # retira os '' do array
403 return self.quote, self.author
404@@ -283,7 +147,7 @@
405 def show_quote(self):
406 if (self.source == quotationspage):
407 self.quotation = "\"%s\" ~ %s" % (self.quotes.next(), self.authors.next()) # N-esima quote refere-se ao N-esimo autor."quote[x]~author[x]"
408- elif (self.source == bash or self.source == xkcdb or self.source == qdb):
409+ elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat):
410 self.quotation = "%s" % self.quotes.next()
411 try:
412 self.icon.PopupDialog({'message':self.quotation, "buttons":"stock_copy;cancel"}, {})
413
414=== modified file 'Quote/Quote.conf'
415--- Quote/Quote.conf 2010-11-23 02:38:59 +0000
416+++ Quote/Quote.conf 2010-11-23 21:19:25 +0000
417@@ -1,4 +1,4 @@
418-#!en;0.0.3
419+#!en;0.0.4
420
421 #[gtk-about]
422 [Icon]
423@@ -89,5 +89,5 @@
424
425 #[gtk-preferences]
426 [Configuration]
427-#l[Quotationspage.com;Bash.org;Xkcdb.com;Qdb.us] Quote source:
428+#l[Quotationspage.com;Bash.org;Xkcdb.com;Qdb.us;Danstonchat.com] Quote source:
429 source = 0
430
431=== added file 'Quote/XkcdbParser.py'
432--- Quote/XkcdbParser.py 1970-01-01 00:00:00 +0000
433+++ Quote/XkcdbParser.py 2010-11-23 21:19:25 +0000
434@@ -0,0 +1,36 @@
435+# This is a part of the external Quote applet for Cairo-Dock
436+#
437+# Author: Eduardo Mucelli Rezende Oliveira
438+# E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br
439+
440+from sgmllib import SGMLParser
441+
442+class XkcdbParser(SGMLParser):
443+
444+ def reset(self):
445+ SGMLParser.reset(self)
446+ self.url = "http://www.xkcdb.com/?random"
447+ self.quote = []
448+ self.inside_span_element = False # indica se o parser esta dentro de <p></p> tag
449+ self.current_quote = ""
450+
451+ def start_span(self, attrs):
452+ for name, value in attrs:
453+ if name == "class" and value == "quote": # <p class="qt">...</p>
454+ self.inside_span_element = True
455+
456+ def end_span(self):
457+ self.inside_span_element = False
458+ self.quote.append(self.current_quote) # adiciona o conteudo completo da tag
459+ self.current_quote = "" # reinicia o armazenador do conteudo
460+
461+ def handle_data(self, text):
462+ if self.inside_span_element: # estamos dentro de <dt><a>...</a></dt>
463+ text = text.replace('<', '[') # se a string contem '<nome>', gera o erro na hora do ShowDialog
464+ text = text.replace('>', ']') # pango_layout_set_markup_with_accel: Unknown tag 'nome'
465+ self.current_quote += text # concatena tudo que tiver dentro da tag
466+
467+ def parse(self, page):
468+ self.feed(page) # feed the parser with the page's html
469+ self.close()
470+
471
472=== modified file 'Quote/auto-load.conf'
473--- Quote/auto-load.conf 2010-11-23 02:38:59 +0000
474+++ Quote/auto-load.conf 2010-11-23 21:19:25 +0000
475@@ -4,10 +4,10 @@
476 author = Eduardo Mucelli Rezende Oliveira
477
478 # A short description of the applet and how to use it.
479-description = This applet provides a "Quote of the day" feature from some internet sources \nsuch as Quotationspage.com, Bash.org, and Xkcdb.com
480+description = This applet provides a "Quote of the day" feature from some internet sources \nsuch as Quotationspage.com, Bash.org, Xkcdb.com, Qdb.us, and Danstonchat.com
481
482 # Category of the applet : 2 = files, 3 = internet, 4 = Desktop, 5 = accessory, 6 = system, 7 = fun
483 category = 7
484
485 # 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.
486-version = 0.0.3
487+version = 0.0.4
488
489=== modified file 'Quote/icon' (properties changed: +x to -x)
490Binary files Quote/icon 2010-11-21 15:12:33 +0000 and Quote/icon 2010-11-23 21:19:25 +0000 differ
491=== added file 'Quote/preview'
492Binary files Quote/preview 1970-01-01 00:00:00 +0000 and Quote/preview 2010-11-23 21:19:25 +0000 differ
493=== removed file 'Quote/preview.png'
494Binary files Quote/preview.png 2010-11-21 15:12:33 +0000 and Quote/preview.png 1970-01-01 00:00:00 +0000 differ

Subscribers

People subscribed via source and target branches