Jump to content

User:BogBot/Source code/Task 04

From Wikipedia, the free encyclopedia

This bot uses the standard pagefromfile.py script with the following parameters:

  • python pagefromfile.py -start:"<begin>" -end:"<end>" -notitle -file:redirects.txt -summary:"created systematic redirect per bot approval, report errors and suggestions to User_talk:BogBot"

The redirects.txt input file is creating using the following python script:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

# create input text file for redirect recreation using pagefromfile.py script

# example record created by this script:
# <begin>
# '''ADA (gene)'''
# #REDIRECT [[Adenosine deaminase]]
# {{R from gene symbol}}
# <end>

from __future__ import print_function
import codecs

lines = codecs.open('entrez_wiki_title_symbol.txt', mode = 'r', encoding='utf-8')

f = codecs.open('redirects.txt', mode = 'w', encoding='utf-8')

for line in lines:
    line = line.rstrip('\n')
    elements = line.split("\t")
    entrez = elements[0]
    title  = elements[1]
    symbol = elements[2]
    if not "(gene)" in title:
        symbol = symbol + " (gene)"
        print("<begin>", file=f)
        print("'''" + symbol + "'''", file=f)
        print("#REDIRECT [[" + title + "]]", file=f)
        print("{{R from gene symbol}} ", file=f)
        print("<end>", file=f)