If you look closely at the code for nightservice.py that I mentioned yesterday in the post about 5 sample Twitter apps (and also posted the source code to Github), you’ll see that it is slightly different. Here was the original I wrote about back in May:

from datetime import *
answer()

if datetime.now().hour not in range(12,21) :
    if currentCall.initialText.find("@stratohelp") == -1:
        say("Our offices are currently closed. We will reply to your tweet as soon as we can but in the meantime, please visit our web site at www.tropo.com")

hangup()

And here is new version:

from datetime import *

if currentCall.initialText.find("@stratohelp") == -1:
    if datetime.now().hour not in range(12,21) :
        say("Our offices are currently closed. We will reply to your tweet as soon as we can but in the meantime, please visit our web site at www.tropo.com")

Two main differences:

1. You no longer need to include “answer()” and “hangup()”. It just made sense to make those defaults. You still can include them if you have some need to do so… for instance using “hangup()” if you want to do some post-call processing after a call is terminated… but you don’t need to do so.

2. Switched the order of the IF statements. My main reason for doing this was so that I could add an “else” statement so that the app performs some action during work hours. My personal interest was that from a demo point-of-view, it’s rather lame to tweet a message to a demo app and receive, well, nothing if it is during “work hours”. The resulting code looks like this:

from datetime import *

if currentCall.initialText.find("@stratohelp") == -1:
    if datetime.now().hour not in range(12,21) :
        say("Our offices are currently closed. We will reply to your tweet as soon as we can but in the meantime, please visit our web site at www.tropo.com")
    else:
        say("Our offices are open. We'll reply back to you soon.")

That’s why I made the changes to the code. Have fun with it… and if you build a cool Twitter app on Tropo please let me know and I’d be glad to feature it here in the blog.

Originally from Voxeo Blogs