All pastes #825625 Raw Edit

Miscellany

public python v1 · immutable
#825625 ·published 2007-12-20 18:25 UTC
rendered paste body
# PhoneTree.py# Version - 0.0.1# Date - 11-18-07############################################################################## This was written by James Middendorff  # to work with Commercial Telephone Systems' # Recipient Response App for the Amanda Voicemail system written by# Doug Jones of Commercial Telephone Systems# This script will count the number of lines in LIST.TXT and change the # appropriate number in CALLSTRING.TXT, it will also read through #the dir, c:\CTS and list all files so you can maintain multiple #lists to call. Then you can run the rest of the # app by dialing the pilot for the app, which is determined by the # CTS technician# ##############################################################################License GPLv3##############################important notes################################ALL text files should be held inside C:/CTS#Important files#LIST.TXT#CALLSTRING.TXT - holds the main callstring for the app#CALLSTRING2.TXT - holds the recall stringimport reimport osimport sysdef replace_string():        astring = '+(%S9)I(%S9,>,18,5010)V("C:/CTS/LIST.TXT",3,4,1,%S0,2,%S1,3,%S2,%S9)O(30)9,%S1W(4,V,5002)R(G1,%S2,20)I(%S2,=,1,5003)I(%S2,=,2,5004)I(%S2,=,3,5005)I(%S2,=," ",5006)'        new_string = re.sub('>,\d+,', '>,%s,' % new_ver_from_file, astring)        #after this we need to open the list.txt and write the string to that filedef count_lines(): #this is used to count all lines in the list.txt        new_ver_from_file = len(open(use_file).readlines()) def replace_filename():        newest_string = re.sub('"C:/CTS/LIST.TXT"', '"%s"' % use_file, new_string)        def show_txtfiles(): #this will list all files in the dir, may not be needed as of 12-20-07 not needed        for files in os.walk("/home/james/Documents"): ##path is for linux environment                print filesdef write_to_file():        print "Writing the CALLSTRING.TXT in order to start the Phone Tree. "        #os.popen3("ren C:/CTS/CALLSTRING.TXT C:/CTS/CALLSTRING.BAK") may use this later for error checking        open('C:/CTS/CALLSTRING.TXT', 'w')        openfile.write(astring)        openfile.close()        def manage_lists():        print "Manage Lists"        print "'1'  Congregation"        print "'2'  Choir"        print "'3'  Children SS Teachers"        print "'4'  Adult SS Teachers"        print "'5'  Youth"         print "'6'  Bridge Workers"        print "'7'  Ushers"        print "'8'  Greeters"        print "'9'  Angel Food"        print "'10' Deacons"        print "'11' Nursery"        print "'12' To return to the main menu"def list_options():        print "'1' Edit List"        print "'2' Use List"        print "'3' To return to the main menu"        #This will actually do all the work, it is basically a huge while loopdef RunTree():        Selection = raw_input("Select a number: ")        while Selection != "12":                if Selection == "1":                        # os.popen3("cls")                        print "Manage The Congregation List"                        list_options()                        Selection = raw_input("Select a number: ")                        while Selection != "3":                                if Selection == '1':                                        os.popen3("notepad.exe C:/CTS/Congregation.txt")                                        manage_lists()                                          Selection = raw_input("Select a number: ")                                elif Selection == '2':                                        use_file = "C:/CTS/Congregation.txt"                                        count_lines()                                        replace_string()                                        replace_filename()                                        write_to_file()                                        print "You may now call the pilot"                                        manage_lists()                                        Selection = raw_input("Select a number: ")                elif Selection == "2":                        # os.popen3("cls")                        print "Manage The Choir List"                        list_options()                        Selection = raw_input("Select a number: ")                        while Selection != "3":                                if Selection == '1':                                        os.popen3("notepad.exe C:/CTS/Choir.txt")                                        manage_lists()                                          Selection = raw_input("Select a number: ")                                elif Selection == '2':                                        use_file = "C:/CTS/Choir.txt"                                        count_lines()                                        replace_string()                                        replace_filename()                                        write_to_file()                                        print "You may now call the pilot"                                        manage_lists()                                        Selection = raw_input("Select a number: ")                        elif Selection == "3":                        # os.popen3("cls")                        print "Manage The Children SS Teachers List"                        list_options()                        Selection = raw_input("Select a number: ")                        while Selection != "3":                                if Selection == '1':                                        os.popen3("notepad.exe C:/CTS/ChildrenSS.txt")                                        manage_lists()                                          Selection = raw_input("Select a number: ")                                elif Selection == '2':                                        use_file = "C:/CTS/ChildrenSS.txt"                                        count_lines()                                        replace_string()                                        replace_filename()                                        write_to_file()                                        print "You may now call the pilot"                                        manage_lists()                                        Selection = raw_input("Select a number: ")                elif Selection == "4":                        # os.popen3("cls")                        print "Manage The Adult SS List"                        list_options()                        Selection = raw_input("Select a number: ")                        while Selection != "3":                                if Selection == '1':                                        os.popen3("notepad.exe C:/CTS/AdultSS.txt")                                        manage_lists()                                          Selection = raw_input("Select a number: ")                                elif Selection == '2':                                        use_file = "C:/CTS/AdultSS.txt"                                        count_lines()                                        replace_string()                                        replace_filename()                                        write_to_file()                                        print "You may now call the pilot"                                        manage_lists()                                        Selection = raw_input("Select a number: ")                elif Selection == "5":                        # os.popen3("cls")                        print "Manage The Youth Workers List"                        list_options()                        Selection = raw_input("Select a number: ")                        while Selection != "3":                                if Selection == '1':                                        os.popen3("notepad.exe C:/CTS/YouthWorkers.txt")                                        manage_lists()                                          Selection = raw_input("Select a number: ")                                elif Selection == '2':                                        use_file = "C:/CTS/YouthWorkers.txt"                                        count_lines()                                        replace_string()                                        replace_filename()                                        write_to_file()                                        print "You may now call the pilot"                                        manage_lists()                                        Selection = raw_input("Select a number: ")                        elif Selection == "6":                        # os.popen3("cls")                        print "Manage The Bridge Builders List"                        list_options()                        Selection = raw_input("Select a number: ")                        while Selection != "3":                                if Selection == '1':                                        os.popen3("notepad.exe C:/CTS/BridgeBuilders.txt")                                        manage_lists()                                          Selection = raw_input("Select a number: ")                                elif Selection == '2':                                        use_file = "C:/CTS/BridgeBuilders.txt"                                        count_lines()                                        replace_string()                                        replace_filename()                                        write_to_file()                                        print "You may now call the pilot"                                        manage_lists()                                        Selection = raw_input("Select a number: ")                elif Selection == "7":                        print "Ushers Menu "                        print "Press '1' for Team 1"                        print "Press '2' for Team 2"                        print "Press '3' for Team 3"                        print "Press '4' for Team 4"                        Selection = raw_input("Select a number: ")                        while Selection !="5":                                if Selection == '1':                                        print "Press '1' to edit Ushers Team 1"                                        print "Press '2' to use Ushers Team 1"                                        Selection = raw_input("Select a number")                                        while Selection !="3":                                                if Selection == "1":                                                        os.popen3("notepad.exe C:/CTS/Ushers1.txt")                                                        manage_lists()                                                          Selection = raw_input("Select a number: ")                                                elif Selection == "2":                                                        use_file = "C:/CTS/Ushers1.txt"                                                        count_lines()                                                        replace_string()                                                        replace_filename()                                                        write_to_file()                                                        print "You may now call the pilot"                                                        manage_lists()                                                        Selection = raw_input("Select a number: ")                                elif Selection == '2':                                        print "Press '1' to edit Ushers Team 1"                                        print "Press '2' to use Ushers Team 1"                                        Selection = raw_input("Select a number")                                        while Selection !="3":                                                if Selection == "1":                                                        os.popen3("notepad.exe C:/CTS/Ushers2.txt")                                                        manage_lists()                                                          Selection = raw_input("Select a number: ")                                                elif Selection == "2":                                                        use_file = "C:/CTS/Ushers2.txt"                                                        count_lines()                                                        replace_string()                                                        replace_filename()                                                        write_to_file()                                                        print "You may now call the pilot"                                                        manage_lists()                                                        Selection = raw_input("Select a number: ")                                elif Selection =='3':                                        print "Press '1' to edit Ushers Team 3"                                        print "Press '2' to use Ushers Team 3"                                        Selection = raw_input("Select a number")                                        while Selection !="3":                                                if Selection == "1":                                                        os.popen3("notepad.exe C:/CTS/Ushers3.txt")                                                        manage_lists()                                                          Selection = raw_input("Select a number: ")                                                elif Selection == "2":                                                        use_file = "C:/CTS/Ushers3.txt"                                                        count_lines()                                                        replace_string()                                                        replace_filename()                                                        write_to_file()                                                        print "You may now call the pilot"                                                        manage_lists()                                                        Selection = raw_input("Select a number: ")                                elif Selection =='4':                                        print "Press '1' to edit Ushers Team 4"                                        print "Press '2' to use Ushers Team 4"                                        Selection = raw_input("Select a number")                                        while Selection !="3":                                                if Selection == "1":                                                        os.popen3("notepad.exe C:/CTS/Ushers4.txt")                                                        manage_lists()                                                          Selection = raw_input("Select a number: ")                                                elif Selection == "2":                                                        use_file = "C:/CTS/Ushers4.txt"                                                        count_lines()                                                        replace_string()                                                        replace_filename()                                                        write_to_file()                                                        print "You may now call the pilot"                                                        manage_lists()                                                        Selection = raw_input("Select a number: ")                                      elif Selection == "8":                        print "Manage The Bridge Greeters List"                        list_options()                        Selection = raw_input("Select a number: ")                        while Selection != "3":                                if Selection == '1':                                        os.popen3("notepad.exe C:/CTS/Greeters.txt")                                        manage_lists()                                          Selection = raw_input("Select a number: ")                                elif Selection == '2':                                        use_file = "C:/CTS/Greeters.txt"                                        count_lines()                                        replace_string()                                        replace_filename()                                        write_to_file()                                        print "You may now call the pilot"                                        manage_lists()                                        Selection = raw_input("Select a number: ")                elif Selection == "9":                        print "Manage The Angel Food List"                        list_options()                        Selection = raw_input("Select a number: ")                        while Selection != "3":                                if Selection == '1':                                        os.popen3("notepad.exe C:/CTS/AngelFood.txt")                                        manage_lists()                                          Selection = raw_input("Select a number: ")                                elif Selection == '2':                                        use_file = "C:/CTS/AngelFood.txt"                                        count_lines()                                        replace_string()                                        replace_filename()                                        write_to_file()                                        print "You may now call the pilot"                                        manage_lists()                                        Selection = raw_input("Select a number: ")                 elif Selection == "10":                        print "Manage The Bridge Deacons List"                        list_options()                        Selection = raw_input("Select a number: ")                        while Selection != "3":                                if Selection == '1':                                        os.popen3("notepad.exe C:/CTS/Deacons.txt")                                        manage_lists()                                          Selection = raw_input("Select a number: ")                                elif Selection == '2':                                        use_file = "C:/CTS/Deacons.txt"                                        count_lines()                                        replace_string()                                        replace_filename()                                        write_to_file()                                        print "You may now call the pilot"                                        manage_lists()                                        Selection = raw_input("Select a number: ")                                                    elif Selection == "11":                        print "Manage The Bridge Nursery List"                        list_options()                        Selection = raw_input("Select a number: ")                        while Selection != "3":                                if Selection == '1':                                        os.popen3("notepad.exe C:/CTS/Nursery.txt")                                        manage_lists()                                          Selection = raw_input("Select a number: ")                                elif Selection == '2':                                        use_file = "C:/CTS/Nursery.txt"                                        count_lines()                                        replace_string()                                        replace_filename()                                        write_to_file()                                        print "You may now call the pilot"                                        manage_lists()                                        Selection = raw_input("Select a number: ")         print "Goodbye"        sys.exit()manage_lists()RunTree()  #Runs the whole script##############################################################################this code is for testing the engine behind this script#use_file = input("type a name: ")#print use_file#new_ver_from_file = len(open(use_file).readlines())#print new_ver_from_file#astring = '+(%S9)I(%S9,>,18,5010)V("C:/CTS/LIST.TXT",3,4,1,%S0,2,%S1,3,%S2,%S9)O(30)9,%S1W(4,V,5002)R(G1,%S2,20)I(%S2,=,1,5003)I(%S2,=,2,5004)I(%S2,=,3,5005)I(%S2,=," ",5006)'#new_string = re.sub('>,\d+,', '>,%s,' % new_ver_from_file, astring)#newest_string = re.sub('"C:/CTS/LIST.TXT",', '"%s",' % use_file, new_string)#print "Writing the CALLSTRING.TXT in order to start the Phone Tree. "#os.popen3("ren C:/CTS/CALLSTRING.TXT C:/CTS/CALLSTRING.BAK") may use this later for error checking#print newest_string#f = open("/home/james/Documents/CALLSTRING.TXT", "w")#f.write(newest_string)#f.close()