Python Crossword Solver

I was looking for help with a particular word in a crossword puzzle. All of the apps in the iPhone app store at the time were charging for this pleasure so I decided to write my own.

Using a script from here. I’ve converted it into a CGI based Apache Web Server script: Crossword Solver

Thanks to Stealthcopter for the simple but effective code.

So now I can run the script when I’m out and about just using the web browser.

Here’s the Python code which lives in the cgi-bin of the web server:


#!/usr/bin/python
import cgi
import cgitb; cgitb.enable()

form=cgi.FieldStorage()
word=form['c1'].value
f=open('/usr/share/dict/words', 'r')

resulthtml = """Content-Type: text/html\n
 <head></head>
 <body>
 Possible Words Are:<br>
 """

print resulthtml

for line in f:
    line=line.strip()
    
    if len(line)==len(word):
        good=1
        position=0
        
        for letter in word:
            if not letter=='*':
                if not letter==line[position]:
                    good=0
            position+=1
        if good==1:
            print line + "<br>"
f.close()
print "</body></html>"

Here’s a (very) simple piece of HTML as the basic web page. It will do as a starter. I’ll need to make this pretty so that it renders properly on the iPhone:

<head>
</head>
<body>
<form action="/cgi-bin/crossword.py"> 
Enter Word. Use * for missing letters:<br>
  <input type="text" name="c1">
  <br>
<input type="submit">
  <br>
</form>
</body>
</html>

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • StumbleUpon

Post a Comment

You must be logged in to post a comment.

Bad Behavior has blocked 12 access attempts in the last 7 days.