, .
, , . next .
offer_comparer.send() offer1 offer2 offers .
, .
import time
def compare_offers():
count_max = 10
while True:
count1 = 0
count2 = 0
while count1 < count_max and count2 < count_max:
offers = yield
offer1, offer2 = offers[0], offers[1]
if offer1 > offer2:
count1 += 1
print("Store1 has the better deal")
if count1 == count_max:
print("go ahead and buy from store1")
elif offer2 > offer1:
count2 += 1
print("Store2 has the better deal")
if count2 == count_max:
print("go buy this from store2")
offer_comparer = compare_offers()
next(offer_comparer)
def testing():
stores = {'lastUpdateId': 202588846,
'store1': [['24.43000000', '0.00606000'],
['24.42000000', '14.76000000'],
['24.39000000', '2.65760000'],
['24.38000000', '29.59867000'],
['24.35000000', '7.71171000']],
'store2': [['24.47000000', '0.22601000'],
['24.52000000', '0.72000000'],
['24.53000000', '3.28839000'],
['24.54000000', '5.63226000'],
['24.55000000', '20.64052000']]}
firststore = [float(i[1]) for i in stores['store1']]
secondstore = [float(e[1]) for e in stores['store2']]
offer1 = sum(firststore[:3])
offer2 = sum(secondstore[:3])
offer_comparer.send((offer1, offer2))
i = 0
while True:
i += 1
testing()
time.sleep(2)