← Back to team overview

cairo-dock-team team mailing list archive

[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 Danstonchat.com. Changed the icon, now the lamp was turned on :¬) Huge code modularization.
-- 
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote/+merge/41657
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.
=== added file 'Quote/BashParser.py'
--- Quote/BashParser.py	1970-01-01 00:00:00 +0000
+++ Quote/BashParser.py	2010-11-23 21:19:25 +0000
@@ -0,0 +1,35 @@
+# 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 BashParser(SGMLParser):
+
+    def reset(self):                              
+        SGMLParser.reset(self)
+        self.url = "http://bash.org/?random";
+        self.quote = []
+        self.inside_p_element = False                                               # indica se o parser esta dentro de <p></p> tag
+        self.current_quote = ""
+
+    def start_p(self, attrs):
+        for name, value in attrs:
+            if name == "class" and value == "qt":                                   # <p class="qt">...</p>
+                self.inside_p_element = True
+    
+    def end_p(self):
+        self.inside_p_element = False
+        self.quote.append(self.current_quote)                                       # adiciona o conteudo completo da tag
+        self.current_quote = ""                                                     # reinicia o armazenador do conteudo
+
+    def handle_data(self, text):
+        if self.inside_p_element:                                                   # estamos dentro de <p>...</p>
+            text = text.replace('<', '[')                                           # se a string contem '<nome>', gera o erro na hora do ShowDialog
+            text = text.replace('>', ']')                                           # pango_layout_set_markup_with_accel: Unknown tag 'nome'
+            self.current_quote += text                                              # concatena tudo que tiver dentro da tag
+
+    def parse(self, page):
+        self.feed(page)                                                             # feed the parser with the page's html
+        self.close()

=== added file 'Quote/DanstonchatParser.py'
--- Quote/DanstonchatParser.py	1970-01-01 00:00:00 +0000
+++ Quote/DanstonchatParser.py	2010-11-23 21:19:25 +0000
@@ -0,0 +1,35 @@
+# 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 DanstonchatParser(SGMLParser):
+
+    def reset(self):                              
+        SGMLParser.reset(self)
+        self.url = "http://danstonchat.com/random.html";
+        self.quote = []
+        self.inside_div_element = False                                             # indica se o parser esta dentro de <span></span> tag
+        self.current_quote = ""
+
+    def start_div(self, attrs):
+        for name, value in attrs:
+            if name == "class" and value == "item-content":                         # <span class="qt">...</span>
+                self.inside_div_element = True
+    
+    def end_div(self):
+        self.inside_div_element = False
+        self.quote.append(self.current_quote)                                       # adiciona o conteudo completo da tag
+        self.current_quote = ""                                                     # reinicia o armazenador do conteudo
+
+    def handle_data(self, text):
+        if self.inside_div_element:                                                 # estamos dentro de <span>...</span>
+            text = text.replace('<', '[')                                           # se a string contem '<nome>', gera o erro na hora do ShowDialog
+            text = text.replace('>', ']')                                           # pango_layout_set_markup_with_accel: Unknown tag 'nome'
+            self.current_quote += text                                              # concatena tudo que tiver dentro da tag
+
+    def parse(self, page):
+        self.feed(page)                                                             # feed the parser with the page's html
+        self.close() 

=== added file 'Quote/QdbParser.py'
--- Quote/QdbParser.py	1970-01-01 00:00:00 +0000
+++ Quote/QdbParser.py	2010-11-23 21:19:25 +0000
@@ -0,0 +1,35 @@
+# 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 QdbParser(SGMLParser):
+
+    def reset(self):                              
+        SGMLParser.reset(self)
+        self.url = "http://www.qdb.us/random";
+        self.quote = []
+        self.inside_span_element = False                                            # indica se o parser esta dentro de <span></span> tag
+        self.current_quote = ""
+
+    def start_span(self, attrs):
+        for name, value in attrs:
+            if name == "class" and value == "qt":                                   # <span class="qt">...</span>
+                self.inside_span_element = True
+    
+    def end_span(self):
+        self.inside_span_element = False
+        self.quote.append(self.current_quote)                                       # adiciona o conteudo completo da tag
+        self.current_quote = ""                                                     # reinicia o armazenador do conteudo
+
+    def handle_data(self, text):
+        if self.inside_span_element:                                                # estamos dentro de <span>...</span>
+            text = text.replace('<', '[')                                           # se a string contem '<nome>', gera o erro na hora do ShowDialog
+            text = text.replace('>', ']')                                           # pango_layout_set_markup_with_accel: Unknown tag 'nome'
+            self.current_quote += text                                              # concatena tudo que tiver dentro da tag
+
+    def parse(self, page):
+        self.feed(page)                                                             # feed the parser with the page's html
+        self.close()

