0rx

BGtime Fix for yachi

0rx
May 26th, 2014
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.42 KB | None | 0 0
  1.         if cmd=="bgtime" and self.getAccess(user) >=4 and len(args) > 0:
  2.                 args=args.lower()
  3.                 if len(args.split(" ", -1)) != 1:
  4.                     return
  5.                 if len(args) == 1:
  6.                     f_args, s_args = args, args
  7.                 elif len(args) > 1:
  8.                     f_args, s_args = args[0], args[1]
  9.  
  10.                 def getBgtime(args):
  11.                     expired = True
  12.                     url = ("http://st.chatango.com/profileimg/" + f_args + "/" + s_args + "/" + args + "/mod1.xml")
  13.                     f = urlreq.urlopen(url)
  14.                     data = f.read().decode("utf-8")
  15.                     e = ET.XML(data)
  16.                     bg = e.findtext("d")
  17.                     bg = int(urlreq.unquote(bg))
  18.                     if bg - int(time.time()) < 0:
  19.                       total_seconds = int(time.time())-bg
  20.                     else:
  21.                       total_seconds = bg-int(time.time())
  22.                       expired = False
  23.  
  24.                     # Helper vars:
  25.                     MINUTE  = 60
  26.                     HOUR    = MINUTE * 60
  27.                     DAY     = HOUR * 24
  28.  
  29.                     # Get the days, hours, etc:
  30.                     days    = int( total_seconds / DAY )
  31.                     hours   = int( ( total_seconds % DAY ) / HOUR )
  32.                     minutes = int( ( total_seconds % HOUR ) / MINUTE )
  33.                     seconds = int( total_seconds % MINUTE )
  34.  
  35.                     # Build up the pretty string (like this: "N days, N hours, N minutes, N seconds")
  36.                     string = ""
  37.                     if days > 0 or days < 0:
  38.                         string += str(days) + " " + (days == 1 and "day" or "days" ) + ", "
  39.                     if len(string) > 0 or hours > 0:
  40.                         string += str(hours) + " " + (hours == 1 and "hour" or "hours" ) + ", "
  41.                     if len(string) > 0 or minutes > 0:
  42.                         string += str(minutes) + " " + (minutes == 1 and "minute" or "minutes" ) + ", "
  43.                     string += str(seconds) + " " + (seconds == 1 and "second" or "seconds" )
  44.                     if expired == True:
  45.                       return "expired: "+string
  46.                     elif expired == False:
  47.                       return "time is: "+string
  48.                 room.message("<font face=\"arial\" size=\"11\"><b>" + args.title() + "</b> BG " + getBgtime(args), True)
Advertisement
Add Comment
Please, Sign In to add comment