Merge lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Moon into lp:~cairo-dock-team/cairo-dock-plug-ins-extras/third-party

Proposed by Eduardo Mucelli Rezende Oliveira
Status: Merged
Merged at revision: 175
Proposed branch: lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Moon
Merge into: lp:~cairo-dock-team/cairo-dock-plug-ins-extras/third-party
Diff against target: 247 lines (+112/-78)
4 files modified
Moon/ChangeLog (+1/-0)
Moon/Moon (+107/-76)
Moon/Moon.conf (+3/-1)
Moon/auto-load.conf (+1/-1)
To merge this branch: bzr merge lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Moon
Reviewer Review Type Date Requested Status
Matthieu Baerts Approve
Review via email: mp+61879@code.launchpad.net

Description of the change

Able to show the moon informations for all the current week. Using the FancyURLopener opener instead of urllib2, I do not know why I was using urllib2.

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

Thank you ;)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Moon/ChangeLog'
2--- Moon/ChangeLog 2011-05-12 07:24:49 +0000
3+++ Moon/ChangeLog 2011-05-21 22:31:08 +0000
4@@ -1,1 +1,2 @@
5+0.0.2: (May/22/2011): Able to show the moon informations for all the current week. Using the FancyURLopener opener instead of urllib2, I do not know why I was using urllib2.
6 0.0.1: (May/12/2011): Moon applet was created with the possibility to show the moon phases as its own icon, and to show some informations. The service used in this applet was created by Brian Casey -- http://www.briancasey.org/artifacts/astro/moon.cgi
7
8=== modified file 'Moon/Moon'
9--- Moon/Moon 2011-05-12 07:24:49 +0000
10+++ Moon/Moon 2011-05-21 22:31:08 +0000
11@@ -6,19 +6,18 @@
12 # E-mail: edumucelli@gmail.com or eduardom@dcc.ufmg.br
13 #
14 # This program is free software: you can redistribute it and/or modify
15-# it under the terms of the GNU General Public License as published by
16-# the Free Software Foundation, either version 3 of the License, or
17-# (at your option) any later version.
18+# it under the terms of the GNU General Public License as published by
19+# the Free Software Foundation, either version 3 of the License, or
20+# (at your option) any later version.
21
22 # This program is distributed in the hope that it will be useful,
23-# but WITHOUT ANY WARRANTY; without even the implied warranty of
24-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25-# GNU General Public License for more details.
26-
27-# This applet displays the moon phases as its own icon,
28-# and some informations about the current moon
29-
30-import urllib, urllib2, datetime, os, re
31+# but WITHOUT ANY WARRANTY; without even the implied warranty of
32+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33+# GNU General Public License for more details.
34+
35+# This applet displays the moon phases and its informations for the current day or week
36+
37+import urllib, datetime, os, re
38 from sgmllib import SGMLParser
39 from urllib import FancyURLopener
40
41@@ -28,77 +27,109 @@
42 from MoonCalendarParser import MoonCalendarParser
43
44 class AgentOpener(FancyURLopener):
45- """Masked user-agent otherwise the access would be forbidden"""
46- version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'
47+ """Masked user-agent otherwise the access would be forbidden"""
48+ version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'
49
50 class Interface:
51
52- def __init__(self, year, month, day):
53- self.year, self.month, self.day = year, month, day
54- self.information = ""
55- self.moon_image = ""
56-
57- def fetch(self):
58- parser = MoonCalendarParser()
59- opener = AgentOpener() # opens the web connection with masked user-agent
60- params = urllib.urlencode({'year': self.year, 'month': self.month, 'day': self.day})
61-
62- try:
63- page = urllib2.urlopen(parser.url, params) # get the HTML
64- except IOError:
65- log ("Problem to open %s" % (parser.url))
66- else:
67- parser.parse(page.read()) # feed the parser to get the specific content: translated text
68- page.close() # lets close the page connection
69- self.information = parser.information
70- self.moon_image = parser.moon_image
71- return self.moon_image, self.information
72-
73-# TODO: Use this struct to build the week structure in order to
74-# maintain the information about the moon for the next seven days
75-#class Data:
76-# def __init__(self, **kwds):
77-# self.__dict__.update(kwds)
78+ def __init__(self, year, month, day):
79+ self.year, self.month, self.day = year, month, day
80+ self.information = ""
81+ self.moon_image = ""
82+
83+ def fetch(self):
84+ parser = MoonCalendarParser()
85+ opener = AgentOpener() # opens the web connection with masked user-agent
86+ params = urllib.urlencode({'year': self.year, 'month': self.month, 'day': self.day})
87+
88+ try:
89+ page = opener.open(parser.url, params)
90+ except IOError:
91+ log("Problem to open %s" % (parser.url))
92+ else:
93+ parser.parse(page.read()) # feed the parser to get the specific content: translated text
94+ page.close() # lets close the page connection
95+ self.information = parser.information
96+ self.moon_image = parser.moon_image
97+ return self.moon_image, self.information
98
99 class Applet(CDApplet):
100
101- def inform_start_of_waiting_process(self):
102- self.icon.SetQuickInfo("...")
103-
104- def inform_end_of_waiting_process(self):
105- self.icon.SetQuickInfo("")
106-
107- def get_moon_from_web(self):
108- self.inform_start_of_waiting_process()
109-
110- interface = Interface(self.year, self.month, self.day)
111- image, information = interface.fetch()
112- self.information = re.sub("\s+\n\s+" , " \n", information) # " ".join(information.split())
113- # os.popen("wget -N -q http://www.briancasey.org/artifacts/astro/image/%s -O %s" % (image, os.path.abspath("./data/%s" % (image))))
114- self.icon.SetIcon(os.path.abspath("./data/%s" % image))
115-
116- self.inform_end_of_waiting_process()
117-
118- def __init__(self):
119-
120- self.year, self.month, self.day = datetime.date.today().timetuple()[:3]
121- self.information = ""
122- self.moon_image = ""
123- self.week = []
124- self.dialog_active_time = 30 # time in seconds that the dialog window will be active
125-
126- CDApplet.__init__(self) # call high-level init
127-
128- # Inherited methods from CDApplet
129- def begin(self):
130- self.get_moon_from_web()
131-
132- def reload(self):
133- self.get_moon_from_web() # refresh the moon informations
134-
135- # Callbacks
136- def on_click(self, key):
137- self.icon.PopupDialog({'message':self.information, 'time-length':self.dialog_active_time},{})
138+ def inform_start_of_waiting_process(self):
139+ self.icon.SetQuickInfo("...")
140+
141+ def inform_end_of_waiting_process(self):
142+ self.icon.SetQuickInfo("")
143+
144+ def flatten(self, array): # Ruby method :-)
145+ return [item for sublist in array for item in sublist]
146+
147+ def clean(self, string):
148+ return re.sub("\s+\n\s+" , " \n", string) # " ".join(information.split())
149+
150+ def get_moon_from_web(self):
151+ self.inform_start_of_waiting_process()
152+
153+ # TODO: Remove code duplication
154+ if self.show_week_moon: # week information
155+ today = datetime.date.today()
156+ tomorrow = datetime.timedelta(days=1)
157+ end_of_the_week = datetime.date.today() + datetime.timedelta(days=6)
158+ week = []
159+ self.week_information = []
160+ id = 0
161+ while today <= end_of_the_week:
162+ ye, mo, da = today.timetuple()[:3]
163+ interface = Interface(ye, mo, da)
164+ image, information = interface.fetch()
165+ self.week_information.append(self.clean(information))
166+ day_of_the_week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
167+ day = []
168+ day.append(day_of_the_week[datetime.date.weekday(today)]) # name of the icon is the week day name
169+ day.append(os.path.abspath("./data/%s" % image)) # icon image is the moon image
170+ day.append(str(id)) # id is a sequential from today (0) until end of the week (6)
171+ week.append(day)
172+ id += 1
173+ today += tomorrow
174+ # log(week)
175+ self.sub_icons.AddSubIcons(self.flatten(week))
176+ else: # todays information
177+ ye, mo, da = datetime.date.today().timetuple()[:3]
178+ interface = Interface(ye, mo, da)
179+ image, information = interface.fetch()
180+ self.information = self.clean(information)
181+ # os.popen("wget -N -q http://www.briancasey.org/artifacts/astro/image/%s -O %s" % (image, os.path.abspath("./data/%s" % (image))))
182+ image = os.path.abspath("./data/%s" % image)
183+ self.icon.SetIcon(image)
184+
185+ self.inform_end_of_waiting_process()
186+
187+ def __init__(self):
188+
189+ self.show_week_moon = False
190+ self.information = ""
191+ self.week_information = []
192+ self.dialog_active_time = 30 # time in seconds that the dialog window will be active
193+
194+ CDApplet.__init__(self) # call high-level init
195+
196+ # Inherited methods from CDApplet
197+ def begin(self):
198+ self.get_moon_from_web()
199+
200+ def get_config(self, keyfile):
201+ self.show_week_moon = keyfile.getboolean('Configuration', 'week') # get the source of quotations
202+
203+ def reload(self):
204+ self.get_moon_from_web() # refresh the moon informations
205+
206+ # Callbacks
207+ def on_click(self, key):
208+ if not self.show_week_moon: # avoid useless popup
209+ self.icon.PopupDialog({'message':self.information, 'time-length':self.dialog_active_time},{})
210+
211+ def on_click_sub_icon (self, state, sub_icon_id):
212+ self.icon.PopupDialog({'message':self.week_information[int(sub_icon_id)], 'time-length':self.dialog_active_time},{})
213
214 if __name__ == '__main__':
215 Applet().run()
216
217=== modified file 'Moon/Moon.conf'
218--- Moon/Moon.conf 2011-05-19 23:57:32 +0000
219+++ Moon/Moon.conf 2011-05-21 22:31:08 +0000
220@@ -1,4 +1,4 @@
221-#0.0.2
222+#!en;0.0.2
223
224 #[gtk-about]
225 [Icon]
226@@ -97,3 +97,5 @@
227
228 #[gtk-preferences]
229 [Configuration]
230+#b Show the moon for all the current week?
231+week = true
232
233=== modified file 'Moon/auto-load.conf'
234--- Moon/auto-load.conf 2011-05-19 23:57:32 +0000
235+++ Moon/auto-load.conf 2011-05-21 22:31:08 +0000
236@@ -4,7 +4,7 @@
237 author = Eduardo Mucelli Rezende Oliveira
238
239 # A short description of the applet and how to use it.
240-description = This applet displays the moon phases as its own icon and some informations about the current moon
241+description = This applet displays the moon phases and its informations for the current day, or week
242
243 # Category of the applet : 2 = files, 3 = internet, 4 = Desktop, 5 = accessory, 6 = system, 7 = fun
244 category = 5
245
246=== modified file 'Moon/preview'
247Binary files Moon/preview 2011-05-12 09:43:46 +0000 and Moon/preview 2011-05-21 22:31:08 +0000 differ

Subscribers

People subscribed via source and target branches