Advertisement
ijontichy

listwads.py

Dec 24th, 2011
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import re, os, sys
  4. import sre_constants
  5.  
  6. from urllib import request
  7.  
  8.  
  9. BASENAME = os.path.basename(sys.argv[0])
  10. USAGE = "{} <re>".format(BASENAME)
  11.  
  12. PARSERE = r''' +<a href=".+?">(.+?)</a> +? (\d{2}-[A-Za-z]{3}-\d{4}) (\d{2}:\d{2}) +([\d\.]+[GKM]?) +'''
  13. PARSERE = re.compile(PARSERE)
  14.  
  15. def errorExit(reason):
  16.     print("{}: error: {}".format(BASENAME, reason))
  17.     sys.exit(1)
  18.  
  19. def usage():
  20.     print("usage:", USAGE)
  21.  
  22. def usageExit(reason):
  23.     print("{}: error: {}".format(BASENAME, reason))
  24.     usage()
  25.     sys.exit(128)
  26.  
  27. if len(sys.argv) < 2:
  28.     usageExit("needs an RE")
  29.  
  30. try:
  31.     matchRE = re.compile(sys.argv[1])
  32. except sre_constants.error:
  33.     errorExit("invalid RE")
  34.  
  35. url   = request.urlopen("http://wadhost.fathax.com/files")
  36. derp  = url.read().decode()
  37.  
  38. for line in derp.split("\n"):
  39.     match = PARSERE.match(line)
  40.    
  41.     if match:
  42.         name, date, time, size = match.groups()
  43.  
  44.         if matchRE.match(name):
  45.             print(name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement