[Pymoul-svn] SF.net SVN: pymoul: [280] pymoul/trunk/src/moul/time/podage.py
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-03-26 07:01:59
|
Revision: 280
http://pymoul.svn.sourceforge.net/pymoul/?rev=280&view=rev
Author: tiran
Date: 2007-03-26 00:01:58 -0700 (Mon, 26 Mar 2007)
Log Message:
-----------
Added HTML table creator for podage lists
Modified Paths:
--------------
pymoul/trunk/src/moul/time/podage.py
Modified: pymoul/trunk/src/moul/time/podage.py
===================================================================
--- pymoul/trunk/src/moul/time/podage.py 2007-03-25 17:55:31 UTC (rev 279)
+++ pymoul/trunk/src/moul/time/podage.py 2007-03-26 07:01:58 UTC (rev 280)
@@ -126,6 +126,10 @@
else:
dict.__getattribute__(self, name)
+ def __str__(self):
+ return ("%s (gate: %i, offset: %0.2f Pahrtahvotee)" %
+ (self['name'], self['gatenumber'], self['offset']))
+
class PodAgeTime(object):
"""A pod age day cycle and gate event timer
"""
@@ -207,32 +211,49 @@
from moul.time.dni import DniTime
from moul.time.utils import normalizeTZ
+def _createTimeList(limit):
+ data = {}
+ for name in listPodAges():
+ age = getPodAge(name)
+ pat = PodAgeTime(name)
+ agedata = data[name] = {}
+ dts = agedata['dt'] = []
+ dnis = agedata['dni'] = []
+ agedata['age'] = age
+ for n, dt in iter(pat):
+ if n > limit:
+ break
+ dnis.append(DniTime.fromUTC(dt))
+ dts.append(dt)
+ return data
+
def forumTimeTable(limit=5, fmt="%Y-%m-%d %H:%M:%S %Z", tzlist=('UTC', 'CET',
'US/Mountain', 'US/Pacific', 'US/Eastern',
'Australia/Sydney')):
"""Small utility function to create a nice list for the forum
"""
+ data = _createTimeList(limit)
for tz in tzlist:
print "[spoiler=%s]" % tz
- for age in listPodAges():
- pat = PodAgeTime(age)
- print
+ for name in listPodAges():
+ agedata = data[name]
+ age = agedata['age']
print age
- print 20 * "-"
- for n, dt in iter(pat):
- if n > limit:
- break
+ print 50 * "-"
+ for dt, dni in zip(agedata['dt'], agedata['dni']):
#dni = DniTime.fromUTC(dt)
ldt = normalizeTZ(tz, dt)
print ldt.strftime(fmt)
#print "Earth: %s, D'ni: %s, %i" % (ldt.strftime(fmt),
# str(dni), dni.pahrtahvo)
+ print
print "[/spoiler]"
def allTzList(limit=50, fmt="%Y-%m-%d %H:%M %Z"):
"""Small utility function to create a nice list for the forum
"""
from pytz import common_timezones
+ data = _createTimeList(limit)
base = os.path.join(os.path.dirname(__file__), 'out')
if not os.path.isdir(base):
os.mkdir(base)
@@ -241,24 +262,34 @@
if continent not in ('UTC', 'US', 'Australia', 'Europe', 'America'):
continue
tzname = tz.replace('/', '_')
- fd = open(os.path.join(base, "%s.html" % tzname), 'w')
- print >>fd, "<html><head><title>%s</title></head><body><pre>" % tz
+ fd = open(os.path.join(base, "%s.html" % tzname), 'w', 16*1024)
+ print >>fd, "<html><head><title>%s</title></head><body><table border='1'>" % tz
print tzname
- for age in listPodAges():
- pat = PodAgeTime(age)
- print >>fd
- print >>fd, age
- print >>fd, 20*"-"
- for n, dt in iter(pat):
- if n > limit:
- break
+ th = []
+ tr = []
+ for i in range(limit):
+ tr.append([])
+ for name in listPodAges():
+ agedata = data[name]
+ #th.append(str(agedata['age']))
+ th.append(name)
+ for i in range(limit):
#dni = DniTime.fromUTC(dt)
+ dt = agedata['dt'][i]
ldt = normalizeTZ(tz, dt)
- #print >>fd, "Earth: %s, D'ni: %s, %i" % (ldt.strftime(fmt),
+ tr[i].append(ldt.strftime(fmt))
+ #print "Earth: %s, D'ni: %s, %i" % (ldt.strftime(fmt),
# str(dni), dni.pahrtahvo)
- print >>fd, ldt.strftime(fmt)
- print >>fd, "\n"
- print >>fd, "</pre></body></html>"
+ print >>fd, "<tr>"
+ for td in th:
+ print >>fd, "<td>%s</td>" % td
+ print >>fd, "</tr>"
+ for row in tr:
+ print >>fd, "<tr>"
+ for d in row:
+ print >>fd, "<td>%s</td>" % d
+ print >>fd, "</tr>"
+ print >>fd, "</table></body></html>"
fd.close()
if __name__ == '__main__':
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|