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: 250
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: 450 lines (+166/-210)
6 files modified
Quote/BashParser.py (+11/-10)
Quote/ChangeLog (+1/-0)
Quote/GroupHugParser.py (+0/-44)
Quote/QdbParser.py (+11/-10)
Quote/Quote (+142/-145)
Quote/Quote.conf (+1/-1)
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+99820@code.launchpad.net

Description of the change

Removed Grouphug.us because it is not offering the random quote anymore. Fixing the return from Bash and Qdb.

To post a comment you must log in.
Revision history for this message
Matthieu Baerts (matttbe) wrote :

Thank you :)

PS: just a detail :) is it possible to simply start you commit messages with the name of the applet which is updated with your revision? (e.g. "Quote: Removed Grouphug.us (...)")

Revision history for this message
Eduardo Mucelli Rezende Oliveira (eduardo-mucelli) wrote :

Sure.
On Mar 29, 2012 12:10 AM, "Matthieu Baerts" <email address hidden> wrote:

> Thank you :)
>
> PS: just a detail :) is it possible to simply start you commit messages
> with the name of the applet which is updated with your revision? (e.g.
> "Quote: Removed Grouphug.us (...)")
> --
>
> https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote/+merge/99820
> You are the owner of lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote.
>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Quote/BashParser.py'
2--- Quote/BashParser.py 2011-04-25 14:56:41 +0000
3+++ Quote/BashParser.py 2012-03-28 20:51:20 +0000
4@@ -28,16 +28,17 @@
5
6 def handle_data(self, text):
7 if self.inside_p_element: # estamos dentro de <p>...</p>
8- if not self.inside_nickname: # <nickname> quote
9- if text == '<': # entered the "nickname area"
10- self.inside_nickname = True
11- self.current_quote += '\n<' # linebreak
12- else:
13- self.current_quote += text # concatena tudo que tiver dentro da tag
14- else:
15- self.current_quote += text # concatenate all the nickname
16- if text == '>': # nickname is over
17- self.inside_nickname = False # set it
18+ self.current_quote += text
19+# if not self.inside_nickname: # <nickname> quote
20+# if text == '<': # entered the "nickname area"
21+# self.inside_nickname = True
22+# self.current_quote += '\n<' # linebreak
23+# else:
24+# self.current_quote += text # concatena tudo que tiver dentro da tag
25+# else:
26+# self.current_quote += text # concatenate all the nickname
27+# if text == '>': # nickname is over
28+# self.inside_nickname = False # set it
29
30 def parse(self, page):
31 self.feed(page) # feed the parser with the page's html
32
33=== modified file 'Quote/ChangeLog'
34--- Quote/ChangeLog 2011-03-17 13:32:10 +0000
35+++ Quote/ChangeLog 2012-03-28 20:51:20 +0000
36@@ -1,3 +1,4 @@
37+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.
38 0.0.8:(March/17/2010): Added Grouphug.us.
39 0.0.7:(January/27/2010): Fixing the message when there were no translation for only one word. Adding Vidademerda.com.br. Adding next quote button in the PopupDialog.
40 0.0.6:(December/22/2010): Automatic fetch more quotes when all of them were already showed to the user, except for Quotationspage.com.
41
42=== removed file 'Quote/GroupHugParser.py'
43--- Quote/GroupHugParser.py 2011-03-17 13:32:10 +0000
44+++ Quote/GroupHugParser.py 1970-01-01 00:00:00 +0000
45@@ -1,44 +0,0 @@
46-# This is a part of the external Quote applet for Cairo-Dock
47-#
48-# Author: Eduardo Mucelli Rezende Oliveira
49-# E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br
50-
51-from sgmllib import SGMLParser
52-
53-class GroupHugParser(SGMLParser):
54-
55- def reset(self):
56- SGMLParser.reset(self)
57- self.url = "http://grouphug.us/random"
58- self.quote = []
59- self.author = []
60- self.inside_div_element = False # indica dentro da <div class="content"></div> tag
61- self.inside_div_p_element = False # indica dentro da <div class="content"><p></p></div> tag
62- self.current_quote = ""
63-
64- def start_div(self, attrs):
65- for name, value in attrs:
66- if name == "class" and value == "content": # <dt class="content">...</dt>
67- self.inside_div_element = True
68-
69- def end_div(self):
70- if self.inside_div_element:
71- self.quote.append(self.current_quote)
72- self.current_quote = "" # reinicia o armazenador do conteudo
73- self.inside_div_element = False
74-
75- def start_p(self, attrs):
76- if self.inside_div_element:
77- self.inside_div_p_element = True
78-
79- def end_p(self):
80- # if self.inside_div_element:
81- self.inside_div_p_element = False
82- # adiciona o conteudo completo da tag
83- def handle_data(self, text):
84- if self.inside_div_p_element: # estamos dentro de <div><p>...</p></div>
85- self.current_quote += text
86-
87- def parse(self, page):
88- self.feed(page) # feed the parser with the page's html
89- self.close()
90
91=== modified file 'Quote/QdbParser.py'
92--- Quote/QdbParser.py 2011-04-25 14:56:41 +0000
93+++ Quote/QdbParser.py 2012-03-28 20:51:20 +0000
94@@ -27,16 +27,17 @@
95
96 def handle_data(self, text):
97 if self.inside_span_element: # estamos dentro de <span>...</span>
98- if not self.inside_nickname: # <nickname> quote
99- if text == '<': # entered the "nickname area"
100- self.inside_nickname = True
101- self.current_quote += '\n<' # linebreak
102- else:
103- self.current_quote += text # concatena tudo que tiver dentro da tag
104- else:
105- self.current_quote += text # concatenate all the nickname
106- if text == '>': # nickname is over
107- self.inside_nickname = False # set it
108+ self.current_quote += text
109+# if not self.inside_nickname: # <nickname> quote
110+# if text == '<': # entered the "nickname area"
111+# self.inside_nickname = True
112+# self.current_quote += '\n<' # linebreak
113+# else:
114+# self.current_quote += text # concatena tudo que tiver dentro da tag
115+# else:
116+# self.current_quote += text # concatenate all the nickname
117+# if text == '>': # nickname is over
118+# self.inside_nickname = False # set it
119
120 def parse(self, page):
121 self.feed(page) # feed the parser with the page's html
122
123=== modified file 'Quote/Quote'
124--- Quote/Quote 2011-07-10 23:26:32 +0000
125+++ Quote/Quote 2012-03-28 20:51:20 +0000
126@@ -6,18 +6,18 @@
127 # E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br
128 #
129 # This program is free software: you can redistribute it and/or modify
130-# it under the terms of the GNU General Public License as published by
131-# the Free Software Foundation, either version 3 of the License, or
132-# (at your option) any later version.
133+# it under the terms of the GNU General Public License as published by
134+# the Free Software Foundation, either version 3 of the License, or
135+# (at your option) any later version.
136
137 # This program is distributed in the hope that it will be useful,
138-# but WITHOUT ANY WARRANTY; without even the implied warranty of
139-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
140-# GNU General Public License for more details.
141+# but WITHOUT ANY WARRANTY; without even the implied warranty of
142+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
143+# GNU General Public License for more details.
144
145 # This applet provides a "Quote of the day" feature from some internet sources
146 # such as Quotationspage.com, Bash.org, Xkcdb.com, Qdb.us, Danstonchat.fr,
147-# Jokes2go.com, Vidademerda.com.br, and Grouphug.us
148+# Jokes2go.com, and Vidademerda.com.br
149
150 import gobject, gtk, urllib, itertools
151 from sgmllib import SGMLParser
152@@ -26,152 +26,149 @@
153
154 from CDApplet import CDApplet, _
155
156-from BashParser import BashParser # Bash.org
157-from QdbParser import QdbParser # Qdb.us
158-from XkcdbParser import XkcdbParser # Xkcdb.com
159-from QuotationspageParser import QuotationspageParser # Quotationspage.com
160-from DanstonchatParser import DanstonchatParser # Danstonchat.fr
161-from JokestogoParser import JokestogoParser # Jokes2go.com
162-from VidademerdaParser import VidademerdaParser # Vidademerda.com.br
163-from GroupHugParser import GroupHugParser # Grouphug.us
164+from BashParser import BashParser # Bash.org
165+from QdbParser import QdbParser # Qdb.us
166+from XkcdbParser import XkcdbParser # Xkcdb.com
167+from QuotationspageParser import QuotationspageParser # Quotationspage.com
168+from DanstonchatParser import DanstonchatParser # Danstonchat.fr
169+from JokestogoParser import JokestogoParser # Jokes2go.com
170+from VidademerdaParser import VidademerdaParser # Vidademerda.com.br
171
172-quotationspage, bash, xkcdb, qdb, danstonchat, jokestogo, vidademerda, grouphug = range(8) # quotationspage = 0, bash = 1, xkcdb = 2, qdb = 3, danstonchat = 4, jokestogo = 5, vidademerda = 6, grouphug = 7
173+quotationspage, bash, xkcdb, qdb, danstonchat, jokestogo, vidademerda = range(7) # quotationspage = 0, bash = 1, xkcdb = 2, qdb = 3, danstonchat = 4, jokestogo = 5, vidademerda = 6
174
175 class AgentOpener(FancyURLopener):
176- """Masked user-agent otherwise the access would be forbidden"""
177- version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'
178+ """Masked user-agent otherwise the access would be forbidden"""
179+ version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'
180
181 class Interface:
182
183- def __init__(self, source):
184- self.source = source
185- self.author = []
186- self.quote = []
187-
188- def fetch(self):
189- if (self.source == quotationspage):
190- parser = QuotationspageParser() # QuotationspageParser.py
191- elif (self.source == bash):
192- parser = BashParser() # BashParser.py
193- elif (self.source == xkcdb):
194- parser = XkcdbParser() # XkcdbParser.py
195- elif (self.source == qdb):
196- parser = QdbParser() # QdbParser.py
197- elif (self.source == danstonchat):
198- parser = DanstonchatParser() # DanstonchatParser.py
199- elif (self.source == jokestogo):
200- parser = JokestogoParser()
201- elif (self.source == vidademerda): # VidademerdaParser.py
202- parser = VidademerdaParser()
203- else:
204- parser = GroupHugParser() # GroupHugParser.py
205-
206- opener = AgentOpener() # opens the web connection with masked user-agent
207-
208- try:
209- page = opener.open(parser.url) # get the HTML
210- except IOError:
211- log ("Problem to open %s" % (parser.url))
212- else:
213- parser.parse(page.read()) # feed the parser to get the specific content: translated text
214- page.close() # lets close the page connection
215- if (self.source == quotationspage):
216- self.quote = parser.quote
217- self.author = parser.author
218- elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat or self.source == grouphug):
219- self.quote = filter(None, parser.quote) # retira os '' do array
220- elif self.source == jokestogo: # jokestogo
221- self.quote = filter(self.breakline, parser.quote)
222- else: # vidademerda
223- self.quote = [''.join(parser.quote)]
224- self.author = parser.author
225- return self.quote, self.author
226-
227- def breakline(self, item):
228- return not item == '\n'
229+ def __init__(self, source):
230+ self.source = source
231+ self.author = []
232+ self.quote = []
233+
234+ def fetch(self):
235+ if (self.source == quotationspage):
236+ parser = QuotationspageParser() # QuotationspageParser.py
237+ elif (self.source == bash):
238+ parser = BashParser() # BashParser.py
239+ elif (self.source == xkcdb):
240+ parser = XkcdbParser() # XkcdbParser.py
241+ elif (self.source == qdb):
242+ parser = QdbParser() # QdbParser.py
243+ elif (self.source == danstonchat):
244+ parser = DanstonchatParser() # DanstonchatParser.py
245+ elif (self.source == jokestogo):
246+ parser = JokestogoParser()
247+ else: # VidademerdaParser.py
248+ parser = VidademerdaParser()
249+
250+ opener = AgentOpener() # opens the web connection with masked user-agent
251+
252+ try:
253+ page = opener.open(parser.url) # get the HTML
254+ except IOError:
255+ log ("Problem to open %s" % (parser.url))
256+ else:
257+ parser.parse(page.read()) # feed the parser to get the specific content: translated text
258+ page.close() # lets close the page connection
259+ if (self.source == quotationspage):
260+ self.quote = parser.quote
261+ self.author = parser.author
262+ elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat):
263+ self.quote = filter(None, parser.quote) # remove the '' from the array
264+ elif self.source == jokestogo: # jokestogo
265+ self.quote = filter(self.breakline, parser.quote)
266+ else: # vidademerda
267+ self.quote = [''.join(parser.quote)]
268+ self.author = parser.author
269+ return self.quote, self.author
270+
271+ def breakline(self, item):
272+ return not item == '\n'
273
274 class Applet(CDApplet):
275
276- def __init__(self):
277- self.authors = None
278- self.quotes = None
279- self.quotation = ""
280- self.dialog_active_time = 30 # time in seconds that the dialog window will be active
281- self.copy_current_quote_key = 0
282- self.go_next_quote_key = 1
283- self.source = quotationspage
284- self.cSiteNames = ['Quotationspage.com','Bash.org','Xkcdb.com','Qdb.us','Danstonchat.com','Jokes2go.com','Vidademerda.com.br', 'Grouphug.us']
285-
286- CDApplet.__init__(self) # call high-level init
287-
288- # Clipboard operations
289- def set_to_clipboard(self, sentence):
290- clipboard = gtk.clipboard_get() # get the clipboard
291- clipboard.set_text(sentence) # set the clipboard the current quote
292-
293- # Quotes
294- def get_quotes_from_web(self):
295- self.inform_start_of_waiting_process() # ...
296- interface = Interface(self.source)
297- quote, author = interface.fetch()
298- if (self.source == quotationspage): # quotationspage nao da quotes diferentes por acesso ...
299- self.quotes = itertools.cycle(quote)
300- self.authors = itertools.cycle(author)
301- else: # ... os outros dao quotes diferentes por acesso entao
302- self.quotes = iter(quote) # nao precisa usar iterador circular, pois depois de mostrar
303- self.authors = iter(author) # todas, busca-se novas quotes com mais uma chamada deste metodo
304- self.inform_end_of_waiting_process() # done
305-
306- def show_quote(self):
307- if (self.source == quotationspage):
308- self.quotation = "\"%s\" ~ %s" % (self.quotes.next(), self.authors.next()) # N-esima quote refere-se ao N-esimo autor."quote[x]~author[x]"
309- elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat or self.source == grouphug):
310- try: # ve a possibilidade de mostrar quotes ja armazenadas
311- current = self.quotes.next()
312- except StopIteration: # todas ja foram mostradas
313- self.get_quotes_from_web() # buscar mais
314- current = self.quotes.next() # posicionar na primeira para mostra-la
315- self.quotation = "%s" % current
316- elif (self.source == jokestogo): # jokestogo provides only one quote per request ...
317- self.quotation = "%s" % self.quotes.next().rstrip()
318- self.get_quotes_from_web() # ... so it is necessary to request it again
319- else:
320- self.quotation = "%s ~ %s" % (self.quotes.next(), self.authors.next()) # vidademerda provides only one quote per request ...
321- self.get_quotes_from_web() # ... so it is necessary to request it again
322- self.icon.PopupDialog({'message':self.quotation, "buttons":"stock_copy;go-next;cancel"}, {})
323-
324- def inform_start_of_waiting_process(self):
325- self.icon.SetQuickInfo("...")
326-
327- def inform_end_of_waiting_process(self):
328- self.icon.SetQuickInfo("")
329-
330- def _display_site_name(self):
331- if self.config['default title'] == "":
332- self.icon.SetLabel(self.cSiteNames[self.source])
333-
334- # Inherited methods from CDApplet
335- def begin(self):
336- self.get_quotes_from_web()
337- self._display_site_name()
338-
339- def get_config(self, keyfile):
340- self.source = keyfile.getint('Configuration', 'source') # get the source of quotations
341- self.config['default title'] = keyfile.get('Icon', 'name') # icon's label set by the user.
342-
343- def reload(self):
344- self.get_quotes_from_web() # refresh the quotations
345- self._display_site_name()
346-
347- # Callbacks
348- def on_click(self, key):
349- self.show_quote()
350-
351- def on_answer_dialog(self, key, content):
352- if (key == self.copy_current_quote_key): # cancel button = 1, and copy_current_quote_key = 0
353- self.set_to_clipboard(self.quotation) # copia para a area de transferencia a quotation atual
354- elif (key == self.go_next_quote_key or key == CDApplet.DIALOG_KEY_ENTER):
355- self.show_quote()
356+ def __init__(self):
357+ self.authors = None
358+ self.quotes = None
359+ self.quotation = ""
360+ self.dialog_active_time = 30 # time in seconds that the dialog window will be active
361+ self.copy_current_quote_key = 0
362+ self.go_next_quote_key = 1
363+ self.source = quotationspage
364+ self.cSiteNames = ['Quotationspage.com','Bash.org','Xkcdb.com','Qdb.us','Danstonchat.com','Jokes2go.com','Vidademerda.com.br']
365+
366+ CDApplet.__init__(self) # call high-level init
367+
368+ # Clipboard operations
369+ def set_to_clipboard(self, sentence):
370+ clipboard = gtk.clipboard_get() # get the clipboard
371+ clipboard.set_text(sentence) # set the clipboard the current quote
372+
373+ # Quotes
374+ def get_quotes_from_web(self):
375+ self.inform_start_of_waiting_process() # ...
376+ interface = Interface(self.source)
377+ quote, author = interface.fetch()
378+ if (self.source == quotationspage): # quotationspage nao da quotes diferentes por acesso ...
379+ self.quotes = itertools.cycle(quote)
380+ self.authors = itertools.cycle(author)
381+ else: # ... os outros dao quotes diferentes por acesso entao
382+ self.quotes = iter(quote) # nao precisa usar iterador circular, pois depois de mostrar
383+ self.authors = iter(author) # todas, busca-se novas quotes com mais uma chamada deste metodo
384+ self.inform_end_of_waiting_process() # done
385+
386+ def show_quote(self):
387+ if (self.source == quotationspage):
388+ self.quotation = "\"%s\" ~ %s" % (self.quotes.next(), self.authors.next()) # N-esima quote refere-se ao N-esimo autor."quote[x]~author[x]"
389+ elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat):
390+ try: # ve a possibilidade de mostrar quotes ja armazenadas
391+ current = self.quotes.next()
392+ except StopIteration: # todas ja foram mostradas
393+ self.get_quotes_from_web() # buscar mais
394+ current = self.quotes.next() # posicionar na primeira para mostra-la
395+ self.quotation = "%s" % current
396+ elif (self.source == jokestogo): # jokestogo provides only one quote per request ...
397+ self.quotation = "%s" % self.quotes.next().rstrip()
398+ self.get_quotes_from_web() # ... so it is necessary to request it again
399+ else:
400+ self.quotation = "%s ~ %s" % (self.quotes.next(), self.authors.next()) # vidademerda provides only one quote per request ...
401+ self.get_quotes_from_web() # ... so it is necessary to request it again
402+ self.icon.PopupDialog({'message':self.quotation, "buttons":"stock_copy;go-next;cancel"}, {})
403+
404+ def inform_start_of_waiting_process(self):
405+ self.icon.SetQuickInfo("...")
406+
407+ def inform_end_of_waiting_process(self):
408+ self.icon.SetQuickInfo("")
409+
410+ def _display_site_name(self):
411+ if self.config['default title'] == "":
412+ self.icon.SetLabel(self.cSiteNames[self.source])
413+
414+ # Inherited methods from CDApplet
415+ def begin(self):
416+ self.get_quotes_from_web()
417+ self._display_site_name()
418+
419+ def get_config(self, keyfile):
420+ self.source = keyfile.getint('Configuration', 'source') # get the source of quotations
421+ self.config['default title'] = keyfile.get('Icon', 'name') # icon's label set by the user.
422+
423+ def reload(self):
424+ self.get_quotes_from_web() # refresh the quotations
425+ self._display_site_name()
426+
427+ # Callbacks
428+ def on_click(self, key):
429+ self.show_quote()
430+
431+ def on_answer_dialog(self, key, content):
432+ if (key == self.copy_current_quote_key): # cancel button = 1, and copy_current_quote_key = 0
433+ self.set_to_clipboard(self.quotation) # copia para a area de transferencia a quotation atual
434+ elif (key == self.go_next_quote_key or key == CDApplet.DIALOG_KEY_ENTER):
435+ self.show_quote()
436
437 if __name__ == '__main__':
438- Applet().run()
439+ Applet().run()
440
441=== modified file 'Quote/Quote.conf'
442--- Quote/Quote.conf 2011-11-06 01:58:42 +0000
443+++ Quote/Quote.conf 2012-03-28 20:51:20 +0000
444@@ -102,5 +102,5 @@
445
446 #[gtk-preferences]
447 [Configuration]
448-#l[Quotationspage.com;Bash.org;Xkcdb.com;Qdb.us;Danstonchat.com;Jokes2go.com;Vidademerda.com.br;Grouphug.us] Quote source:
449+#l[Quotationspage.com;Bash.org;Xkcdb.com;Qdb.us;Danstonchat.com;Jokes2go.com;Vidademerda.com.br] Quote source:
450 source = 0

Subscribers

People subscribed via source and target branches