cairo-dock-team team mailing list archive
-
cairo-dock-team team
-
Mailing list archive
-
Message #02608
[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)
Added support to Jokes2go.com
--
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote/+merge/42458
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/ChangeLog'
--- Quote/ChangeLog 2010-11-23 02:38:59 +0000
+++ Quote/ChangeLog 2010-12-02 10:21:52 +0000
@@ -1,3 +1,5 @@
+0.0.5:(December/2/2010): Added Jokes2go.com.
+0.0.4:(November/23/2010): Added Danstonchat.com. Changed the icon, now the lamp was turned on :¬) Huge code modularization.
0.0.3:(November/23/2010): It is possible now copy the quote to the clipboard. Added quotes from Qdb.us.
0.0.2:(November/22/2010): Added quotes from Bash.org, and Xkcdb.com
0.0.1:(November/20/2010): Quotes from Quotationspage.com
=== added file 'Quote/JokestogoParser.py'
--- Quote/JokestogoParser.py 1970-01-01 00:00:00 +0000
+++ Quote/JokestogoParser.py 2010-12-02 10:21:52 +0000
@@ -0,0 +1,31 @@
+# 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 JokestogoParser(SGMLParser):
+
+ def reset(self):
+ SGMLParser.reset(self)
+ self.url = "http://www.jokes2go.com/cgi-perl/randjoke.cgi?type=j"
+ self.quote = []
+ self.inside_pre_element = False # indica se o parser esta dentro de <pre></pre> tag
+ self.current_quote = ""
+
+ def start_pre(self, attrs):
+ self.inside_pre_element = True
+
+ def end_pre(self):
+ self.inside_pre_element = False
+ self.quote.append(self.current_quote)
+ self.current_quote = ""
+
+ def handle_data(self, text):
+ if self.inside_pre_element: # estamos dentro de <pre>...</pre>
+ self.current_quote += text
+
+ def parse(self, page):
+ self.feed(page) # feed the parser with the page's html
+ self.close()
=== modified file 'Quote/Quote'
--- Quote/Quote 2010-11-23 21:01:19 +0000
+++ Quote/Quote 2010-12-02 10:21:52 +0000
@@ -16,7 +16,8 @@
# 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, and Danstonchat.fr
+# such as Quotationspage.com, Bash.org, Xkcdb.com, Qdb.us, Danstonchat.fr, and
+# Jokes2go.com
import gobject, dbus, os, urllib, gtk, ConfigParser, itertools
from dbus.mainloop.glib import DBusGMainLoop
@@ -30,10 +31,11 @@
from XkcdbParser import XkcdbParser # Xkcdb.com
from QuotationspageParser import QuotationspageParser # Quotationspage.com
from DanstonchatParser import DanstonchatParser # Danstonchat.fr
+from JokestogoParser import JokestogoParser # Jokes2go.com
DBusGMainLoop(set_as_default=True)
-quotationspage, bash, xkcdb, qdb, danstonchat = range(5) # quotationspage = 0, bash = 1, xkcdb = 2, qdb = 3, danstonchat = 4
+quotationspage, bash, xkcdb, qdb, danstonchat, jokestogo = range(6) # quotationspage = 0, bash = 1, xkcdb = 2, qdb = 3, danstonchat = 4, jokestogo = 5
class AgentOpener(FancyURLopener):
"""Masked user-agent otherwise the access would be forbidden"""
@@ -55,15 +57,17 @@
parser = XkcdbParser() # XkcdbParser.py
elif (self.source == qdb):
parser = QdbParser() # QdbParser.py
- else:
+ elif (self.source == danstonchat):
parser = DanstonchatParser() # DanstonchatParser.py
+ else:
+ parser = JokestogoParser()
opener = AgentOpener() # opens the web connection with masked user-agent
-
+
try:
page = opener.open(parser.url) # get the HTML
except IOError:
- print ("Problem to open %s" % (parser.url))
+ 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
@@ -71,10 +75,14 @@
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 = parser.quote
- self.quote = filter(None, self.quote) # retira os '' do array
+ self.quote = filter(None, parser.quote) # retira os '' do array
+ else: # jokestogo
+ self.quote = filter(self.breakline, parser.quote)
return self.quote, self.author
+ def breakline(self, item):
+ return not item == '\n'
+
class Quote:
def start(self):
@@ -101,7 +109,7 @@
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.copy_current_quote_key = 1
self.source = quotationspage
def start(self):
@@ -129,7 +137,7 @@
self.get_quotes_from_web() # refresh the quotations
def action_on_answer_dialog(self, key, content):
- if (key == self.copy_current_quote_key): # cancel button = 1, and copy_current_quote_key = 0
+ if (key == self.copy_current_quote_key): # cancel button = 0, and copy_current_quote_key = 1
self.set_to_clipboard(self.quotation) # copia para a area de transferencia a quotation atual
def set_to_clipboard(self, sentence):
@@ -149,8 +157,11 @@
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):
self.quotation = "%s" % self.quotes.next()
+ else: # 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
try:
- self.icon.PopupDialog({'message':self.quotation, "buttons":"stock_copy;cancel"}, {})
+ self.icon.PopupDialog({'message':self.quotation, "buttons":"cancel;stock_copy"}, {})
except Exception:
log("Error caused PopupDialog not be shown, ShowDialog was used instead") # back-compatibility with CD < 2.2.0
self.icon.ShowDialog(self.quotation, self.dialog_active_time)
=== modified file 'Quote/Quote.conf'
--- Quote/Quote.conf 2010-11-23 21:01:19 +0000
+++ Quote/Quote.conf 2010-12-02 10:21:52 +0000
@@ -1,4 +1,4 @@
-#!en;0.0.4
+#!en;0.0.5
#[gtk-about]
[Icon]
@@ -89,5 +89,5 @@
#[gtk-preferences]
[Configuration]
-#l[Quotationspage.com;Bash.org;Xkcdb.com;Qdb.us;Danstonchat.com] Quote source:
+#l[Quotationspage.com;Bash.org;Xkcdb.com;Qdb.us;Danstonchat.com;Jokes2go.com] Quote source:
source = 0
=== modified file 'Quote/auto-load.conf'
--- Quote/auto-load.conf 2010-11-23 21:16:03 +0000
+++ Quote/auto-load.conf 2010-12-02 10:21:52 +0000
@@ -4,10 +4,10 @@
author = Eduardo Mucelli Rezende Oliveira
# A short description of the applet and how to use it.
-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
+description = This applet provides a "Quote of the day" feature from some internet sources \nsuch as Quotationspage.com, Bash.org, Xkcdb.com, Qdb.us, Danstonchat.com, and Jokes2go.com
# Category of the applet : 2 = files, 3 = internet, 4 = Desktop, 5 = accessory, 6 = system, 7 = fun
category = 7
# 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.
-version = 0.0.4
+version = 0.0.5