Python code for a personalized idea prompt generator

Sophia

Staff member
Super Moderator
Moderator
Super Member
Registered
Joined
Apr 10, 2007
Messages
4,550
Reaction score
1,781
Location
U.K.
This little program is a story idea/prompt generator that will run on your own computer. The personalization comes from the input file for the program, which is a mind map that you can create using FreeMind, mind-mapping software available at no cost from http://freemind.sourceforge.net/wiki/index.php/Main_Page.

The idea for this mind map is based entirely on the concept of the Sweet Spot Map by Holly Lisle, which she describes in detail in her paid writing course How To Think Sideways. I asked my husband if he would write this program as it might be of use for people taking that course, but I thought it could be of use to writers here, too. As I don't have permission to share Holly's course material, I'll describe the mind map like this: it's a file that contains words, descriptions, names, places, random images, feelings... just anything that hold a 'spark' of energy for you. You can add to it whenever you like.

I hope that that is not so vague that it seems pointless.

The generator will display however many random prompts from your mind maps that you would like. The program is written in Python, and requires you to install Python in order to run it. Here are step-by-step instructions to get it all going.

1. This is the code for the program. Copy and paste it into something like Notepad, and save it in the same folder that contains your mind map files. In my example below, it's called mmparse.py. (But generator.py will work just as well.)

import xml.dom.minidom
import random
import sys

fileName = sys.argv[1]
numItems = int(sys.argv[2])

mm_file = open(fileName,'r')
mm = xml.dom.minidom.parse(mm_file)

mm_nodes = mm.getElementsByTagName('node')

textList = []
for node in mm_nodes:
textList.append(node.getAttribute('TEXT'))

if numItems > len(textList):
print 'You have specified more items than exist in the file.\nPrinting everything in random order.'
numItems = len(textList)
else:
print 'Printing %s of %s items.' % (numItems,len(textList))

print '---------------------------------------------------'

for i in range(numItems):
print textList.pop(random.randrange(len(textList)))



2. Go to:

http://www.python.org/download/releases/2.7/

Download:

Windows x86 MSI Installer (2.7)

That is what I used on my Windows XP system. The file is 15.2 MB.

The downloaded file is called python-2.7.msi. Double-click on it to install Python 2.7. You can choose the default options.

To tell your system it can use Python (I'm assuming you're using Windows XP, here) :

Right-click on My Computer and select Properties.
Go to the Advanced tab and select Environment Variables.
Scroll down through the System variables list until you find Path. Select it and click on Edit.
At the end of the Variable value, enter

;C:\Program Files\Python27\

(or whatever the path is to where you installed the program.)

Click OK on all these windows.


Open Command Prompt (which is usually under Accessories in the Start Menu). To test Python has installed properly, you can type

python -c "print 'hello'"

That should display the word hello. :)


Change to the directory where your mind map files are by typing cd followed by the path: e.g.

cd Desktop\Novel\Mind Maps

Finally, to run the generator, type

python mmparse.py "My Map.mm" 3

Here, mmparse.py is the name of the generator program, "My map.mm" is the name of the FreeMind map file, and 3 is the number of elements you'd like returned.

You can ask for any number of elements here. If you enter more than the number of elements the map file contains, it will tell you, and then display them all randomly.

If your mind map file name doesn't contain spaces, you don't need to use the quotation marks.


I hope this is of some use to people here. You may edit the code above as you wish.
 
Last edited:

Matera the Mad

Bartender, gimme a Linux Mint
Super Member
Registered
Joined
Jan 6, 2008
Messages
13,979
Reaction score
1,533
Location
Wisconsin's (sore) thumb
Website
www.firefromthesky.org
Drtat. :( I wish it didn't depend on a mind map. I've found that I can't handle mind map progs very well. Can't see enough if font is big enough to read, and my mind is hard to map anyway. And I loathe Java apps (Freemind is). But I already have two versions of Python installed, so the temptation will undoubtedly triumph. :D