Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API - Call from bash script #67

Open
Jbithell opened this issue May 27, 2016 · 4 comments
Open

API - Call from bash script #67

Jbithell opened this issue May 27, 2016 · 4 comments

Comments

@Jbithell
Copy link

Is there a simple way to call whitakers-words from a bash script, with parameters passed, and have only the output returned, instead of the welcome menu returned etc.

@mk270
Copy link
Owner

mk270 commented May 27, 2016

Yes - BTW, you've got some wrapped version of Words, right? What's it called again?

@Jbithell
Copy link
Author

Yes I do - it's sapiensoptio.com - and the intention is to move it to this script.

@chrisfair
Copy link

What I did was just provide the argument when I called it. The welcome menu does not show up when providing arguments. I made a prayer memorizing program years ago in python and that mechanism worked fine. I actually parsed the argument list and did a single word at a time for example:

words pater
words noster
words qui
words es

If the user selected more than one word for grammar.

Here is a link to the python code if you are interested.
def btnShowGrammarClick(self, event): # wxGlade: MyFrame.<event_handler>

    contentsOfSelection = self.txtDisplayPrayer.GetStringSelection()
    if contentsOfSelection != '':
        searchTerms = \
            self.Parser.scrubListOfPunctuation(contentsOfSelection.split(' '
                ))
    else:
        searchTerms = \
            self.Parser.scrubListOfPunctuation(self.txtDisplayPrayer.GetValue().split(' '
                ))
    operatingSystem = platform.system().lower()
    runCommandForGrammar = ''

    for searchTerm in searchTerms:
        if searchTerm != '':

            currentDirectory = self.getCurrentFileLocation()

            newDirectory = os.path.join(currentDirectory,
                    'LatinEngines')
            if operatingSystem.find('linux') != -1:
                newDirectory = os.path.join(newDirectory, 'Linux')
                runCommandForGrammar = './words'
            if operatingSystem.find('windows') != -1\
                 or operatingSystem.find('microsoft') != -1:
                newDirectory = os.path.join(newDirectory, 'Windows')
                runCommandForGrammar = 'words.exe'
            if operatingSystem.find('darwin') != -1:
                newDirectory.path.join(newDirectory, 'Linux')
                runCommandForGrammar = './words'
            os.chdir(newDirectory)

            try:
                myOutput = subprocess.Popen([runCommandForGrammar,
                        self.Parser.unicodeToAscii(searchTerm)],
                        stdout=subprocess.PIPE).communicate()[0]
            except:
                myOutput = 'An error has occured try again.'
            os.chdir(currentDirectory)
            self.txtDisplayInfo.SetValue((self.txtDisplayInfo.GetValue()
                     + '''

''' + myOutput).strip('\n'))

    event.Skip()

@chrisfair
Copy link

btw I had just started learning to program back then and am naturally embarrassed by the code specifically checking for the os on every loop through was wasteful. The program worked/works well enough though. The output was the full grammar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants