#1
  1. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154

    Get Current Time


    How do I get the exact current time in Python? I need these for my bot to recognize who is spamming in channels and who is not. (FloodBots in case you know that I'm talking about)Also while Im at it I have another question. VB6 needs a DataArrival when using the winsock control, in Python does socket module need anything of this type?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    136
    Rep Power
    10
    Originally Posted by †Yegg†
    How do I get the exact current time in Python? I need these for my bot to recognize who is spamming in channels and who is not. (FloodBots in case you know that I'm talking about)Also while Im at it I have another question. VB6 needs a DataArrival when using the winsock control, in Python does socket module need anything of this type?


    exact current time as in? localtime?
    Check out the time module, it got several options,
    example:

    Code:
    >>> import time
    >>> dir(time)
    ['__doc__', '__name__', 'accept2dyear', 'altzone', 'asctime', 'clock', 'ctime', 'daylight', 'gmtime', 'localtime', 'mktime', 'sleep', 'strftime', 'strptime', 'struct_time', 'time', 'timezone', 'tzname']
    >>> time.strftime("%X")
    '22:49:49'
    >>> time.strftime("%x")
    '12/19/04'
    >>> time.strftime("%a")
    'Sun'
    >>> time.strftime("%b")
    'Dec'
    >>> time.strftime("%d")
    '19'
    >>> time.strftime("%H")
    '22'
    >>> time.strftime("%M")
    '50'
    >>> time.strftime("%S")
    '12'
    >>> time.strftime("%Y")
    '2004'
    >>> time.asctime()
    'Sun Dec 19 22:51:41 2004'
    Your second question I can't answer as I dont know VB how sockets are used there. The best way to learn sockets in python is to read and test some examples..
    this is a good starting point(using UDP sockets): http://www.evolt.org/article/Socket_Programming_in_Python/17/60276/
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    73
    Rep Power
    10
    for your first question
    PHP Code:
    import time
    time
    .time() #returns a float
    #note 0 is 2:00AM 1 Jan 1970

    time.localtime() 
    #returns a list of 9 items of the following format
    #[Year, Month, Year, Hour. Minute, Second, Day of week, Daylight Savings (True or False) ]

    time.mktime() 
    #takes a list of 9 items in the time.localtime() format
    #and returns a number

    time.ctime() 
    #takes a number and returns a string, defualt is current time 
    in my opinion, store time in float format e.g time.time(), and do the conversion later, this would be more precise
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    40
    Rep Power
    10
    try this..

    import time
    ...
    currTime = time.strftime("%H:%M:%S", time.localtime(time.time()))
    ...

IMN logo majestic logo threadwatch logo seochat tools logo