[Tutor] Shifts and DateTime problems
mikalzet@libero.it
mikalzet@libero.it
Thu, 7 Feb 2002 01:20:53 +0100 (CET)
Well, by fumbling around I've finally reached this result:
class Shift:
def __init__(self, name="None", worker="None", begin="None", end="None"):
self.name = name
self.worker = worker
self.begin = begin
self.end = end
def __str__(self):
return str(self.name) + "\n" + str(self.worker) + "\n" + str(self.begin) + " - " + str(self.end)
from mx.DateTime import *
import pgdb
db = pgdb.connect(database = 'turni')
cursor = db.cursor()
cursor.execute('select * from shifts;')
shifts = cursor.fetchone()
pythonworker = shifts[0]
pythonname= shifts[3]
pythonbegin = DateTimeFrom(shifts[1])
pythonend = DateTimeFrom(shifts[2])
turno = Shift(name = pythonname, begin=pythonbegin.hour, end = pythonend.hour, worker = pythonworker)
print turno
Which gives me the following output:
Shiftsname
Workersname
7 - 13
So it seems most of the problems I was complaining about are solved.
It does seem sort of fumbling though ...
Any comments ?
--
Michele Alzetta