Advertisement
GeneralVeers

chatango.py Connection Update

Apr 17th, 2011
1,025
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1. #Before you continue, I should note that I was *not* the one to make these.  These codes were graciously provided to me by another bot coder (MyNameIsChriz) so that I could update my own bot's connection to Chatango chatrooms.
  2. #The self.server assignment in def:  __init__ of class chatroom should be updated to use the new getServer helper method.
  3.  
  4. self.server = getServer(self.name)
  5.  
  6. #I just put these toward the top of "Helper Methods," the bottom-most category of code in chatango.py.  It is a helper method, after all.
  7.  
  8. nspecials = {'mitvcanal': 56}
  9. tsweights = [['5', 61], ['6', 61], ['7', 61], ['8', 61], ['16', 61], ['17', 61], ['9', 90], ['11', 90], ['13', 90], ['14', 90], ['15', 90], ['23', 110], ['24', 110], ['25', 110], ['28', 104], ['29', 104], ['30', 104], ['31', 104], ['32', 104], ['33', 104], ['35', 101], ['36', 101], ['37', 101], ['38', 101], ['39', 101], ['40', 101], ['41', 101], ['42', 101], ['43', 101], ['44', 101], ['45', 101], ['46', 101], ['47', 101], ['48', 101], ['49', 101], ['50', 101], ['57', 110], ['58', 110], ['59', 110], ['60', 110], ['61', 110], ['62', 110], ['63', 110], ['64', 110], ['65', 110], ['66', 110]]
  10.  
  11. def getServer(group):
  12.     '''
  13.     Get the server host for a certain room.
  14.     @type group: str
  15.     @param group: room name
  16.     @rtype: str
  17.     @return: the server's hostname
  18.     '''
  19.     try:
  20.         sn = nspecials[group]
  21.     except KeyError:
  22.         group = group.replace("_", "q")
  23.         group = group.replace("-", "q")
  24.         fnv = float(int(group[0:min(5, len(group))], 36))
  25.         lnv = group[6: (6 + min(3, len(group) - 5))]
  26.         if(lnv):
  27.             lnv = float(int(lnv, 36))
  28.             if(lnv <= 1000):
  29.                 lnv = 1000
  30.         else:
  31.             lnv = 1000
  32.         num = (fnv % lnv) / lnv
  33.         maxnum = sum(map(lambda x: x[1], tsweights))
  34.         cumfreq = 0
  35.         sn = 0
  36.         for wgt in tsweights:
  37.             cumfreq += float(wgt[1]) / maxnum
  38.             if(num <= cumfreq):
  39.                 sn = int(wgt[0])
  40.                 break
  41.  
  42.     return "s" + str(sn) + ".chatango.com"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement