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

Skip to content

Commit fbf30bf

Browse files
author
Siddharta Govindaraj
committed
Doctests moved to a separate readme.txt file
1 parent 659ce0c commit fbf30bf

File tree

2 files changed

+42
-45
lines changed

2 files changed

+42
-45
lines changed

stock_alerter/__init__.py

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,3 @@
1-
r"""
2-
The stock_alerter module allows you to setup rules and get alerted when
3-
those rules are met.
4-
5-
>>> from datetime import datetime
6-
7-
First, we need to setup an exchange which contains all the stocks that
8-
are going to be processed. A simple dictionary will do.
9-
10-
>>> from stock_alerter.stock import Stock
11-
>>> exchange = {"GOOG": Stock("GOOG"), "AAPL": Stock("AAPL")}
12-
13-
Next, we configure the reader. The reader is the source from where the
14-
stock updates are coming. The module provides two readers out of the
15-
box: A FileReader for reading updates from a comma separated file,
16-
and a ListReader to get updates from a list. You can create other
17-
readers, such as an HTTPReader to get updates from a remote server.
18-
Here we create a simple ListReader by passing in a list of 3-tuples
19-
containing the stock symbol, timestamp and price.
20-
21-
>>> from stock_alerter.reader import ListReader
22-
>>> reader = ListReader([("GOOG", datetime(2014, 2, 8), 5)])
23-
24-
Next, we setup an Alert. We give it a rule, and an action to be taken
25-
when the rule is fired.
26-
27-
>>> from stock_alerter.alert import Alert
28-
>>> from stock_alerter.rule import PriceRule
29-
>>> from stock_alerter.action import PrintAction
30-
>>> alert = Alert("GOOG > $3", PriceRule("GOOG", lambda s: s.price > 3),\
31-
... PrintAction())
32-
33-
Connect the alert to the exchange
34-
35-
>>> alert.connect(exchange)
36-
37-
Now that everything is setup, we can start processing the updates
38-
39-
>>> from stock_alerter.processor import Processor
40-
>>> processor = Processor(reader, exchange)
41-
>>> processor.process()
42-
GOOG > $3
43-
"""
44-
451
if __name__ == "__main__":
462
import doctest
47-
doctest.testmod()
3+
doctest.testfile("readme.txt")

stock_alerter/readme.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
The stock_alerter module allows you to setup rules and get alerted when
2+
those rules are met.
3+
4+
>>> from datetime import datetime
5+
6+
First, we need to setup an exchange which contains all the stocks that
7+
are going to be processed. A simple dictionary will do.
8+
9+
>>> from stock_alerter.stock import Stock
10+
>>> exchange = {"GOOG": Stock("GOOG"), "AAPL": Stock("AAPL")}
11+
12+
Next, we configure the reader. The reader is the source from where the
13+
stock updates are coming. The module provides two readers out of the
14+
box: A FileReader for reading updates from a comma separated file,
15+
and a ListReader to get updates from a list. You can create other
16+
readers, such as an HTTPReader to get updates from a remote server.
17+
Here we create a simple ListReader by passing in a list of 3-tuples
18+
containing the stock symbol, timestamp and price.
19+
20+
>>> from stock_alerter.reader import ListReader
21+
>>> reader = ListReader([("GOOG", datetime(2014, 2, 8), 5)])
22+
23+
Next, we setup an Alert. We give it a rule, and an action to be taken
24+
when the rule is fired.
25+
26+
>>> from stock_alerter.alert import Alert
27+
>>> from stock_alerter.rule import PriceRule
28+
>>> from stock_alerter.action import PrintAction
29+
>>> alert = Alert("GOOG > $3", PriceRule("GOOG", lambda s: s.price > 3),\
30+
... PrintAction())
31+
32+
Connect the alert to the exchange
33+
34+
>>> alert.connect(exchange)
35+
36+
Now that everything is setup, we can start processing the updates
37+
38+
>>> from stock_alerter.processor import Processor
39+
>>> processor = Processor(reader, exchange)
40+
>>> processor.process()
41+
GOOG > $3

0 commit comments

Comments
 (0)