cairo-dock-team team mailing list archive
-
cairo-dock-team team
-
Mailing list archive
-
Message #03770
[Merge] lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote into lp:cairo-dock-plug-ins-extras
Eduardo Mucelli Rezende Oliveira has proposed merging lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote into lp:cairo-dock-plug-ins-extras.
Requested reviews:
Cairo-Dock Team (cairo-dock-team)
For more details, see:
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote/+merge/99820
Removed Grouphug.us because it is not offering the random quote anymore. Fixing the return from Bash and Qdb.
--
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote/+merge/99820
Your team Cairo-Dock Team is requested to review the proposed merge of lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote into lp:cairo-dock-plug-ins-extras.
=== modified file 'Quote/BashParser.py'
--- Quote/BashParser.py 2011-04-25 14:56:41 +0000
+++ Quote/BashParser.py 2012-03-28 20:51:20 +0000
@@ -28,16 +28,17 @@
def handle_data(self, text):
if self.inside_p_element: # estamos dentro de <p>...</p>
- if not self.inside_nickname: # <nickname> quote
- if text == '<': # entered the "nickname area"
- self.inside_nickname = True
- self.current_quote += '\n<' # linebreak
- else:
- self.current_quote += text # concatena tudo que tiver dentro da tag
- else:
- self.current_quote += text # concatenate all the nickname
- if text == '>': # nickname is over
- self.inside_nickname = False # set it
+ self.current_quote += text
+# if not self.inside_nickname: # <nickname> quote
+# if text == '<': # entered the "nickname area"
+# self.inside_nickname = True
+# self.current_quote += '\n<' # linebreak
+# else:
+# self.current_quote += text # concatena tudo que tiver dentro da tag
+# else:
+# self.current_quote += text # concatenate all the nickname
+# if text == '>': # nickname is over
+# self.inside_nickname = False # set it
def parse(self, page):
self.feed(page) # feed the parser with the page's html
=== modified file 'Quote/ChangeLog'
--- Quote/ChangeLog 2011-03-17 13:32:10 +0000
+++ Quote/ChangeLog 2012-03-28 20:51:20 +0000
@@ -1,3 +1,4 @@
+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.
0.0.8:(March/17/2010): Added Grouphug.us.
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.
0.0.6:(December/22/2010): Automatic fetch more quotes when all of them were already showed to the user, except for Quotationspage.com.
=== removed file 'Quote/GroupHugParser.py'
--- Quote/GroupHugParser.py 2011-03-17 13:32:10 +0000
+++ Quote/GroupHugParser.py 1970-01-01 00:00:00 +0000
@@ -1,44 +0,0 @@
-# This is a part of the external Quote applet for Cairo-Dock
-#
-# Author: Eduardo Mucelli Rezende Oliveira
-# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
-
-from sgmllib import SGMLParser
-
-class GroupHugParser(SGMLParser):
-
- def reset(self):
- SGMLParser.reset(self)
- self.url = "http://grouphug.us/random"
- self.quote = []
- self.author = []
- self.inside_div_element = False # indica dentro da <div class="content"></div> tag
- self.inside_div_p_element = False # indica dentro da <div class="content"><p></p></div> tag
- self.current_quote = ""
-
- def start_div(self, attrs):
- for name, value in attrs:
- if name == "class" and value == "content": # <dt class="content">...</dt>
- self.inside_div_element = True
-
- def end_div(self):
- if self.inside_div_element:
- self.quote.append(self.current_quote)
- self.current_quote = "" # reinicia o armazenador do conteudo
- self.inside_div_element = False
-
- def start_p(self, attrs):
- if self.inside_div_element:
- self.inside_div_p_element = True
-
- def end_p(self):
- # if self.inside_div_element:
- self.inside_div_p_element = False
- # adiciona o conteudo completo da tag
- def handle_data(self, text):
- if self.inside_div_p_element: # estamos dentro de <div><p>...</p></div>
- self.current_quote += text
-
- def parse(self, page):
- self.feed(page) # feed the parser with the page's html
- self.close()
=== modified file 'Quote/QdbParser.py'
--- Quote/QdbParser.py 2011-04-25 14:56:41 +0000
+++ Quote/QdbParser.py 2012-03-28 20:51:20 +0000
@@ -27,16 +27,17 @@
def handle_data(self, text):
if self.inside_span_element: # estamos dentro de <span>...</span>
- if not self.inside_nickname: # <nickname> quote
- if text == '<': # entered the "nickname area"
- self.inside_nickname = True
- self.current_quote += '\n<' # linebreak
- else:
- self.current_quote += text # concatena tudo que tiver dentro da tag
- else:
- self.current_quote += text # concatenate all the nickname
- if text == '>': # nickname is over
- self.inside_nickname = False # set it
+ self.current_quote += text
+# if not self.inside_nickname: # <nickname> quote
+# if text == '<': # entered the "nickname area"
+# self.inside_nickname = True
+# self.current_quote += '\n<' # linebreak
+# else:
+# self.current_quote += text # concatena tudo que tiver dentro da tag
+# else:
+# self.current_quote += text # concatenate all the nickname
+# if text == '>': # nickname is over
+# self.inside_nickname = False # set it
def parse(self, page):
self.feed(page) # feed the parser with the page's html
=== modified file 'Quote/Quote'
--- Quote/Quote 2011-07-10 23:26:32 +0000
+++ Quote/Quote 2012-03-28 20:51:20 +0000
@@ -6,18 +6,18 @@
# E-mail: edumucelli@xxxxxxxxx or eduardom@xxxxxxxxxxx
#
# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
# This applet provides a "Quote of the day" feature from some internet sources
# such as Quotationspage.com, Bash.org, Xkcdb.com, Qdb.us, Danstonchat.fr,
-# Jokes2go.com, Vidademerda.com.br, and Grouphug.us
+# Jokes2go.com, and Vidademerda.com.br
import gobject, gtk, urllib, itertools
from sgmllib import SGMLParser
@@ -26,152 +26,149 @@
from CDApplet import CDApplet, _
-from BashParser import BashParser # Bash.org
-from QdbParser import QdbParser # Qdb.us
-from XkcdbParser import XkcdbParser # Xkcdb.com
-from QuotationspageParser import QuotationspageParser # Quotationspage.com
-from DanstonchatParser import DanstonchatParser # Danstonchat.fr
-from JokestogoParser import JokestogoParser # Jokes2go.com
-from VidademerdaParser import VidademerdaParser # Vidademerda.com.br
-from GroupHugParser import GroupHugParser # Grouphug.us
+from BashParser import BashParser # Bash.org
+from QdbParser import QdbParser # Qdb.us
+from XkcdbParser import XkcdbParser # Xkcdb.com
+from QuotationspageParser import QuotationspageParser # Quotationspage.com
+from DanstonchatParser import DanstonchatParser # Danstonchat.fr
+from JokestogoParser import JokestogoParser # Jokes2go.com
+from VidademerdaParser import VidademerdaParser # Vidademerda.com.br
-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
+quotationspage, bash, xkcdb, qdb, danstonchat, jokestogo, vidademerda = range(7) # quotationspage = 0, bash = 1, xkcdb = 2, qdb = 3, danstonchat = 4, jokestogo = 5, vidademerda = 6
class AgentOpener(FancyURLopener):
- """Masked user-agent otherwise the access would be forbidden"""
- version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'
+ """Masked user-agent otherwise the access would be forbidden"""
+ version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'
class Interface:
- def __init__(self, source):
- self.source = source
- self.author = []
- self.quote = []
-
- def fetch(self):
- if (self.source == quotationspage):
- parser = QuotationspageParser() # QuotationspageParser.py
- elif (self.source == bash):
- parser = BashParser() # BashParser.py
- elif (self.source == xkcdb):
- parser = XkcdbParser() # XkcdbParser.py
- elif (self.source == qdb):
- parser = QdbParser() # QdbParser.py
- elif (self.source == danstonchat):
- parser = DanstonchatParser() # DanstonchatParser.py
- elif (self.source == jokestogo):
- parser = JokestogoParser()
- elif (self.source == vidademerda): # VidademerdaParser.py
- parser = VidademerdaParser()
- else:
- parser = GroupHugParser() # GroupHugParser.py
-
- opener = AgentOpener() # opens the web connection with masked user-agent
-
- try:
- page = opener.open(parser.url) # get the HTML
- except IOError:
- log ("Problem to open %s" % (parser.url))
- else:
- parser.parse(page.read()) # feed the parser to get the specific content: translated text
- page.close() # lets close the page connection
- if (self.source == quotationspage):
- self.quote = parser.quote
- self.author = parser.author
- elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat or self.source == grouphug):
- self.quote = filter(None, parser.quote) # retira os '' do array
- elif self.source == jokestogo: # jokestogo
- self.quote = filter(self.breakline, parser.quote)
- else: # vidademerda
- self.quote = [''.join(parser.quote)]
- self.author = parser.author
- return self.quote, self.author
-
- def breakline(self, item):
- return not item == '\n'
+ def __init__(self, source):
+ self.source = source
+ self.author = []
+ self.quote = []
+
+ def fetch(self):
+ if (self.source == quotationspage):
+ parser = QuotationspageParser() # QuotationspageParser.py
+ elif (self.source == bash):
+ parser = BashParser() # BashParser.py
+ elif (self.source == xkcdb):
+ parser = XkcdbParser() # XkcdbParser.py
+ elif (self.source == qdb):
+ parser = QdbParser() # QdbParser.py
+ elif (self.source == danstonchat):
+ parser = DanstonchatParser() # DanstonchatParser.py
+ elif (self.source == jokestogo):
+ parser = JokestogoParser()
+ else: # VidademerdaParser.py
+ parser = VidademerdaParser()
+
+ opener = AgentOpener() # opens the web connection with masked user-agent
+
+ try:
+ page = opener.open(parser.url) # get the HTML
+ except IOError:
+ log ("Problem to open %s" % (parser.url))
+ else:
+ parser.parse(page.read()) # feed the parser to get the specific content: translated text
+ page.close() # lets close the page connection
+ if (self.source == quotationspage):
+ self.quote = parser.quote
+ self.author = parser.author
+ elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat):
+ self.quote = filter(None, parser.quote) # remove the '' from the array
+ elif self.source == jokestogo: # jokestogo
+ self.quote = filter(self.breakline, parser.quote)
+ else: # vidademerda
+ self.quote = [''.join(parser.quote)]
+ self.author = parser.author
+ return self.quote, self.author
+
+ def breakline(self, item):
+ return not item == '\n'
class Applet(CDApplet):
- def __init__(self):
- self.authors = None
- self.quotes = None
- self.quotation = ""
- self.dialog_active_time = 30 # time in seconds that the dialog window will be active
- self.copy_current_quote_key = 0
- self.go_next_quote_key = 1
- self.source = quotationspage
- self.cSiteNames = ['Quotationspage.com','Bash.org','Xkcdb.com','Qdb.us','Danstonchat.com','Jokes2go.com','Vidademerda.com.br', 'Grouphug.us']
-
- CDApplet.__init__(self) # call high-level init
-
- # Clipboard operations
- def set_to_clipboard(self, sentence):
- clipboard = gtk.clipboard_get() # get the clipboard
- clipboard.set_text(sentence) # set the clipboard the current quote
-
- # Quotes
- def get_quotes_from_web(self):
- self.inform_start_of_waiting_process() # ...
- interface = Interface(self.source)
- quote, author = interface.fetch()
- if (self.source == quotationspage): # quotationspage nao da quotes diferentes por acesso ...
- self.quotes = itertools.cycle(quote)
- self.authors = itertools.cycle(author)
- else: # ... os outros dao quotes diferentes por acesso entao
- self.quotes = iter(quote) # nao precisa usar iterador circular, pois depois de mostrar
- self.authors = iter(author) # todas, busca-se novas quotes com mais uma chamada deste metodo
- self.inform_end_of_waiting_process() # done
-
- def show_quote(self):
- if (self.source == quotationspage):
- self.quotation = "\"%s\" ~ %s" % (self.quotes.next(), self.authors.next()) # N-esima quote refere-se ao N-esimo autor."quote[x]~author[x]"
- elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat or self.source == grouphug):
- try: # ve a possibilidade de mostrar quotes ja armazenadas
- current = self.quotes.next()
- except StopIteration: # todas ja foram mostradas
- self.get_quotes_from_web() # buscar mais
- current = self.quotes.next() # posicionar na primeira para mostra-la
- self.quotation = "%s" % current
- elif (self.source == jokestogo): # jokestogo provides only one quote per request ...
- self.quotation = "%s" % self.quotes.next().rstrip()
- self.get_quotes_from_web() # ... so it is necessary to request it again
- else:
- self.quotation = "%s ~ %s" % (self.quotes.next(), self.authors.next()) # vidademerda provides only one quote per request ...
- self.get_quotes_from_web() # ... so it is necessary to request it again
- self.icon.PopupDialog({'message':self.quotation, "buttons":"stock_copy;go-next;cancel"}, {})
-
- def inform_start_of_waiting_process(self):
- self.icon.SetQuickInfo("...")
-
- def inform_end_of_waiting_process(self):
- self.icon.SetQuickInfo("")
-
- def _display_site_name(self):
- if self.config['default title'] == "":
- self.icon.SetLabel(self.cSiteNames[self.source])
-
- # Inherited methods from CDApplet
- def begin(self):
- self.get_quotes_from_web()
- self._display_site_name()
-
- def get_config(self, keyfile):
- self.source = keyfile.getint('Configuration', 'source') # get the source of quotations
- self.config['default title'] = keyfile.get('Icon', 'name') # icon's label set by the user.
-
- def reload(self):
- self.get_quotes_from_web() # refresh the quotations
- self._display_site_name()
-
- # Callbacks
- def on_click(self, key):
- self.show_quote()
-
- def on_answer_dialog(self, key, content):
- if (key == self.copy_current_quote_key): # cancel button = 1, and copy_current_quote_key = 0
- self.set_to_clipboard(self.quotation) # copia para a area de transferencia a quotation atual
- elif (key == self.go_next_quote_key or key == CDApplet.DIALOG_KEY_ENTER):
- self.show_quote()
+ def __init__(self):
+ self.authors = None
+ self.quotes = None
+ self.quotation = ""
+ self.dialog_active_time = 30 # time in seconds that the dialog window will be active
+ self.copy_current_quote_key = 0
+ self.go_next_quote_key = 1
+ self.source = quotationspage
+ self.cSiteNames = ['Quotationspage.com','Bash.org','Xkcdb.com','Qdb.us','Danstonchat.com','Jokes2go.com','Vidademerda.com.br']
+
+ CDApplet.__init__(self) # call high-level init
+
+ # Clipboard operations
+ def set_to_clipboard(self, sentence):
+ clipboard = gtk.clipboard_get() # get the clipboard
+ clipboard.set_text(sentence) # set the clipboard the current quote
+
+ # Quotes
+ def get_quotes_from_web(self):
+ self.inform_start_of_waiting_process() # ...
+ interface = Interface(self.source)
+ quote, author = interface.fetch()
+ if (self.source == quotationspage): # quotationspage nao da quotes diferentes por acesso ...
+ self.quotes = itertools.cycle(quote)
+ self.authors = itertools.cycle(author)
+ else: # ... os outros dao quotes diferentes por acesso entao
+ self.quotes = iter(quote) # nao precisa usar iterador circular, pois depois de mostrar
+ self.authors = iter(author) # todas, busca-se novas quotes com mais uma chamada deste metodo
+ self.inform_end_of_waiting_process() # done
+
+ def show_quote(self):
+ if (self.source == quotationspage):
+ self.quotation = "\"%s\" ~ %s" % (self.quotes.next(), self.authors.next()) # N-esima quote refere-se ao N-esimo autor."quote[x]~author[x]"
+ elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat):
+ try: # ve a possibilidade de mostrar quotes ja armazenadas
+ current = self.quotes.next()
+ except StopIteration: # todas ja foram mostradas
+ self.get_quotes_from_web() # buscar mais
+ current = self.quotes.next() # posicionar na primeira para mostra-la
+ self.quotation = "%s" % current
+ elif (self.source == jokestogo): # jokestogo provides only one quote per request ...
+ self.quotation = "%s" % self.quotes.next().rstrip()
+ self.get_quotes_from_web() # ... so it is necessary to request it again
+ else:
+ self.quotation = "%s ~ %s" % (self.quotes.next(), self.authors.next()) # vidademerda provides only one quote per request ...
+ self.get_quotes_from_web() # ... so it is necessary to request it again
+ self.icon.PopupDialog({'message':self.quotation, "buttons":"stock_copy;go-next;cancel"}, {})
+
+ def inform_start_of_waiting_process(self):
+ self.icon.SetQuickInfo("...")
+
+ def inform_end_of_waiting_process(self):
+ self.icon.SetQuickInfo("")
+
+ def _display_site_name(self):
+ if self.config['default title'] == "":
+ self.icon.SetLabel(self.cSiteNames[self.source])
+
+ # Inherited methods from CDApplet
+ def begin(self):
+ self.get_quotes_from_web()
+ self._display_site_name()
+
+ def get_config(self, keyfile):
+ self.source = keyfile.getint('Configuration', 'source') # get the source of quotations
+ self.config['default title'] = keyfile.get('Icon', 'name') # icon's label set by the user.
+
+ def reload(self):
+ self.get_quotes_from_web() # refresh the quotations
+ self._display_site_name()
+
+ # Callbacks
+ def on_click(self, key):
+ self.show_quote()
+
+ def on_answer_dialog(self, key, content):
+ if (key == self.copy_current_quote_key): # cancel button = 1, and copy_current_quote_key = 0
+ self.set_to_clipboard(self.quotation) # copia para a area de transferencia a quotation atual
+ elif (key == self.go_next_quote_key or key == CDApplet.DIALOG_KEY_ENTER):
+ self.show_quote()
if __name__ == '__main__':
- Applet().run()
+ Applet().run()
=== modified file 'Quote/Quote.conf'
--- Quote/Quote.conf 2011-11-06 01:58:42 +0000
+++ Quote/Quote.conf 2012-03-28 20:51:20 +0000
@@ -102,5 +102,5 @@
#[gtk-preferences]
[Configuration]
-#l[Quotationspage.com;Bash.org;Xkcdb.com;Qdb.us;Danstonchat.com;Jokes2go.com;Vidademerda.com.br;Grouphug.us] Quote source:
+#l[Quotationspage.com;Bash.org;Xkcdb.com;Qdb.us;Danstonchat.com;Jokes2go.com;Vidademerda.com.br] Quote source:
source = 0
Follow ups