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

Skip to content

Commit 7bd73f7

Browse files
author
Siddharta Govindaraj
committed
Legacy code that we will work on
1 parent b9160b4 commit 7bd73f7

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

stock_alerter/legacy.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from datetime import datetime
2+
3+
from .stock import Stock
4+
from .rule import PriceRule
5+
6+
7+
class AlertProcessor:
8+
def __init__(self):
9+
self.exchange = {"GOOG": Stock("GOOG"), "AAPL": Stock("AAPL")}
10+
rule_1 = PriceRule("GOOG", lambda stock: stock.price > 10)
11+
rule_2 = PriceRule("AAPL", lambda stock: stock.price > 5)
12+
self.exchange["GOOG"].updated.connect(
13+
lambda stock: print(stock.symbol, stock.price) \
14+
if rule_1.matches(self.exchange) else None)
15+
self.exchange["AAPL"].updated.connect(
16+
lambda stock: print(stock.symbol, stock.price) \
17+
if rule_2.matches(self.exchange) else None)
18+
updates = []
19+
with open("updates.csv", "r") as fp:
20+
for line in fp.readlines():
21+
symbol, timestamp, price = line.split(",")
22+
updates.append((symbol,
23+
datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S.%f"),
24+
int(price)))
25+
for symbol, timestamp, price in updates:
26+
stock = self.exchange[symbol]
27+
stock.update(timestamp, price)

updates.csv

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
GOOG,2014-02-11T14:10:22.13,5
2+
AAPL,2014-02-11T00:00:00.0,8
3+
GOOG,2014-02-11T14:11:22.13,3
4+
GOOG,2014-02-11T14:12:22.13,15
5+
AAPL,2014-02-11T00:00:00.0,10
6+
GOOG,2014-02-11T14:15:22.13,21

0 commit comments

Comments
 (0)