Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e9ba2e

Browse files
author
Siddharta Govindaraj
committed
Refactored printing into separate method
1 parent 070def0 commit 9e9ba2e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

stock_alerter/legacy.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ def __init__(self, autorun=True, exchange=None):
1212
self.exchange = exchange
1313
rule_1 = PriceRule("GOOG", lambda stock: stock.price > 10)
1414
rule_2 = PriceRule("AAPL", lambda stock: stock.price > 5)
15-
self.exchange["GOOG"].updated.connect(
16-
lambda stock: print(stock.symbol, stock.price) \
17-
if rule_1.matches(self.exchange) else None)
18-
self.exchange["AAPL"].updated.connect(
19-
lambda stock: print(stock.symbol, stock.price) \
20-
if rule_2.matches(self.exchange) else None)
15+
self.exchange["GOOG"].updated.connect(lambda stock: self.print_action(stock, rule_1))
16+
self.exchange["AAPL"].updated.connect(lambda stock: self.print_action(stock, rule_2))
2117
if autorun:
2218
self.run()
2319

20+
def print_action(self, stock, rule):
21+
print(stock.symbol, stock.price) \
22+
if rule.matches(self.exchange) else None
23+
2424
def do_updates(self, updates):
2525
for symbol, timestamp, price in updates:
2626
stock = self.exchange[symbol]

0 commit comments

Comments
 (0)