Filling in the python weather update client, too.

cat-town
Dan Buch 13 years ago
parent afe51e924f
commit 31f56408d7

@ -0,0 +1,32 @@
# vim:fileencoding=utf-8
from __future__ import print_function
import sys
import zmq
def main(sysargs=sys.argv[:]):
context = zmq.Context()
socket = context.socket(zmq.SUB)
print("Collecting updates from weather server…")
socket.connect("tcp://localhost:5556")
target_zipcode = sysargs[1] if len(sysargs) > 1 else '10001'
socket.setsockopt(zmq.SUBSCRIBE, target_zipcode)
total_temp = 0
for update_nbr in range(100):
string = socket.recv()
total_temp += int(string.split()[1])
print("Average temperature for zipcode '{}' was {}F".format(
target_zipcode, total_temp / update_nbr
))
return 0
if __name__ == '__main__':
sys.exit(main())
Loading…
Cancel
Save