2014-02-26 23:22:53 +00:00
|
|
|
#!/usr/bin/env python2
|
2012-04-07 13:58:19 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2012-08-14 18:11:37 +00:00
|
|
|
# Copyright (C) 2011-2012 WikiTeam
|
2012-04-07 13:58:19 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2012-08-14 18:11:37 +00:00
|
|
|
# Script to check if a list of wikis are alive or dead
|
|
|
|
|
2012-04-07 13:58:19 +00:00
|
|
|
import thread
|
|
|
|
import time
|
|
|
|
import sys
|
2012-08-14 18:11:37 +00:00
|
|
|
import urllib2
|
2014-01-27 20:47:14 +00:00
|
|
|
import exceptions
|
2014-01-05 10:50:18 +00:00
|
|
|
import re
|
2012-04-07 13:58:19 +00:00
|
|
|
|
2014-01-27 20:47:14 +00:00
|
|
|
# Configuration
|
2014-01-29 10:47:15 +00:00
|
|
|
delay = 30 # Seconds before timing out on request
|
2012-04-07 13:58:19 +00:00
|
|
|
limit = 100
|
|
|
|
|
2014-01-05 10:50:18 +00:00
|
|
|
def printapi(api):
|
|
|
|
print api, 'is alive'
|
|
|
|
open('wikisalive.txt', 'a').write(('%s\n' % api.strip()).encode('utf-8'))
|
|
|
|
|
2012-08-14 18:11:37 +00:00
|
|
|
def checkcore(api):
|
2014-01-27 20:47:14 +00:00
|
|
|
req = urllib2.Request(api, None)
|
2012-04-07 13:58:19 +00:00
|
|
|
try:
|
2014-01-27 20:47:14 +00:00
|
|
|
raw = urllib2.urlopen(req, None, delay).read()
|
|
|
|
except IOError: # http://docs.python.org/2/howto/urllib2.html#handling-exceptions
|
2012-08-14 19:08:50 +00:00
|
|
|
print api, 'is dead or has errors'
|
2014-01-27 20:47:14 +00:00
|
|
|
return
|
|
|
|
# RSD is available since 1.17, bug 25648
|
|
|
|
rsd = re.search(r'(?:link rel="EditURI".+href=")(?:https?:)?(.+api.php)\?action=rsd', raw)
|
|
|
|
# Feeds are available, with varying format, in 1.8 or earlier
|
|
|
|
feed = re.search(r'(?:link rel="alternate" type="application/)(?:atom|rss)(?:\+xml[^>]+href="/)([^>]*index.php)(?:\?title=[^>]+&)(?:feed|format)', raw)
|
|
|
|
# Sometimes they're missing though, this should catch the rest but goes out of <head>
|
|
|
|
login = re.search(r'(?:<li id="pt-login"><a href="/)([^>]*index.php)', raw)
|
|
|
|
domain = re.search(r'(https?://.[^/]+/)', api)
|
2014-01-29 10:47:15 +00:00
|
|
|
# TODO: Simplistic check for API. The docs page can be returned even if everything else
|
|
|
|
# is choking on database or PHP errors (hundreds online wikis fatal on every request).
|
2014-01-27 20:47:14 +00:00
|
|
|
if 'This is an auto-generated MediaWiki API documentation page' in raw:
|
|
|
|
printapi(api)
|
|
|
|
elif rsd:
|
|
|
|
api = 'http:' + rsd.group(1)
|
|
|
|
printapi(api)
|
|
|
|
elif feed:
|
|
|
|
index = domain.group(1) + feed.group(1)
|
|
|
|
printapi(index)
|
|
|
|
elif login:
|
|
|
|
index = domain.group(1) + login.group(1)
|
|
|
|
printapi(index)
|
|
|
|
else:
|
|
|
|
print api, 'is not a MediaWiki wiki'
|
2012-04-07 13:58:19 +00:00
|
|
|
|
2012-08-14 18:11:37 +00:00
|
|
|
def check(apis):
|
|
|
|
for api in apis:
|
|
|
|
thread.start_new_thread(checkcore, (api,))
|
|
|
|
time.sleep(0.1)
|
|
|
|
time.sleep(delay+1)
|
|
|
|
|
2012-04-07 13:58:19 +00:00
|
|
|
apis = []
|
2012-08-14 18:11:37 +00:00
|
|
|
for api in open('wikistocheck.txt', 'r').read().strip().splitlines():
|
2012-04-07 13:58:19 +00:00
|
|
|
if not api in apis:
|
|
|
|
apis.append(api)
|
|
|
|
if len(apis) >= limit:
|
2012-08-14 18:11:37 +00:00
|
|
|
check(apis)
|
2012-04-07 13:58:19 +00:00
|
|
|
apis = []
|
|
|
|
|
2012-08-14 18:11:37 +00:00
|
|
|
check(apis)
|