Hi thanks for the suggestions. Sorry for not responding sooner. I figured a
way of working and been working abroad for a few days...) so I haven't
tried your suggestions.

What worked for me was I wrote a service that returned the contents of a
table that define the bot commands and called it using requests in Python.
The response contains the data as json. Then I connect to my Slack room and
listen for commands that invoke my bot. the bot responds according to the
commands received and looked-up responses read from the DB.

I suspect using the DAL directly could have achieved the same goal and also
retain the DB connection to store stuff too if required - but right now I
don't need to do that.

Happy to share my code if you have a similar need to drive a Slack bot.



On 2 March 2016 at 20:42, Ian Ryder <[email protected]> wrote:

> Sounds like you just need some sort of never ending loop (obviously you
> can put checks in the loop for stop requests and whatever other complexity
> you like / need).
>
> You can pass arguments on the python command line. So for example you
> could do something like:
>
> python web2py.py -S your_app -M -A 1 run_my_loop
>
> In the example, 1 is the user record to use and then:
>
> if sys.argv[2] == 'run_my_loop':
>     this_user = db_auth.auth_user[sys.argv[1]]
>
>
> if not this_user:
>     raise Exception('...')
> auth.login_bare(this_user.email, this_user.password)
> run_my_loop()
>
>
>
> On Monday, 29 February 2016 10:36:23 UTC+1, Paul Gerrard wrote:
>>
>> I have written some Python code to act as a chatbot working with Slack.
>> All looks good so far. I could add it as a service to /etc/init.d etc and
>> make it work at startup. However...
>>
>> I want to enhance the service to access my MySQL database using the
>> Web2py DAL. Now, I created a webservice to do this - but of course when run
>> the Apache server eventually times out and I get a 500 error. Is there a
>> simple way of creating a permanently running service that can access
>> models, the DAL etc?
>>
>> Now, in the web2py directory, I guess I could run:
>>
>> python -M -S myapp/controller/function
>>
>> But I need to add credentials to the command too? How do I do this?
>>
>> Assuming there's a way to provide credentials through the shell, would a
>> permanently running service created this way cause any other issues?
>>
>> thanks, Paul.
>>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/XEbLuixLJUY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to