33 lines
718 B
Python
33 lines
718 B
Python
# 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())
|