Skip to content

Commit

Permalink
scheduling aync commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchir594 committed May 19, 2017
1 parent dd38047 commit ebdfd5c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 7 deletions.
12 changes: 12 additions & 0 deletions 334.py
@@ -0,0 +1,12 @@
class Solution(object):
def increasingTriplet(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
return 'executed?? from 334.py'

a = Solution()
#print a.increasingTriplet([5,4,4,4,5])
#print a.increasingTriplet([1,4,4,4,5])
print a.increasingTriplet([0,4,2,1,0,-1,-3])
14 changes: 10 additions & 4 deletions ActionsA/scheduler.py
@@ -1,6 +1,6 @@
# scheduler.py

from tasks import tiger, my_task, push
from tasks import tiger, my_task, push, execute
from tasktiger import Task
import json
import datetime
Expand All @@ -14,16 +14,22 @@ def message(**kwargs):
ref = ''
val = ''
text = ''
command = ''
if kwargs is not None:
for key, value in kwargs.iteritems():
if key in refs:
ref = key
val = value
if key == 'text':
text = value

task = Task(tiger, push, ([text]))
print task.delay(when=datetime.timedelta(**{ref: val}))
if key == 'command':
command = value
if text != '':
task = Task(tiger, push, ([text]))
print task.delay(when=datetime.timedelta(**{ref: val}))
if command != '':
task = Task(tiger, execute, ([command]))
print task.delay(when=datetime.timedelta(**{ref: val}))

def reminders(**kwargs):
freq = ['everyday']
Expand Down
9 changes: 8 additions & 1 deletion ActionsA/tasks.py
@@ -1,6 +1,7 @@
# tasks.py
from lib import tasktiger
from nlg.speak import say
import subprocess

tiger = tasktiger.TaskTiger()

Expand All @@ -10,7 +11,13 @@
def push(line):
print(line)
say(line)


@tiger.task()
def execute(command):
print(command)
listen = subprocess.Popen(command, shell=True)


def my_task(name):
print('Hello', name)
say('Hello '+name)
3 changes: 2 additions & 1 deletion Modules/MotivationBot/bot.py
Expand Up @@ -29,4 +29,5 @@ def lambda_function(a):
return ret


#scheduler.message(seconds=4, text='Nitesh is brilliant...')
#scheduler.message(seconds=4, text='Nitesh is brilliant...', command='python 334.py')
#scheduler.message(seconds=7, command='afplay ../Chained\ to\ the\ Rhythm.mp3')
24 changes: 23 additions & 1 deletion README.md
Expand Up @@ -2,6 +2,15 @@

If at first you don't succeed, we have a lot in common.

### Scheduling async commands with one line. Literally.

```
from ActionsA import scheduler
scheduler.message(seconds=7, command='afplay imagine.mp3')
scheduler.message(minutes=5, command='python 334.py &')
```

### Schedule async voice message with one line. Literally.

```
Expand All @@ -21,13 +30,26 @@ cd NatOS
sudo make
```

If you are running this on a Mac or any other Unix, please make sure your redis-server and queue-server is running. Open CLI, and run

```
redis-server
cd NatOS
python queue-server.py &
```

In Raspberry Pi, for some weird reason, even after adding queue-server into init.d, it still has to be manually started.

Do not forget to run redis-server and queue-server.

### Technical Documentation

Uses Redis and tasktiger as backend.

During make, redis-server and a queue for "tasks" is added to deamon for perceived seemless interaction. (Tasks = when to play, text to be played).

text-to-speech is powered by gttx for now.
text-to-speech is powered by omxplayer on raspberry pi.

-- more coming soon --

Expand Down
2 changes: 2 additions & 0 deletions mothership.py
Expand Up @@ -82,4 +82,6 @@ def maketest():
ret = nlqueen.extract('tell a joke')
speak.say(ret)

#maketest()

#mothercall()

0 comments on commit ebdfd5c

Please sign in to comment.