I am getting the data from websocket (ws://localhost:8080) and doing command line args with that. code mentioned below..
python datapy.py -i 127.0.0.1 -p 8080
from websocket import create_connection
#import ConfigParser
#from test import settings
import sys
import argparse
import socket
parser = argparse.ArgumentParser()
parser.add_argument('-i', dest='ip' , help='host name / IP')
parser.add_argument('-p', dest='port' , type=int, help='port')
parser.add_argument('-t', dest='time' , type=int, help='Time (in seconds) to keep reading data from websocket. After this process will be exit. Default value is 0. For 0 it will run infinitely')
parser.add_argument('-m', dest='msg' , type=int, help='Number of message. Process will exit after receiving Number of messages. Default is 0, means runs for ever.')
args = parser.parse_args()
print(args.ip)
#ws://%s:%s" % (args.ip,args.port)
url = "ws://%s:%s" % (args.ip,args.port)
ws = create_connection(url)
print "Receiving data from the socket..."
for each in ws:
result = ws.recv();
print "Received '%s'" % result
ws.close();
Console:
C:\Users\556718\Desktop\pythonprac>python datapy.py -i 127.0.0.1 -p 8080
127.0.0.1
Receiving data from the socket...
Received 'sound'
Received 'eokeoe'
Received 'mdmmd'
Received 'ssss'
Received 'tttt'
As mentioned in argparse, I want to pass -m and -t - like
python data.py -i 127.0.0.1 -p 8080 -m 5 --> It will limit to only 5 messages in the console..
python data.py -i 127.0.0.1 -p 8080 -t 120 --> Send me the messages until 120 seconds - after that exit ....
python data.py -i 127.0.0.1 -p 8080 -m 5 -t 120 --> for limiting to 120 seconds (2 minutes) and 5 messages - either of the condition
Can anyone help me in this