1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-01-10 10:04:21 +01:00

detect when the pirate bay is blocked

This commit is contained in:
Viktor Stanchev 2014-02-01 06:58:55 -05:00
parent 5432de0b0e
commit 4cd591e47d

View File

@ -8,6 +8,12 @@ from HTMLParser import HTMLParser
import argparse import argparse
from pprint import pprint from pprint import pprint
class NoRedirection(urllib2.HTTPErrorProcessor):
def http_response(self, request, response):
return response
https_response = http_response
# create a subclass and override the handler methods # create a subclass and override the handler methods
class MyHTMLParser(HTMLParser): class MyHTMLParser(HTMLParser):
@ -104,7 +110,10 @@ def main():
else: else:
mirrors = ["http://thepiratebay.se"] mirrors = ["http://thepiratebay.se"]
try: try:
f = urllib2.urlopen("http://proxybay.info/list.txt") opener = urllib2.build_opener(NoRedirection)
f = opener.open("http://proxybay.info/list.txt")
if f.getcode() != 200:
raise Exception("The pirate bay responded with an error.")
res = f.read() res = f.read()
mirrors += res.split("\n")[3:] mirrors += res.split("\n")[3:]
except: except: