-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reconnect the wiki repo; Wikipedia-based automation
- Loading branch information
1 parent
6a92ade
commit 5d97fd7
Showing
3 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "wiki"] | ||
path = wiki | ||
url = git@github.com:grammarware/glossary.wiki.git | ||
url = git@github.com:grammarware/sleg.wiki.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/local/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import urllib, urllib2, httplib, socket | ||
|
||
languages = ('en','ru','nl','de') | ||
|
||
def safelyLoadURL(url): | ||
errors = 0 | ||
while errors<3: | ||
try: | ||
return urllib.urlopen(url).read() | ||
except IOError,e: | ||
print 'Warning: failed to load URL, retrying...' | ||
errors += 1 | ||
except socket.error,e: | ||
print 'Warning: connection reset by peer, retrying...' | ||
errors += 1 | ||
print 'Error fetching URL:',url | ||
return '' | ||
|
||
for root, dirs, filenames in os.walk('wiki/'): | ||
for f in filter(lambda x:x.endswith('.md'),filenames): | ||
if f == 'Home.md': | ||
continue | ||
print f | ||
md = open('wiki/%s' % f, 'r') | ||
topic = '' | ||
links = [] | ||
for line in md.readlines(): | ||
if not line: | ||
continue | ||
for chunk in line.split('[')[1:]: | ||
name = chunk.split(']')[0] | ||
link = chunk.split('](')[1].split('))')[0] | ||
if name == 'Wikipedia': | ||
links.append(link) | ||
print 'Checking up',topic | ||
for link in links: | ||
print '----->',link | ||
rawlink = link.replace('.wikipedia.org/wiki/', '.wikipedia.org/w/index.php?title=')+'&action=raw' | ||
for iw in filter(lambda x:x.startswith('[[') and x.strip().endswith(']]') and x[2:4] in languages and x[4]==':', safelyLoadURL(rawlink).split('\n')): | ||
newlink = 'http://%s.wikipedia.org/wiki/%s' % (iw[2:4],iw.split(':')[1].split(']]')[0]) | ||
newlink = newlink.replace('(','%28').replace(')','%29') | ||
if newlink not in links: | ||
print ' ?-->',newlink | ||
md.close() |
Submodule wiki
updated
from 622c64 to d5f926