=== added file 'Quote/QuotationspageParser.py'
--- Quote/QuotationspageParser.py	1970-01-01 00:00:00 +0000
+++ Quote/QuotationspageParser.py	2010-11-23 21:19:25 +0000
@@ -0,0 +1,63 @@
+# 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 QuotationspageParser(SGMLParser):
+
+    def reset(self):
+        SGMLParser.reset(self)
+        self.url = "http://www.quotationspage.com/qotd.html";
+        self.quote = []
+        self.author = []
+        self.inside_dt_a_element = False                                            # indica se o parser esta dentro de <dt><a></a></dt> tag
+        self.inside_dt_element = False                                              # indica se o parser esta dentro de <dt></dt> tag
+
+        self.inside_dd_element = False                                              # indica se o parser esta dentro de <dd></dd> tag
+        self.inside_dd_b_element = False                                            # indica se o parser esta dentro de <dt><b><b></dt> tag
+        self.inside_dd_b_a_element = False                                          # indica se o parser esta dentro de <dt><b><a><a><b></dt> tag
+
+    def start_dt(self, attrs):
+        for name, value in attrs:
+            if name == "class" and value == "quote":                                # <dt class="quote">...</dt>
+                self.inside_dt_element = True
+    
+    def end_dt(self):
+        self.inside_dt_element = False
+
+    def start_dd(self, attrs):
+        for name, value in attrs:
+            if name == "class" and value == "author":                               # <dd class="author">...</dd>
+                self.inside_dd_element = True
+
+    def end_dd(self):
+        self.inside_dd_element = False
+
+    def start_b(self, attrs):
+        if self.inside_dd_element:
+            self.inside_dd_b_element = True
+
+    def end_b(self):
+        self.inside_dd_b_element = False
+
+    def start_a(self, attrs):
+        if self.inside_dt_element:
+            self.inside_dt_a_element = True                                        # <dt class="quote"><a>Quote</a></dt>
+        if self.inside_dd_b_element:
+            self.inside_dd_b_a_element = True                                      # <dd class="author"><b><a>Quote</a></b></dd>
+
+    def end_a(self):
+        self.inside_dt_a_element = False
+        self.inside_dd_b_a_element = False
+
+    def handle_data(self, text):
+        if self.inside_dt_a_element:                                                # estamos dentro de <dt><a>...</a></dt>
+            self.quote.append(text)
+        if self.inside_dd_b_a_element:                                              # estamos dentro de <dd><b><a>...</a></b></dd>
+            self.author.append(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 14:24:56 +0000
+++ Quote/Quote	2010-11-23 21:19:25 +0000
@@ -16,7 +16,7 @@
 #    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, and Qdb.us
+# such as Quotationspage.com, Bash.org, Xkcdb.com, Qdb.us, and Danstonchat.fr
 
 import gobject, dbus, os, urllib, gtk, ConfigParser, itertools
 from dbus.mainloop.glib import DBusGMainLoop
@@ -25,154 +25,20 @@
 from urllib import FancyURLopener
 from util import log
 
+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
+
 DBusGMainLoop(set_as_default=True)
 
-quotationspage, bash, xkcdb, qdb = range(4)                                         # quotationspage = 0, bash = 1, xkcdb = 2, qdb = 3
+quotationspage, bash, xkcdb, qdb, danstonchat = range(5)                            # quotationspage = 0, bash = 1, xkcdb = 2, qdb = 3, danstonchat = 4
 
 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'
 
-class BashParser(SGMLParser):
-
-    def reset(self):                              
-        SGMLParser.reset(self)
-        self.quote = []
-        self.inside_p_element = False                                               # indica se o parser esta dentro de <p></p> tag
-        self.current_quote = ""
-
-    def start_p(self, attrs):
-        for name, value in attrs:
-            if name == "class" and value == "qt":                                   # <p class="qt">...</p>
-                self.inside_p_element = True
-    
-    def end_p(self):
-        self.inside_p_element = False
-        self.quote.append(self.current_quote)                                       # adiciona o conteudo completo da tag
-        self.current_quote = ""                                                     # reinicia o armazenador do conteudo
-
-    def handle_data(self, text):
-        if self.inside_p_element:                                                   # estamos dentro de <p>...</p>
-            text = text.replace('<', '[')                                           # se a string contem '<nome>', gera o erro na hora do ShowDialog
-            text = text.replace('>', ']')                                           # pango_layout_set_markup_with_accel: Unknown tag 'nome'
-            self.current_quote += text                                              # concatena tudo que tiver dentro da tag
-
-    def parse(self, page):
-        self.feed(page)                                                             # feed the parser with the page's html
-        self.close()
-
-class QdbParser(SGMLParser):
-
-    def reset(self):                              
-        SGMLParser.reset(self)
-        self.quote = []
-        self.inside_span_element = False                                            # indica se o parser esta dentro de <span></span> tag
-        self.current_quote = ""
-
-    def start_span(self, attrs):
-        for name, value in attrs:
-            if name == "class" and value == "qt":                                   # <span class="qt">...</span>
-                self.inside_span_element = True
-    
-    def end_span(self):
-        self.inside_span_element = False
-        self.quote.append(self.current_quote)                                       # adiciona o conteudo completo da tag
-        self.current_quote = ""                                                     # reinicia o armazenador do conteudo
-
-    def handle_data(self, text):
-        if self.inside_span_element:                                                # estamos dentro de <span>...</span>
-            text = text.replace('<', '[')                                           # se a string contem '<nome>', gera o erro na hora do ShowDialog
-            text = text.replace('>', ']')                                           # pango_layout_set_markup_with_accel: Unknown tag 'nome'
-            self.current_quote += text                                              # concatena tudo que tiver dentro da tag
-
-    def parse(self, page):
-        self.feed(page)                                                             # feed the parser with the page's html
-        self.close()
-
-class XkcdbParser(SGMLParser):
-
-    def reset(self):                              
-        SGMLParser.reset(self)
-        self.quote = []
-        self.inside_span_element = False                                               # indica se o parser esta dentro de <p></p> tag
-        self.current_quote = ""
-
-    def start_span(self, attrs):
-        for name, value in attrs:
-            if name == "class" and value == "quote":                                   # <p class="qt">...</p>
-                self.inside_span_element = True
-    
-    def end_span(self):
-        self.inside_span_element = False
-        self.quote.append(self.current_quote)                                       # adiciona o conteudo completo da tag
-        self.current_quote = ""                                                     # reinicia o armazenador do conteudo
-
-    def handle_data(self, text):
-        if self.inside_span_element:                                                   # estamos dentro de <dt><a>...</a></dt>
-            text = text.replace('<', '[')                                           # se a string contem '<nome>', gera o erro na hora do ShowDialog
-            text = text.replace('>', ']')                                           # pango_layout_set_markup_with_accel: Unknown tag 'nome'
-            self.current_quote += text                                              # concatena tudo que tiver dentro da tag
-
-    def parse(self, page):
-        self.feed(page)                                                             # feed the parser with the page's html
-        self.close() 
-
-class QuotationspageParser(SGMLParser):
-
-    def reset(self):                              
-        SGMLParser.reset(self)
-        self.quote = []
-        self.author = []
-        self.inside_dt_a_element = False                                            # indica se o parser esta dentro de <dt><a></a></dt> tag
-        self.inside_dt_element = False                                              # indica se o parser esta dentro de <dt></dt> tag
-
-        self.inside_dd_element = False                                              # indica se o parser esta dentro de <dd></dd> tag
-        self.inside_dd_b_element = False                                            # indica se o parser esta dentro de <dt><b><b></dt> tag
-        self.inside_dd_b_a_element = False                                          # indica se o parser esta dentro de <dt><b><a><a><b></dt> tag
-
-    def start_dt(self, attrs):
-        for name, value in attrs:
-            if name == "class" and value == "quote":                                # <dt class="quote">...</dt>
-                self.inside_dt_element = True
-    
-    def end_dt(self):
-        self.inside_dt_element = False
-
-    def start_dd(self, attrs):
-        for name, value in attrs:
-            if name == "class" and value == "author":                               # <dd class="author">...</dd>
-                self.inside_dd_element = True
-
-    def end_dd(self):
-        self.inside_dd_element = False
-
-    def start_b(self, attrs):
-        if self.inside_dd_element:
-            self.inside_dd_b_element = True
-
-    def end_b(self):
-        self.inside_dd_b_element = False
-
-    def start_a(self, attrs):
-        if self.inside_dt_element:
-            self.inside_dt_a_element = True                                        # <dt class="quote"><a>Quote</a></dt>
-        if self.inside_dd_b_element:
-            self.inside_dd_b_a_element = True                                      # <dd class="author"><b><a>Quote</a></b></dd>
-
-    def end_a(self):
-        self.inside_dt_a_element = False
-        self.inside_dd_b_a_element = False
-
-    def handle_data(self, text):
-        if self.inside_dt_a_element:                                                # estamos dentro de <dt><a>...</a></dt>
-            self.quote.append(text)
-        if self.inside_dd_b_a_element:                                              # estamos dentro de <dd><b><a>...</a></b></dd>
-            self.author.append(text)        
-
-    def parse(self, page):
-        self.feed(page)                                                             # feed the parser with the page's html
-        self.close()   
-
 class Interface:
 
     def __init__(self, source):
@@ -182,31 +48,29 @@
 
     def fetch(self):
         if (self.source == quotationspage):
-            parser = QuotationspageParser()                                         # create the parser
-            url = "http://www.quotationspage.com/qotd.html";
+            parser = QuotationspageParser()                                         # QuotationspageParser.py
         elif (self.source == bash):
-            parser = BashParser()                                                   # create the parser
-            url = "http://bash.org/?random";
+            parser = BashParser()                                                   # BashParser.py
         elif (self.source == xkcdb):
-            parser = XkcdbParser()
-            url = "http://www.xkcdb.com/?random";
+            parser = XkcdbParser()                                                  # XkcdbParser.py
+        elif (self.source == qdb):
+            parser = QdbParser()                                                    # QdbParser.py
         else:
-            parser = QdbParser()                                                    # create the parser
-            url = "http://www.qdb.us/random";            
+            parser = DanstonchatParser()                                            # DanstonchatParser.py
 
         opener = AgentOpener()                                                      # opens the web connection with masked user-agent
         
         try:
-            page = opener.open(url)                                                 # get the HTML
+            page = opener.open(parser.url)                                          # get the HTML
         except IOError:
-            print ("Problem to open %s" % (url))
+            print ("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):
+            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
         return self.quote, self.author
@@ -283,7 +147,7 @@
     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):
+        elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat):
             self.quotation = "%s" % self.quotes.next()
         try:
             self.icon.PopupDialog({'message':self.quotation, "buttons":"stock_copy;cancel"}, {})

