Skip to content
Browse files

updates consume.py and produce.py to use the new streaming API.

  • Loading branch information...
1 parent aee6ad5 commit e2b631447fb1fe9da4d3d65246ef9bcfa0dd3052 @aturley aturley committed Oct 8, 2011
Showing with 16 additions and 14 deletions.
  1. +7 −5 consume.py
  2. +9 −9 produce.py
View
12 consume.py
@@ -10,9 +10,9 @@ def usage(script_name):
print "Use '%s [method] --help' for a method's usage and options."%(script_name)
sys.exit()
-def consume(hostname, api_key, swarm_id):
+def consume(hostname, api_key, swarm_id, resource_id):
conn = httplib.HTTPConnection(hostname)
- conn.request("GET", "/stream?swarm_id=%s"%(swarm_id), None, {"x-bugswarmapikey":api_key, "connection":"keep-alive"})
+ conn.request("GET", "/stream?swarm_id=%s&resouce_id=%s"%(swarm_id, resource_id), None, {"x-bugswarmapikey":api_key, "connection":"keep-alive"})
resp = conn.getresponse()
while(1):
txt = resp.read(1)
@@ -26,15 +26,17 @@ def main():
if len(sys.argv) == 1:
usage(sys.argv[0])
elif sys.argv[1] == "consume":
- opt_usage = "usage: \n %s SWARM_ID"%(sys.argv[1])
+ opt_usage = "usage: \n %s SWARM_ID RESOURCE_ID"%(sys.argv[1])
opt_usage += "\n\n *SWARM_ID: The ID of the Swarm to consume. This is a really long, unique identifier."
+ opt_usage += "\n\n *RESOURCE_ID: The ID of the Resource to use for consumption. This is another really long, unique identifier."
parser = OptionParser(usage = opt_usage)
(options, args) = parser.parse_args()
- if len(args) != 2:
+ if len(args) != 3:
print "Invalid number of args. See --help for correct usage."
sys.exit()
swarm_id = args[1]
- consume(server_info["hostname"], keys["consumer"], swarm_id)
+ resource_id = args[2]
+ consume(server_info["hostname"], keys["consumer"], swarm_id, resource_id)
else:
usage(sys.argv[0])
main()
View
18 produce.py
@@ -18,11 +18,13 @@ def signal_handler(signal, frame):
print 'Http connection closed.'
sys.exit(0)
-def produce(hostname, api_key, swarm_id, resource_id, feed_name):
+def produce(hostname, api_key, swarm_id, resource_id):
global conn
conn = httplib.HTTPConnection(hostname)
- sel = "/resources/%s/feeds/%s?swarm_id=%s"%(resource_id, feed_name, swarm_id)
- conn.putrequest("PUT", sel)
+ sel = "/stream?swarm_id=%s&resource_id=%s"%(swarm_id, resource_id)
+ print sel
+ print api_key
+ conn.putrequest("POST", sel)
conn.putheader("x-bugswarmapikey", api_key)
conn.putheader("transfer-encoding", "chunked")
conn.endheaders()
@@ -55,20 +57,18 @@ def main():
usage(sys.argv[0])
elif sys.argv[1] == "produce":
signal.signal(signal.SIGINT, signal_handler)
- opt_usage = "usage: \n DATA | python %s SWARM_ID RESOURCE_ID FEED_NAME"%(sys.argv[1])
+ opt_usage = "usage: \n DATA | python %s SWARM_ID RESOURCE_ID"%(sys.argv[1])
opt_usage += "\n\n *DATA: The data to produce in the Feed. Valid forms; \"echo 'data here'\", \"cat <filename>\"." \
+"\n *SWARM_ID: The ID of the Swarm to produce to. This is a really long, unique identifier." \
- +"\n *RESOURCE_ID: The ID of the Resource to produce with. This is the \"id\" field in the resource's listed JSON." \
- +"\n *FEED_NAME: The name of the Feed you are producing."
+ +"\n *RESOURCE_ID: The ID of the Resource to produce with. This is the \"id\" field in the resource's listed JSON."
parser = OptionParser(usage = opt_usage)
(options, args) = parser.parse_args()
- if len(args) != 4:
+ if len(args) != 3:
print "Invalid number of args. See --help for correct usage."
sys.exit()
swarm_id = args[1]
resource_id = args[2]
- feed_name = args[3]
- produce(server_info["hostname"], keys["producer"], swarm_id, resource_id, feed_name)
+ produce(server_info["hostname"], keys['master'], swarm_id, resource_id)
else:
usage(sys.argv[0])

0 comments on commit e2b6314

Please sign in to comment.
Something went wrong with that request. Please try again.