Advertisement
einstein95

Untitled

May 25th, 2014
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.66 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from __future__ import print_function
  4. import re
  5. import urllib2
  6. import xchat
  7.  
  8. __module_name__ = "altwfc stats"
  9. __module_version__ = "0.01a"
  10. __module_description__ = "Checks the stats page for a gamecode [/stat]"
  11.  
  12. print("\0034", __module_name__, __module_version__, "(/stat) loading...\003")
  13.  
  14. wordlist = open('path\to\list.txt','r').read().split('\n')
  15. data = urllib2.Request("http://75.127.5.215:9001")
  16. opener = urllib2.build_opener()
  17. source = opener.open(data).read()
  18.  
  19. def delayed_say(text, context):
  20.     def on_timer(userdata):
  21.         context.command("SAY " + text)
  22.         return 0
  23.  
  24.     xchat.hook_timer(1, on_timer)
  25.  
  26. def stat(word, word_eol, userdata):
  27.     if re.search('^!stat$', word[1], re.IGNORECASE):
  28.         delayed_say(str(re.findall("<tr><td>((?:[a-zA-Z0-9]|)+?)</td><td><center>", source, re.IGNORECASE)).replace("'Game ID', ",'').replace('[','').replace(']',''), xchat.get_context())
  29.  
  30.     elif re.search('^!stat ', word[1], re.IGNORECASE):
  31.         word = re.findall('^!stat (.+?)$', word[1], re.IGNORECASE).pop()
  32.         # data.add_header('User-Agent', 'Mozilla/5.0 () Gecko/20091221 Firefox/4.0.0 GTB6 ()')
  33.  
  34.         try:
  35.             up = re.findall('<tr><td>((?:[a-zA-Z0-9]|)+?'+re.escape(word)+'(?:[a-zA-Z0-9]|)+?)</td><td><center>(.+?)</center></td></tr>', source, re.IGNORECASE)
  36.             if len(up) > 1:
  37.                 delayed_say("Choose one: "+str(re.findall("<tr><td>((?:[a-zA-Z0-9]|)+?"+re.escape(word)+"(?:[a-zA-Z0-9]|)+?)</td><td><center>", source, re.IGNORECASE)).replace("'Game ID', ",'').replace('[','').replace(']',''), xchat.get_context())
  38.             else:
  39.                 up = up.pop()
  40.                 if int(up[1]) == 1:
  41.                     delayed_say(up[0]+" has "+up[1]+" player.", xchat.get_context())
  42.                 else:
  43.                     delayed_say(up[0]+" has "+up[1]+" players.", xchat.get_context())
  44.         except IndexError:
  45.             try:
  46.                 for i in wordlist:
  47.                     i = i.split('\t')
  48.                     if word.lower() in i[0].lower():
  49.                         word = i[1]
  50.                         up = re.findall('<tr><td>((?:[a-zA-Z0-9]|)+?'+re.escape(word)+'(?:[a-zA-Z0-9]|)+?)</td><td><center>(.+?)</center></td></tr>', source, re.IGNORECASE)
  51.                         if len(up) > 1:
  52.                             delayed_say("Choose one: "+str(re.findall("<tr><td>((?:[a-zA-Z0-9]|)+?"+re.escape(word)+"(?:[a-zA-Z0-9]|)+?)</td><td><center>", source, re.IGNORECASE)).replace("'Game ID', ",'').replace('[','').replace(']',''), xchat.get_context())
  53.                         else:
  54.                             up = up.pop()
  55.                             if int(up[1]) == 1:
  56.                                 delayed_say(up[0]+" has "+up[1]+" player.", xchat.get_context())
  57.                             else:
  58.                                 delayed_say(up[0]+" has "+up[1]+" players.", xchat.get_context())
  59.             except IndexError:
  60.                 delayed_say("No matches/players for "+word+".", xchat.get_context())
  61.  
  62.  
  63. xchat.hook_print("Channel Message", stat)
  64. xchat.hook_print("Your Message", stat)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement