You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
box-o-sand/zeromq/wuclient.py

33 lines
718 B

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