Filling in the python weather update client, too.

This commit is contained in:
Dan Buch 2012-03-17 10:33:29 -04:00
parent afe51e924f
commit 31f56408d7

32
zeromq/wuclient.py Normal file
View File

@ -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())