#!/usr/bin/python import re from urllib import urlopen   url = 'http://74.63.239.234/banlist.txt' ban_list = urlopen(url).readlines()   #clean shit from beginning of banlist.txt ban_list = ban_list[37:]   #init the ban list BANS = []   for line in ban_list:       #place holders     ban_nicks = []     ban_ids = []     ban_length = ""     ban_msg = []       #get ban time     ban_time = ' '.join(line.split()[:2])       #test for validity     if len(line.split('STEAM')) < 3: continue       # split the line with whitespace as delim     tmp_list = line.split()[2:]       #another validity test     if len(tmp_list) < 11: continue       #loop twice(2 STEAM id's)     for z in range(0,2):         for i in range(0,len(tmp_list)):             #match steam id             if re.match('STEAM_[0-1]:[0-1]:\d+', tmp_list[i]):                 #append id to place holder list                 ban_ids.append(tmp_list[i])                 #append everything before id to nick place holder list                 ban_nicks.append(' '.join(tmp_list[:i]))                 #if ban_length not set, it's right after 1st steam ID                 if len(ban_length) == 0: ban_length = tmp_list[i+1]                 #slice everything already looped away                 tmp_list = tmp_list[i+2:]                 #break to next parent loop                 break       #loop trough what's left in tmp_list (the ban msg and the extra at end)     for i in tmp_list:         #if we encounter '(' stop         if i.startswith('('): break         ban_msg.append(i)       #join the ban message back together     ban_msg = ' '.join(ban_msg)       #print shit      # print "----------"    # print "Ban timestamp: " + str(ban_time)    # print "Banned user: " + str(ban_nicks[0]) +' / '+ str(ban_ids[0])    # print "Ban message: " + str(ban_msg)    # print "Ban length: " + str(ban_length)    # print "Set by: " + str(ban_nicks[1]) +' / '+ str(ban_ids[1])    # print "----------"       #use tmp_list again to parse everything back together     tmp_list = [str(ban_time),str(ban_nicks[0]),str(ban_ids[0]),str(ban_length),str(ban_nicks[1]),str(ban_ids[1]),str(ban_msg)]     #append the list to the global ban list     BANS.append(tmp_list)   #from now on, you can manipulate BANS easily and extract info from them   #ie. this would print all banned nicks #for i in BANS: #    print i[1]   #ie. to get unique bans next = input("What do you want to know?\nPress 1 to print the amount of total bans and unique bans.\n\ Press 2 to look up all of the bans of a specific SteamID. > ") if next == 1:     unique_list = []     unique_tmp = []     for i in BANS:         if i[2] not in unique_tmp:             unique_tmp.append(i[2])             unique_list.append(i)       print "Unique bans: " + str(len(unique_list))     print "Total bans: " + str(len(BANS)) if next == 2:     id_list = []     id_tmp = []     id_compare = raw_input("What SteamID do you want to view bans for? > ")     for i in BANS: #        print i[2]         if i[2] == id_compare:             id_tmp.append(i)             print "----------"             print "Ban timestamp: " + str(i[0])             print "Banned user: " + str(i[1]) +' / '+ str(i[2])             print "Ban message: " + str(i[6])             print "Ban length: " + str(i[3])             print "Set by: " + str(i[4]) +' / '+ str(i[5])             print "----------"     # print id_list         #['03/02/10 12:55:09', 'Unknown', 'STEAM_0:1:9420667', '1440', 'Sinavestos', 'STEAM_0:0:26672860', 'repeated spawnkill, next time will be perma']