← Back to team overview

cairo-dock-team team mailing list archive

[Merge] lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Moon into lp:cairo-dock-plug-ins-extras

 

Eduardo Mucelli Rezende Oliveira has proposed merging lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Moon 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/Moon/+merge/61879

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.
-- 
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Moon/+merge/61879
Your team Cairo-Dock Team is requested to review the proposed merge of lp:~eduardo-mucelli/cairo-dock-plug-ins-extras/Moon into lp:cairo-dock-plug-ins-extras.
=== modified file 'Moon/ChangeLog'
--- Moon/ChangeLog	2011-05-12 07:24:49 +0000
+++ Moon/ChangeLog	2011-05-21 22:31:08 +0000
@@ -1,1 +1,2 @@
+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.
 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

=== modified file 'Moon/Moon'
--- Moon/Moon	2011-05-12 07:24:49 +0000
+++ Moon/Moon	2011-05-21 22:31:08 +0000
@@ -6,19 +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.
-
-# This applet displays the moon phases as its own icon, 
-# and some informations about the current moon
-
-import urllib, urllib2, datetime, os, re
+#	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 displays the moon phases and its informations for the current day or week
+
+import urllib, datetime, os, re
 from sgmllib import SGMLParser
 from urllib import FancyURLopener
 
@@ -28,77 +27,109 @@
 from MoonCalendarParser import MoonCalendarParser
 
 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, year, month, day):
-        self.year, self.month, self.day = year, month, day
-        self.information = ""
-        self.moon_image = ""
-
-    def fetch(self):
-        parser = MoonCalendarParser()
-        opener = AgentOpener()                                                      # opens the web connection with masked user-agent
-        params = urllib.urlencode({'year': self.year, 'month': self.month, 'day': self.day})
-
-        try:
-            page = urllib2.urlopen(parser.url, params)                              # 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
-            self.information = parser.information
-            self.moon_image = parser.moon_image
-        return self.moon_image, self.information
-
-# TODO: Use this struct to build the week structure in order to
-# maintain the information about the moon for the next seven days
-#class Data:
-#    def __init__(self, **kwds):
-#        self.__dict__.update(kwds)
+	def __init__(self, year, month, day):
+		self.year, self.month, self.day = year, month, day
+		self.information = ""
+		self.moon_image = ""
+
+	def fetch(self):
+		parser = MoonCalendarParser()
+		opener = AgentOpener()													  		# opens the web connection with masked user-agent
+		params = urllib.urlencode({'year': self.year, 'month': self.month, 'day': self.day})
+
+		try:
+			page = opener.open(parser.url, params)
+		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
+			self.information = parser.information
+			self.moon_image = parser.moon_image
+		return self.moon_image, self.information
 
 class Applet(CDApplet):
 
