dwyl / hapi-socketio-redis-chat-example

:speech_balloon: Real-time Chat using Hapi.js + Socket.io + Redis Pub/Sub (example with tests!!)
GNU General Public License v2.0
364 stars 73 forks source link

Send chat message from command line #81

Open Jamesdwi opened 7 years ago

Jamesdwi commented 7 years ago

Wanted the ability to send messages from the command line, so wrote this little script. feel free to add to the project, the time stamp is screwed up, not sure what the fix is.

#!/usr/bin/python2
#
# talk to chat from the command line
#  by James Dickens 
#
import time
import redis
import sys
redis_host="192.168.1.42"

t = str(time.time()).replace('.','')
count =  len(sys.argv)
if count < 3:
    print "Usage: "
    print sys.argv[0], "username message"
    sys.exit()

r = redis.Redis(redis_host)
mess ='{"m":"%s","t":%s,"n":"%s"}'%(sys.argv[2],t,sys.argv[1])
r.publish("chat:messages:latest", mess)
nelsonic commented 7 years ago

@Jamesdwi Sweet Script! 😍