TimeClient win32api.setsystemtime

quickbbs at my-deja.com quickbbs at my-deja.com
Thu Oct 14 13:56:36 EDT 1999


Folks,

	I'm posting from Deja because I'm behind a firewall, please reply
either in the usenet conference, or to junkster at rochester.rr.com.

	This is the latest version of the timeserver *CLIENT*, it's not
quite ready, it's *ALMOST* ready...

	Except that when I use win32api.SetSystemTime, two little quirks
are happening.

	1) It's "GPF's" (Aka Dr. Watson reports a error has occurred).
	2) Even though the time.asctime (timetuple) reports the right
		time, the tuple when processed by SetSystemTime is off by
		5 hours.  It might be due to a setting somewhere in windows
		but can someone glance at this and make sure everything
		looks AOK?

	I'm not sure what's causing the GPF, the clock gets set (except
-5 hours), so the time/date set is occuring.  It just dies before it
closes the program.

			- Benjamin

#
#       Python Time Server client, based off of RFC 868.
#
#       Thanks to the folks in comp.language.python for their assistance
with this code.
#
#       This code is free to the public, EXCEPT, I would appreciate any
changes to be
#       emailed to me ("Junkster at rochester.rr.com")
#

import time
import struct
import sys
from telnetlib import Telnet

#
#       Use Telnet library to connect to server on port 37
#
print "Connecting to : ", sys.argv[1]
tn_session = Telnet(sys.argv[1], 37)    # Connect to NTP date / time
server
datetime   = tn_session.read_all()      # Read the Integer
tn_session.close()                      # Close the Telnet session

dt = struct.unpack ("!L", datetime)     # Unpack the data from the server

#
#       "Dump the Data to Screen for Debug"
#
print "Server Returned: ",datetime," |       Unpacked structure value :
", dt

#
#       Epoch is the diff. between Epochs between Python & RFC 868
#
epoch = 2208988800L
dt = (dt[0]) - epoch             # Remove "Tuple" status & Convert it to
a python time value

#
#       Print out "English" Version of time/date
#
timetuple = time.localtime(dt)
print "Time - ", time.asctime(timetuple)

#
#
#
if sys.platform == "win32":
        import win32api
        win32api.SetSystemTime (timetuple[0], timetuple[1], timetuple[6],
timetuple[2], timetuple[3], timetuple[4], timetuple[5], 0)


Sent via Deja.com http://www.deja.com/
Before you buy.




More information about the Python-list mailing list