Merge lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote into lp:~cairo-dock-team/cairo-dock-plug-ins-extras/third-party
- Quote
- Merge into third-party
Status: | Merged |
---|---|
Merged at revision: | 264 |
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: |
240 lines (+91/-29) 5 files modified
Quote/ChangeLog (+1/-0) Quote/Quote (+43/-24) Quote/Quote.conf (+3/-3) Quote/ViedemerdeParser.py (+42/-0) Quote/auto-load.conf (+2/-2) |
To merge this branch: | bzr merge lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Matthieu Baerts | file missing | Needs Fixing | |
Review via email: mp+105581@code.launchpad.net |
Commit message
Description of the change
Added Viedemerde.fr, and more documentation on the code. I hope this new documentation can make it easier to ours_en_pluche to get together with me on this applet :)
Matthieu Baerts (matttbe) wrote : | # |
Eduardo Mucelli Rezende Oliveira (eduardo-mucelli) wrote : | # |
Damn, sorry!
As soon as I arrive at home, Im going to post it again.
Sorry about that.
On Mon, May 14, 2012 at 4:54 PM, Matthieu Baerts <email address hidden> wrote:
> Review: Needs Fixing file missing
>
> Hello and thank you for this new feature :)
>
> It seems ok except that this file is missing: ViedemerdeParser.py
>
> --
>
> https:/
> You are the owner of lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Quote.
>
--
Eduardo Mucelli R. Oliveira ~
Launchpad<https:/
Matthieu Baerts (matttbe) wrote : | # |
No problem, take time ;)
- 264. By Eduardo Mucelli Rezende Oliveira
-
ViedemerdeParser.py
Eduardo Mucelli Rezende Oliveira (eduardo-mucelli) wrote : | # |
Added.
Preview Diff
1 | === modified file 'Quote/ChangeLog' |
2 | --- Quote/ChangeLog 2012-03-28 20:50:03 +0000 |
3 | +++ Quote/ChangeLog 2012-05-14 16:35:25 +0000 |
4 | @@ -1,3 +1,4 @@ |
5 | +0.1:(May/13/2012): Added Viedemerde.fr, and more documentation on the code |
6 | 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. |
7 | 0.0.8:(March/17/2010): Added Grouphug.us. |
8 | 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. |
9 | |
10 | === modified file 'Quote/Quote' |
11 | --- Quote/Quote 2012-03-28 20:50:03 +0000 |
12 | +++ Quote/Quote 2012-05-14 16:35:25 +0000 |
13 | @@ -26,6 +26,18 @@ |
14 | |
15 | from CDApplet import CDApplet, _ |
16 | |
17 | +# To add a new parser you have to: |
18 | +# 1 - Create a file NameOfTheSiteParser.py, see BashParser.py, QdbParser.py, etc |
19 | +# 1.1 - For specific parts on the creation of the parser, refer to BashParser, some documentation is there |
20 | +# 2 - Import it "from MyWebSiteParser (module name) import MyWebSiteParser (class name)" |
21 | +# 3 - Add one identificator for the parser, for example, "quotationspage" = 1. Look that we already have |
22 | +# seven parsers = range(8). For each new one you add, you have increment the parameter on the range method |
23 | +# 4 - On the fetch method, add a new block |
24 | +# elif (self.source == mywebsite): |
25 | +# parser = MyNewWebSiteParser |
26 | +# And check if it is necessary to remove some extra character, check the documented part on the fetch method |
27 | +# 5 - Add the website option on the Quote.conf, see the [Configuration] section inside it |
28 | + |
29 | from BashParser import BashParser # Bash.org |
30 | from QdbParser import QdbParser # Qdb.us |
31 | from XkcdbParser import XkcdbParser # Xkcdb.com |
32 | @@ -33,8 +45,10 @@ |
33 | from DanstonchatParser import DanstonchatParser # Danstonchat.fr |
34 | from JokestogoParser import JokestogoParser # Jokes2go.com |
35 | from VidademerdaParser import VidademerdaParser # Vidademerda.com.br |
36 | +from ViedemerdeParser import ViedemerdeParser # Viedemerde.fr |
37 | |
38 | -quotationspage, bash, xkcdb, qdb, danstonchat, jokestogo, vidademerda = range(7) # quotationspage = 0, bash = 1, xkcdb = 2, qdb = 3, danstonchat = 4, jokestogo = 5, vidademerda = 6 |
39 | +# quotationspage = 0, bash = 1, xkcdb = 2, qdb = 3, danstonchat = 4, jokestogo = 5, vidademerda = 6, viedemerde = 7 |
40 | +quotationspage, bash, xkcdb, qdb, danstonchat, jokestogo, vidademerda, viedemerde = range(8) |
41 | |
42 | class AgentOpener(FancyURLopener): |
43 | """Masked user-agent otherwise the access would be forbidden""" |
44 | @@ -43,9 +57,9 @@ |
45 | class Interface: |
46 | |
47 | def __init__(self, source): |
48 | - self.source = source |
49 | - self.author = [] |
50 | - self.quote = [] |
51 | + self.source = source # The source of the quotes, it is the |
52 | + self.author = [] # List of authors of the current source |
53 | + self.quote = [] # List of quotes of the current source |
54 | |
55 | def fetch(self): |
56 | if (self.source == quotationspage): |
57 | @@ -60,8 +74,10 @@ |
58 | parser = DanstonchatParser() # DanstonchatParser.py |
59 | elif (self.source == jokestogo): |
60 | parser = JokestogoParser() |
61 | - else: # VidademerdaParser.py |
62 | + elif (self.source == vidademerda): # VidademerdaParser.py |
63 | parser = VidademerdaParser() |
64 | + else: # ViedemerdeParser.py |
65 | + parser = ViedemerdeParser() |
66 | |
67 | opener = AgentOpener() # opens the web connection with masked user-agent |
68 | |
69 | @@ -70,21 +86,24 @@ |
70 | except IOError: |
71 | log ("Problem to open %s" % (parser.url)) |
72 | else: |
73 | - parser.parse(page.read()) # feed the parser to get the specific content: translated text |
74 | - page.close() # lets close the page connection |
75 | + parser.parse(page.read()) # feed the parser with the page's content |
76 | + page.close() # close the page connection |
77 | + |
78 | + # Handle different kind of returns from the parser. It is necessary because some sources return quotes with extra |
79 | + # characters that we need to filter here. Some come with extra '', others come with linebreaks, etc. |
80 | if (self.source == quotationspage): |
81 | self.quote = parser.quote |
82 | self.author = parser.author |
83 | - elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat): |
84 | + elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat or self.source == viedemerde): |
85 | self.quote = filter(None, parser.quote) # remove the '' from the array |
86 | elif self.source == jokestogo: # jokestogo |
87 | - self.quote = filter(self.breakline, parser.quote) |
88 | + self.quote = filter(self.linebreak, parser.quote) # remove linebreak from the array |
89 | else: # vidademerda |
90 | self.quote = [''.join(parser.quote)] |
91 | self.author = parser.author |
92 | return self.quote, self.author |
93 | |
94 | - def breakline(self, item): |
95 | + def linebreak(self, item): |
96 | return not item == '\n' |
97 | |
98 | class Applet(CDApplet): |
99 | @@ -97,7 +116,7 @@ |
100 | self.copy_current_quote_key = 0 |
101 | self.go_next_quote_key = 1 |
102 | self.source = quotationspage |
103 | - self.cSiteNames = ['Quotationspage.com','Bash.org','Xkcdb.com','Qdb.us','Danstonchat.com','Jokes2go.com','Vidademerda.com.br'] |
104 | + self.cSiteNames = ['Quotationspage.com','Bash.org','Xkcdb.com','Qdb.us','Danstonchat.com','Jokes2go.com','Vidademerda.com.br', 'Viedemerde.fr'] |
105 | |
106 | CDApplet.__init__(self) # call high-level init |
107 | |
108 | @@ -108,26 +127,26 @@ |
109 | |
110 | # Quotes |
111 | def get_quotes_from_web(self): |
112 | - self.inform_start_of_waiting_process() # ... |
113 | + self.inform_start_of_waiting_process() # write "..." on the icon |
114 | interface = Interface(self.source) |
115 | quote, author = interface.fetch() |
116 | - if (self.source == quotationspage): # quotationspage nao da quotes diferentes por acesso ... |
117 | + if (self.source == quotationspage): # sources that gives the same quotes per fetch, we need circular iterator |
118 | self.quotes = itertools.cycle(quote) |
119 | self.authors = itertools.cycle(author) |
120 | - else: # ... os outros dao quotes diferentes por acesso entao |
121 | - self.quotes = iter(quote) # nao precisa usar iterador circular, pois depois de mostrar |
122 | - self.authors = iter(author) # todas, busca-se novas quotes com mais uma chamada deste metodo |
123 | - self.inform_end_of_waiting_process() # done |
124 | + else: # all the rest of sources that gives different quotes per fetch, for example, |
125 | + self.quotes = iter(quote) # pages that have "random" section from where we always fetch new quotes |
126 | + self.authors = iter(author) # from where we do not need to use circular iterator |
127 | + self.inform_end_of_waiting_process() # remove the "..." from the icon |
128 | |
129 | def show_quote(self): |
130 | if (self.source == quotationspage): |
131 | - self.quotation = "\"%s\" ~ %s" % (self.quotes.next(), self.authors.next()) # N-esima quote refere-se ao N-esimo autor."quote[x]~author[x]" |
132 | - elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat): |
133 | - try: # ve a possibilidade de mostrar quotes ja armazenadas |
134 | + self.quotation = "\"%s\" ~ %s" % (self.quotes.next(), self.authors.next()) # quote[x] ~ author[x] |
135 | + elif (self.source == bash or self.source == xkcdb or self.source == qdb or self.source == danstonchat or self.source == viedemerde): |
136 | + try: # check if it is possible to show the already stored quotes |
137 | current = self.quotes.next() |
138 | - except StopIteration: # todas ja foram mostradas |
139 | - self.get_quotes_from_web() # buscar mais |
140 | - current = self.quotes.next() # posicionar na primeira para mostra-la |
141 | + except StopIteration: # all were already shown |
142 | + self.get_quotes_from_web() # fetch more |
143 | + current = self.quotes.next() # get the first |
144 | self.quotation = "%s" % current |
145 | elif (self.source == jokestogo): # jokestogo provides only one quote per request ... |
146 | self.quotation = "%s" % self.quotes.next().rstrip() |
147 | @@ -166,7 +185,7 @@ |
148 | |
149 | def on_answer_dialog(self, key, content): |
150 | if (key == self.copy_current_quote_key): # cancel button = 1, and copy_current_quote_key = 0 |
151 | - self.set_to_clipboard(self.quotation) # copia para a area de transferencia a quotation atual |
152 | + self.set_to_clipboard(self.quotation) # copy to the transfer area the current quotation |
153 | elif (key == self.go_next_quote_key or key == CDApplet.DIALOG_KEY_ENTER): |
154 | self.show_quote() |
155 | |
156 | |
157 | === modified file 'Quote/Quote.conf' |
158 | --- Quote/Quote.conf 2012-03-28 20:50:03 +0000 |
159 | +++ Quote/Quote.conf 2012-05-14 16:35:25 +0000 |
160 | @@ -1,4 +1,4 @@ |
161 | -#0.0.9 |
162 | +#0.1 |
163 | |
164 | #[gtk-about] |
165 | [Icon] |
166 | @@ -102,5 +102,5 @@ |
167 | |
168 | #[gtk-preferences] |
169 | [Configuration] |
170 | -#l[Quotationspage.com;Bash.org;Xkcdb.com;Qdb.us;Danstonchat.com;Jokes2go.com;Vidademerda.com.br] Quote source: |
171 | -source = 0 |
172 | +#l[Quotationspage.com;Bash.org;Xkcdb.com;Qdb.us;Danstonchat.com;Jokes2go.com;Vidademerda.com.br;Viedemerde.fr] Quote source: |
173 | +source = 1 |
174 | |
175 | === added file 'Quote/ViedemerdeParser.py' |
176 | --- Quote/ViedemerdeParser.py 1970-01-01 00:00:00 +0000 |
177 | +++ Quote/ViedemerdeParser.py 2012-05-14 16:35:25 +0000 |
178 | @@ -0,0 +1,42 @@ |
179 | +# This is a part of the external Quote applet for Cairo-Dock |
180 | +# |
181 | +# Author: Eduardo Mucelli Rezende Oliveira |
182 | +# E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br |
183 | + |
184 | +from sgmllib import SGMLParser |
185 | + |
186 | +class ViedemerdeParser(SGMLParser): |
187 | + |
188 | + def reset(self): |
189 | + SGMLParser.reset(self) |
190 | + self.url = "http://www.viedemerde.fr/aleatoire" |
191 | + self.quote = [] # list of quotes to be filled |
192 | + self.inside_div_element = False # indicates if the parser is inside the <div></div> tag |
193 | + self.inside_div_p_element = False |
194 | + self.current_quote = "" |
195 | + |
196 | + def start_div(self, attrs): |
197 | + for name, value in attrs: |
198 | + if name == "class" and value == "post article": # <div class="post article">...</dt> |
199 | + self.inside_div_element = True |
200 | + |
201 | + def end_div(self): |
202 | + self.inside_div_element = False |
203 | + |
204 | + def start_p(self, attrs): |
205 | + if self.inside_div_element: |
206 | + self.inside_div_p_element = True # Parser is inside <div><p>...</p></div> |
207 | + |
208 | + def end_p(self): |
209 | + if self.inside_div_p_element: # if this is the end of our specific <div><p> tag, |
210 | + self.quote.append(self.current_quote) # append the whole content found inside <div><p>...</p></div>, |
211 | + self.current_quote = "" # clear it for the next quote, |
212 | + self.inside_div_p_element = False # and mark as finished tag |
213 | + |
214 | + def handle_data(self, text): |
215 | + if self.inside_div_p_element: # Concatenate all the content inside <div><p>...</p></div> |
216 | + self.current_quote += text |
217 | + |
218 | + def parse(self, page): |
219 | + self.feed(page) # feed the parser with the page's html |
220 | + self.close() |
221 | |
222 | === modified file 'Quote/auto-load.conf' |
223 | --- Quote/auto-load.conf 2011-05-19 23:57:32 +0000 |
224 | +++ Quote/auto-load.conf 2012-05-14 16:35:25 +0000 |
225 | @@ -4,13 +4,13 @@ |
226 | author = Eduardo Mucelli Rezende Oliveira |
227 | |
228 | # A short description of the applet and how to use it. |
229 | -description = This applet provides a "Quote of the day" feature from some internet sources such as:\n Quotationspage.com, Bash.org, Xkcdb.com, Qdb.us, Danstonchat.com, Jokes2go.com, and Vidademerda.com.br |
230 | +description = This applet provides a "Quote of the day" feature from some internet sources such as:\n Quotationspage.com, Bash.org, Xkcdb.com, Qdb.us, Danstonchat.com, Jokes2go.com, Vidademerda.com.br, and Viedemerde.fr |
231 | |
232 | # Category of the applet : 2 = files, 3 = internet, 4 = Desktop, 5 = accessory, 6 = system, 7 = fun |
233 | category = 7 |
234 | |
235 | # 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. |
236 | -version = 0.0.9 |
237 | +version = 0.1 |
238 | |
239 | # Whether the applet can be instanciated several times or not. |
240 | multi-instance = true |
Hello and thank you for this new feature :)
It seems ok except that this file is missing: ViedemerdeParser.py