Advertisement
Aha2Y

PyBNC-Classes

Apr 2nd, 2012
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. buffer = {}
  2.  
  3. class IRCbot():
  4.    def __init__(self):
  5.       self.server = ""
  6.       self.host = ""
  7.       self.nick = ""
  8.       self.ident = ""
  9.       self.host = ""
  10.       self.name = ""
  11.       self.auth = ""
  12.      
  13. def parse(line):
  14.     line = line.lstrip(":")
  15.     temp = line.split(" :", 1)
  16.     data = []
  17.     data.extend(temp[0].split(" "))
  18.     try:
  19.         data.append(temp[1])
  20.     except IndexError:
  21.         pass
  22.     return data
  23.  
  24. def readline(sock):
  25.    global buffer
  26.    try:
  27.       buffer[sock]
  28.    except:
  29.       buffer[sock] = ""
  30.    while "\n" not in buffer[sock]:
  31.       new = sock.recv(2**12)
  32.       buffer[sock] += new
  33.       if len(new) == 0:
  34.          break
  35.    splt = buffer[sock].split("\n", 1)
  36.    try:
  37.       buffer[sock] = splt[1]
  38.    except:
  39.       buffer[sock] = ""
  40.    return splt[0].rstrip("\r\n")
  41.    
  42. def duration_human(seconds):
  43.     seconds = long(round(seconds))
  44.     minutes, seconds = divmod(seconds, 60)
  45.     hours, minutes = divmod(minutes, 60)
  46.     days, hours = divmod(hours, 24)
  47.     years, days = divmod(days, 365.242199)
  48.  
  49.     minutes = long(minutes)
  50.     hours = long(hours)
  51.     days = long(days)
  52.     years = long(years)
  53.  
  54.     duration = []
  55.     if years > 0:
  56.         duration.append('%dy' % years + ''*(years != 1))
  57.     else:
  58.         if days > 0:
  59.             duration.append('%dd' % days + ''*(days != 1))
  60.         if hours > 0:
  61.             duration.append('%dh' % hours + ''*(hours != 1))
  62.         if minutes > 0:
  63.             duration.append('%dm' % minutes + ''*(minutes != 1))
  64.         if seconds > 0:
  65.             duration.append('%ds' % seconds + ''*(seconds != 1))
  66.     return ' '.join(duration)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement