Skip to content

Instantly share code, notes, and snippets.

@sbp
Created July 21, 2011 22:42
Show Gist options
  • Save sbp/1098414 to your computer and use it in GitHub Desktop.
Save sbp/1098414 to your computer and use it in GitHub Desktop.
Swhack search script
#!/usr/bin/python
import sys, os, time, urllib
print 'Content-Type: text/plain; charset=utf-8'
print
query = os.environ['QUERY_STRING']
query = urllib.unquote(query)
query = query.lower()
now = time.time()
day = 24 * 60 * 60
for i in xrange(28):
offset = day * i
d = time.gmtime(now - offset)
name = 'logs/%04i-%02i-%02i.txt' % (d[0], d[1], d[2])
try: f = open(name)
except IOError, OSError: continue
for line in reversed(list(f)):
if query in line.lower():
if '.o swhack' in line: continue
if '<phenny>' in line: continue
print '%04i-%02i-%02i' % (d[0], d[1], d[2]), line
f.close()
sys.exit(0)
f.close()
print 'No result in past month for "%s".' % query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment