python generated ktouch typing lessons

I have been teaching my self to type with ktouch. It is a pretty good program, I am already faster than I was in my hunt and peck days, about 120 kpm. I got tired of doing the same lessons over and over, starting with two keys and progressively getting more difficult. Even the most difficult lesson gets easier after you have typed the same nonsense sequences a dozen times.

I found that the lessons are stored in xml files and decided to write a script that would fetch articles from wikipedia and turn them into typing exercises.

here is the file and here is the code;

#! /usr/bin/python
# today's featured article from wikipedia scraped into ktouch lesson

from urllib import FancyURLopener
import re

# a custom urlopener with firefox2 user agent
class MyOpener(FancyURLopener) :
        version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv: Gecko/20071127 Firefox/'

# get the wikipedia mainpage
myopener = MyOpener()
address = ""
wikiEN =

# parse out Todays Featured Article
tfa = wikiEN.split('<div id="mp-tfa" style="padding:2px 5px">\n')[1].split('Recently featured:')[0]
tfa = re.sub('\n','',tfa)

# strip out the html tags
p = re.compile(r'<.*?>');
tdaStripped = p.sub('', tfa);

# break string into an array of strings ~70 characters long
l = len(tdaStripped)
lineArray = []
c = 0
while c <= l :
        oldc = c
        c += 70
        if oldc <= (l - 70) :
                while tdaStripped[c] != ' ' :
                        c += 1
        elif (l - oldc) > 50 :

# create /usr/share/kde4/apps/ktouch/wikipedia.ktouch.xml
# Lesson will be called 'Wikipedia English Daily Featured Article (auto-generated)'
output = '''<?xml version="1.0" encoding="UTF-8"?>
 <Title>Wikipedia English Daily Featured Article (auto-generated)</Title>
 <Comment>KTouch training file generated</Comment>
   <NewCharacters>Wikipedia Article</NewCharacters>'''
for line in lineArray :
        output += '\n    <Line>' + line + '</Line>'
output += '\n  </Level>\n </Levels>\n</KTouchLecture>'
outFile = open('/usr/share/kde4/apps/ktouch/wikipedia.ktouch.xml', 'w')

Now I could go ahead and schedule it to be run regularly and I would always have a fresh lesson.


2 thoughts on “python generated ktouch typing lessons

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s