Last active
June 27, 2016 23:50
-
-
Save whym/4af2d44d586942ab03f51800b0398425 to your computer and use it in GitHub Desktop.
Add interwiki links to pages with no interwiki links
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
import sys | |
import oursql | |
sys.path.append(os.environ['PWB']) | |
from scripts import interwiki | |
import pywikibot | |
def mygen(): | |
conn = oursql.connect(host = 'enwiktionary.labsdb', | |
read_default_file=os.path.expanduser('~/.my.cnf'), | |
db = 'enwiktionary_p', | |
charset=None, | |
use_unicode=False) | |
cursor = conn.cursor() | |
cursor.execute(''' | |
SELECT page_title | |
FROM page | |
WHERE page_namespace = 0 | |
AND NOT EXISTS( SELECT * FROM langlinks WHERE page_id = ll_from) | |
AND NOT page_is_redirect | |
''') | |
site = pywikibot.Site() | |
for col in cursor: | |
yield pywikibot.Page(site, list(col)[0].decode('utf-8')) | |
if __name__ == '__main__': | |
args = ['-dir:%s/.pywikibot' % os.environ['HOME'], | |
'-lang:en', | |
'-family:wiktionary', | |
'-user:Whymbot', | |
'-wiktionary', | |
'-autonomous', | |
'-async', | |
'-query:500', | |
#'-simulate', | |
'-putthrottle:60'] | |
args = pywikibot.handle_args(args) | |
for arg in args: | |
interwiki.globalvar.readOptions(arg) | |
bot = interwiki.InterwikiBot() | |
gen = mygen() | |
bot.setPageGenerator(iter(gen)) | |
bot.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment