Created
January 27, 2011 13:40
-
-
Save sbp/798510 to your computer and use it in GitHub Desktop.
Service to search the Swhack logs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import os, re, urllib, time | |
| querystring = os.environ.get('QUERY_STRING', '') | |
| pattern = urllib.unquote(querystring) | |
| r_pattern = re.compile('(?i)' + pattern) | |
| os.chdir('logs') | |
| matches = [] | |
| a = time.time() | |
| for name in sorted(os.listdir('.'), reverse=True)[:1000]: | |
| if not name.endswith('.txt'): continue | |
| with open(name) as f: | |
| lines = f.readlines() | |
| for line in reversed(lines): | |
| if r_pattern.search(line): | |
| if '.o swhack' in line: continue | |
| if '<phenny> 2' in line: continue | |
| text = name[:10] + ' ' + line[:5] + line[8:].rstrip() | |
| text = text.replace('Monty', 'M-nty') | |
| matches.append(text) | |
| if len(matches) >= 3: break | |
| if len(matches) >= 3: break | |
| b = time.time() | |
| print 'Content-Type: text/plain; charset=utf-8' | |
| if matches: | |
| print ' | '.join(matches) | |
| else: | |
| args = (pattern, round(b - a, 2)) | |
| print 'No results for /%s/. (Search took %s seconds)' % args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment