← 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/67097

Adding support the perspective of the Southern Hemisphere.
-- 
https://code.launchpad.net/~eduardo-mucelli/cairo-dock-plug-ins-extras/Moon/+merge/67097
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-24 14:44:30 +0000
+++ Moon/ChangeLog	2011-07-06 22:06:00 +0000
@@ -1,3 +1,4 @@
+0.0.4: (July/6/2011): Adding support the perspective of the Southern Hemisphere.
 0.0.3: (May/24/2011): Fixing a non sub-icons cleaning problem. Adding moon00b.gif that I forgot. Changing the whole icon set, using the icons created by Presto-X -- http://presto-x.deviantart.com/art/Presto-s-Moon-Phases-53625689
 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-24 14:44:30 +0000
+++ Moon/Moon	2011-07-06 22:06:00 +0000
@@ -16,6 +16,7 @@
 #	GNU General Public License for more details.
 
 # This applet displays the moon phases and its informations for the current day or week
+# from the Northern or Southern hemisphere
 
 import urllib, datetime, os, re
 from sgmllib import SGMLParser
@@ -39,7 +40,7 @@
 
 	def fetch(self):
 		parser = MoonCalendarParser()
-		opener = AgentOpener()													  		# opens the web connection with masked user-agent
+		opener = AgentOpener()													  	# opens the web connection with masked user-agent
 		params = urllib.urlencode({'year': self.year, 'month': self.month, 'day': self.day})
 
 		try:
@@ -47,8 +48,8 @@
 		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
+			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
@@ -61,73 +62,87 @@
 	def inform_end_of_waiting_process(self):
 		self.icon.SetQuickInfo("")
 
-	def flatten(self, array):															# Ruby method :-)
+	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())
+		return re.sub("\s+\n\s+" , " \n", string)									# " ".join(information.split())
 	
 	def clean_week_icons(self):
 		self.sub_icons.RemoveSubIcon("any")
 
+	def name_of_the_day(self, day):
+		days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
+		return days[datetime.date.weekday(day)]
+
+	def img_local_path(self, image):
+		return os.path.abspath("./data/%s" % image)
+
 	def get_moon_from_web(self):
 		self.inform_start_of_waiting_process()
 
 		self.clean_week_icons()
 		# TODO: Remove code duplication
-		if self.show_week_moon:															# week information
+		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)
+			last_day = datetime.date.today() + datetime.timedelta(days=6)
 			week = []																# ['namesubicon1','imagesubicon1','idsubicon1', 'namesubicon2' ...]
 			self.week_information = []
 			id = 0
-			while today <= end_of_the_week:
+			while today <= last_day:
 				ye, mo, da = today.timetuple()[:3]
 				interface = Interface(ye, mo, da)
 				image, information = interface.fetch()
+				# The website provides images from the Northern perspective, but since
+				# a) The images differs horizontally by "a", or "b" in its names;
+				# b) The moon differs horizontally between hemispheres;
+				# It is just a question of replace "a" (North) by "b" (South)
+				if self.hemisphere == self.south:
+					image = image.replace('a','b')
 				self.week_information.append(self.clean(information))
-				day_of_the_week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
-				week.append(day_of_the_week[datetime.date.weekday(today)])				# name of the icon is the week day name
-				week.append(os.path.abspath("./data/%s" % image))					# icon image is the moon image
-				week.append(str(id))													# id is a sequential from today (0) until end of the week (6)
+				week.append(self.name_of_the_day(today))
+				week.append(self.img_local_path(image))
+				week.append(str(id))												# id is a sequential from today (0) until end of the week (6)
 				id += 1
 				today += tomorrow
 			# log(week)
 			self.sub_icons.AddSubIcons(week)
-		else:																			# todays information
+		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.icon.SetIcon(self.img_local_path(image))
 
 		self.inform_end_of_waiting_process()
 
 	def __init__(self):
 
 		self.show_week_moon = False
+		self.north, self.south = range(2)
+		self.hemisphere = self.north
 		self.information = ""
 		self.week_information = []
-		self.dialog_active_time = 30													# time in seconds that the dialog window will be active
+		self.dialog_active_time = 30												# time in seconds that the dialog window will be active
 
-		CDApplet.__init__(self)														 	# call high-level init
+		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
+		self.show_week_moon = keyfile.getboolean('Configuration', 'week')			# information from the current day or from the whole week
+		self.hemisphere = keyfile.getboolean('Configuration', 'hemisphere')			# view from the north, or south hemisphere
 
 	def reload(self):
-		self.get_moon_from_web()														# refresh the moon informations
+		self.get_moon_from_web()													# refresh the moon informations
 
 	# Callbacks
 	def on_click(self, key):
-		if not self.show_week_moon:														# avoid useless popup
+		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):

=== modified file 'Moon/Moon.conf'
--- Moon/Moon.conf	2011-05-24 14:44:30 +0000
+++ Moon/Moon.conf	2011-07-06 22:06:00 +0000
@@ -1,4 +1,4 @@
-#!en;0.0.3
+#!en;0.0.4
 
 #[gtk-about]
 [Icon]
@@ -99,3 +99,6 @@
 [Configuration]
 #b Show the moon for all the current week?
 week = true
+#l[North;South] Hemisphere:
+#{You are going to see the moon from the perspective of this hemisphere}
+hemisphere=0

=== modified file 'Moon/auto-load.conf'
--- Moon/auto-load.conf	2011-05-24 14:44:30 +0000
+++ Moon/auto-load.conf	2011-07-06 22:06:00 +0000
@@ -4,13 +4,13 @@
 author = Eduardo Mucelli Rezende Oliveira
 
 # A short description of the applet and how to use it.
-description = This applet displays the moon phases and its informations for the current day, or week
+description = This applet displays the moon phases and its informations for the current day, or week from the Northern or Southern hemisphere
 
 # Category of the applet : 2 = files, 3 = internet, 4 = Desktop, 5 = accessory, 6 = system, 7 = fun
 category = 5
 
 # 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
 
 # Whether the applet can be instanciated several times or not.
 multi-instance = true


Follow ups