=== modified file 'Quote/Quote.conf'
--- Quote/Quote.conf	2010-11-23 02:38:59 +0000
+++ Quote/Quote.conf	2010-11-23 21:19:25 +0000
@@ -1,4 +1,4 @@
-#!en;0.0.3
+#!en;0.0.4
 
 #[gtk-about]
 [Icon]
@@ -89,5 +89,5 @@
 
 #[gtk-preferences]
 [Configuration]
-#l[Quotationspage.com;Bash.org;Xkcdb.com;Qdb.us] Quote source:
+#l[Quotationspage.com;Bash.org;Xkcdb.com;Qdb.us;Danstonchat.com] Quote source:
 source = 0

=== added file 'Quote/XkcdbParser.py'
--- Quote/XkcdbParser.py	1970-01-01 00:00:00 +0000
+++ Quote/XkcdbParser.py	2010-11-23 21:19:25 +0000
@@ -0,0 +1,36 @@
+# 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 XkcdbParser(SGMLParser):
+
+    def reset(self):                              
+        SGMLParser.reset(self)
+        self.url = "http://www.xkcdb.com/?random";
+        self.quote = []
+        self.inside_span_element = False                                               # indica se o parser esta dentro de <p></p> tag
+        self.current_quote = ""
+
+    def start_span(self, attrs):
+        for name, value in attrs:
+            if name == "class" and value == "quote":                                   # <p class="qt">...</p>
+                self.inside_span_element = True
+    
+    def end_span(self):
+        self.inside_span_element = False
+        self.quote.append(self.current_quote)                                       # adiciona o conteudo completo da tag
+        self.current_quote = ""                                                     # reinicia o armazenador do conteudo
+
+    def handle_data(self, text):
+        if self.inside_span_element:                                                   # estamos dentro de <dt><a>...</a></dt>
+            text = text.replace('<', '[')                                           # se a string contem '<nome>', gera o erro na hora do ShowDialog
+            text = text.replace('>', ']')                                           # pango_layout_set_markup_with_accel: Unknown tag 'nome'
+            self.current_quote += text                                              # concatena tudo que tiver dentro da tag
+
+    def parse(self, page):
+        self.feed(page)                                                             # feed the parser with the page's html
+        self.close() 
+

=== modified file 'Quote/auto-load.conf'
--- Quote/auto-load.conf	2010-11-23 02:38:59 +0000
+++ Quote/auto-load.conf	2010-11-23 21:19:25 +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, and Xkcdb.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, and Danstonchat.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.3
+version = 0.0.4

=== modified file 'Quote/icon' (properties changed: +x to -x)
Binary files Quote/icon	2010-11-21 15:12:33 +0000 and Quote/icon	2010-11-23 21:19:25 +0000 differ
=== added file 'Quote/preview'
Binary files Quote/preview	1970-01-01 00:00:00 +0000 and Quote/preview	2010-11-23 21:19:25 +0000 differ
=== removed file 'Quote/preview.png'
Binary files Quote/preview.png	2010-11-21 15:12:33 +0000 and Quote/preview.png	1970-01-01 00:00:00 +0000 differ

Follow ups