-    def inform_start_of_waiting_process(self):
-        self.icon.SetQuickInfo("...")
-
-    def inform_end_of_waiting_process(self):
-        self.icon.SetQuickInfo("")
-
-    def get_moon_from_web(self):
-        self.inform_start_of_waiting_process()
-
-        interface = Interface(self.year, self.month, self.day)
-        image, information = interface.fetch()
-        self.information = re.sub("\s+\n\s+" , " \n", information)                                 # " ".join(information.split())
-        # os.popen("wget -N -q http://www.briancasey.org/artifacts/astro/image/%s -O %s" % (image, os.path.abspath("./data/%s" % (image))))
-        self.icon.SetIcon(os.path.abspath("./data/%s" % image))
-
-        self.inform_end_of_waiting_process()
-
-    def __init__(self):
-
-        self.year, self.month, self.day = datetime.date.today().timetuple()[:3]
-        self.information = ""
-        self.moon_image = ""
-        self.week = []
-        self.dialog_active_time = 30                                                    # time in seconds that the dialog window will be active
-
-        CDApplet.__init__(self)                                                         # call high-level init
-
-    # Inherited methods from CDApplet
-    def begin(self):
-        self.get_moon_from_web()
-
-    def reload(self):
-        self.get_moon_from_web()                                                        # refresh the moon informations
-
-    # Callbacks
-    def on_click(self, key):
-        self.icon.PopupDialog({'message':self.information, 'time-length':self.dialog_active_time},{})
+	def inform_start_of_waiting_process(self):
+		self.icon.SetQuickInfo("...")
+
+	def inform_end_of_waiting_process(self):
+		self.icon.SetQuickInfo("")
+
+	def flatten(self, array):															# Ruby method :-)
+		return [item for sublist in array for item in sublist]
+	
+	def clean(self, string):
+		return re.sub("\s+\n\s+" , " \n", string)										# " ".join(information.split())
+
+	def get_moon_from_web(self):
+		self.inform_start_of_waiting_process()
+		
+		# TODO: Remove code duplication
+		if self.show_week_moon:															# week information
+			today = datetime.date.today()
+			tomorrow = datetime.timedelta(days=1)
+			end_of_the_week = datetime.date.today() + datetime.timedelta(days=6)
+			week = []
+			self.week_information = []
+			id = 0
+			while today <= end_of_the_week:
+				ye, mo, da = today.timetuple()[:3]
+				interface = Interface(ye, mo, da)
+				image, information = interface.fetch()
+				self.week_information.append(self.clean(information))
+				day_of_the_week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
+				day = []
+				day.append(day_of_the_week[datetime.date.weekday(today)])				# name of the icon is the week day name
+				day.append(os.path.abspath("./data/%s" % image))						# icon image is the moon image
+				day.append(str(id))														# id is a sequential from today (0) until end of the week (6)
+				week.append(day)
+				id += 1
+				today += tomorrow
+			# log(week)
+			self.sub_icons.AddSubIcons(self.flatten(week))
+		else:																			# todays information
+			ye, mo, da = datetime.date.today().timetuple()[:3]
+			interface = Interface(ye, mo, da)
+			image, information = interface.fetch()
+			self.information = self.clean(information)
+			# os.popen("wget -N -q http://www.briancasey.org/artifacts/astro/image/%s -O %s" % (image, os.path.abspath("./data/%s" % (image))))
+			image = os.path.abspath("./data/%s" % image)
+			self.icon.SetIcon(image)
+
+		self.inform_end_of_waiting_process()
+
+	def __init__(self):
+
+		self.show_week_moon = False
+		self.information = ""
+		self.week_information = []
+		self.dialog_active_time = 30													# time in seconds that the dialog window will be active
+
+		CDApplet.__init__(self)														 	# call high-level init
+
+	# Inherited methods from CDApplet
+	def begin(self):
+		self.get_moon_from_web()
+
+	def get_config(self, keyfile):
+		self.show_week_moon = keyfile.getboolean('Configuration', 'week')				# get the source of quotations
+
+	def reload(self):
+		self.get_moon_from_web()														# refresh the moon informations
+
+	# Callbacks
+	def on_click(self, key):
+		if not self.show_week_moon:														# avoid useless popup
+			self.icon.PopupDialog({'message':self.information, 'time-length':self.dialog_active_time},{})
+	
+	def on_click_sub_icon (self, state, sub_icon_id):
+		self.icon.PopupDialog({'message':self.week_information[int(sub_icon_id)], 'time-length':self.dialog_active_time},{})
 
 if __name__ == '__main__':
 	Applet().run()

=== modified file 'Moon/Moon.conf'
--- Moon/Moon.conf	2011-05-19 23:57:32 +0000
+++ Moon/Moon.conf	2011-05-21 22:31:08 +0000
@@ -1,4 +1,4 @@
-#0.0.2
+#!en;0.0.2
 
 #[gtk-about]
 [Icon]
@@ -97,3 +97,5 @@
 
 #[gtk-preferences]
 [Configuration]
+#b Show the moon for all the current week?
+week = true

=== modified file 'Moon/auto-load.conf'
--- Moon/auto-load.conf	2011-05-19 23:57:32 +0000
+++ Moon/auto-load.conf	2011-05-21 22:31:08 +0000
@@ -4,7 +4,7 @@
 author = Eduardo Mucelli Rezende Oliveira
 
 # A short description of the applet and how to use it.
-description = This applet displays the moon phases as its own icon and some informations about the current moon
+description = This applet displays the moon phases and its informations for the current day, or week
 
 # Category of the applet : 2 = files, 3 = internet, 4 = Desktop, 5 = accessory, 6 = system, 7 = fun
 category = 5

=== modified file 'Moon/preview'
Binary files Moon/preview	2011-05-12 09:43:46 +0000 and Moon/preview	2011-05-21 22:31:08 +0000 differ

Follow ups