[zeromq-dev] Weather update client in Python incorrect

Pieter Hintjens ph at imatix.com
Thu Jun 7 12:26:14 CEST 2012


Hi Kelvin,

Thanks, if you send a pull request to fix this we'll merge it in.

-Pieter

On Wed, Jun 6, 2012 at 9:59 PM, Kelvin Ishigo <kkishigo at directv.com> wrote:
> temperature is unbound.
>
> Corrected:
>
> #! /usr/bin/python
>
> #
> # Weather update client
> # Connects SUB socket to tcp://localhost:5556
> # Collects weather updates and finds avg temp in zipcode
> #
>
> import sys
> import zmq
>
> # Socket to talk to server
> context = zmq.Context()
> socket = context.socket(zmq.SUB)
>
> print "weather_client"
> socket.connect ("tcp://localhost:5556")
>
> # Subscribe to zipcode, default is NYC, 10001
> zip_filter = sys.argv[1] if len(sys.argv) > 1 else "10001"
> socket.setsockopt(zmq.SUBSCRIBE, zip_filter)
>
> # Process 5 updates
> total_temp = 0
> for update_nbr in range (5):
>    string = socket.recv()
>    stuff = string.split()
>    temperature = stuff[1]
>    print 'weather_client:', string
>    total_temp += int(temperature)
>
> print "Average temperature for zipcode '%s' was %dF" % (zip_filter, total_temp /
> update_nbr)
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>



More information about the zeromq-dev mailing list