This Python script does two things:
- Writes a text file based on input
- Takes the previous used text file to sort its items into arrays based by tag
The following is the steps of the two functions within the script:
Writing (theSource):
- Create the variable continuation set to true
- Do Steps 3 - 5 while continuation is true
- Create the variable writing set to the user's input
- if the variable writing is equal to the string "#End#", set continuation to false and add the writing to the file theSource
- If the conditions in step 4 are false, add the writing along with a new line indicator to the file the Source
- close theSource
Sorting(theSource, listNumber):
- Create these variables: continuation set to true, count set to 0, and currentItem set to ""
- Try to set currentItem to the first line read in theSource
- When an exception occurs, set continuation to false, print "Failed Reading", and return
- Set currentItem to itself without the last character in the string
- Do steps 6 - 23 while continuation is true
- If currentItem is equal to the string "#Greetings", do steps ## - ##
- Set continuation to true, create empty array listGreetings
- Do lines 9 - 11 while continuation is true
- Set currentItem to the next line read in theSource
- If currentItem doesn't start with a "#", add currentItem without the last character to the listGreetings array
- If the conditions in step 10 are false, set continuation to false
- Set currentItem to itself without the last character
- Set count to 0
- If currentItem is equal to the string "#Goodbyes", do steps ## - ##
- Set continuation to true, create empty array listGoodbyes
- Do lines 16 - 19 while continuation is true
- Set currentItem to the next line read in theSource
- If currentItem doesn't start with a "#", add currentItem without the last character to the listGoodbyes array
- If the conditions in step 10 are false, set continuation to false
- Set currentItem to itself without the last character
- Set count to 0
- Increment count by 1
- If count is equal to 2, set continuation to false
- If the currentItem is equal to "#End", close theSource. If listNumber is 1, return listGreetings. If listNumber is 2, return listGoodbyes