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

Skip to content

Commit 659ce0c

Browse files
author
Siddharta Govindaraj
committed
Package level doctests
1 parent 01ac627 commit 659ce0c

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

stock_alerter/__init__.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
45+
if __name__ == "__main__":
46+
import doctest
47+
doctest.testmod()

0 commit comments

Comments
 (0)