Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import re
- import sys
- import urllib
- def findDemo(url, needle):
- print "Searching for '{0}' at {1}".format(needle, url)
- page = downloadFile(url)
- files = re.findall(r'<a href="(.*\.txt)">', page)
- pattern = re.compile(needle)
- numFiles = len(files)
- matches = []
- for i in range(0, numFiles):
- progressBar(i, numFiles)
- file = files[i]
- tmp = downloadFile(url + file)
- if pattern.search(tmp) is not None:
- mvd = file.replace('.txt', '.mvd')
- out = urllib.unquote(mvd)
- urllib.urlretrieve(url + mvd, out)
- matches.append(out)
- return matches
- def downloadFile(url):
- sock = urllib.urlopen(url)
- page = sock.read()
- sock.close()
- return page
- def progressBar(index, total):
- percent = float(index) / float(total) * 100
- sys.stdout.write("%3d%%\r" % percent)
- sys.stdout.flush()
- if __name__ == "__main__":
- if len(sys.argv) != 3:
- print "Usage: %s <url> <pattern>" % sys.argv[0]
- sys.exit(0)
- files = findDemo(sys.argv[1], sys.argv[2])
- if len(files) == 0:
- print "No demos found"
- sys.exit(0)
- print "Found demos:"
- for file in files:
- print file
Add Comment
Please, Sign In to add comment