-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pubsub fuctionallity using a python script, meh
- Loading branch information
1 parent
ecc5eee
commit 1ff3b93
Showing
2 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#! /usr/bin/python | ||
import redis | ||
import time | ||
import random | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
r = redis.StrictRedis(host='localhost', port=6379, db=0) | ||
|
||
if (not (3 <= len(sys.argv) <= 4)) or (sys.argv[1] in ["-?", "-h", "--help"]): | ||
print "usage: %s <dehydrator_name> <channel> [Hz]" % sys.argv[0] | ||
exit() | ||
|
||
dehydrator_name = sys.argv[1] | ||
channel = sys.argv[2] | ||
if len(sys.argv) > 3: | ||
Hz = sys.argv[3] | ||
sleep_time = 1.0/Hz | ||
else: | ||
sleep_time = 1.0 | ||
|
||
print "Polling and Publishing (press Ctrl-C to quit)" | ||
user_notified = False | ||
while True: | ||
try: | ||
poll_result = r.execute_command("REDE.POLL", dehydrator_name) | ||
except: | ||
if not user_notified: | ||
print "an error occured in POLL, probably bad dehydrator name (this message will not be repeted)" | ||
user_notified = True | ||
else: | ||
for element in poll_result: | ||
poll_result = r.execute_command("PUBLISH", channel, element) | ||
time.sleep(sleep_time) |