-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcalcbench_listener.py
More file actions
69 lines (49 loc) · 1.78 KB
/
Copy pathcalcbench_listener.py
File metadata and controls
69 lines (49 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
"""
The `get_filing_standardized` function will get called every time a new filing is published.
Calcbench pushes messages onto the queue when data is available, typically a few minutes after the SEC publishes the data.
Messages will remain in the queue for seven days, if the listening process goes down you will receive the messages when it is started again.
If the `handle_filing` function throws an error the message will be pushed back on the queue to re-try.
`pip install calcbench-api-client[Listener]` to install the service bus dependencies.
"""
from pathlib import Path
import calcbench as cb
logger = cb.turn_on_logging()
# cb.set_credentials("andrew@calcbench.com", "not my real password")
columns = [
"preliminary",
"revision_number",
"period_start",
"period_end",
"date_reported",
"metric",
"value",
"calendar_year",
"calendar_period",
"fiscal_period",
"ticker",
"CIK",
"filing_type",
"date_downloaded",
]
output_file_name = Path.joinpath(Path.home(), "push_notification_data.csv")
def get_filing_standardized(filing: cb.Filing):
filing_data = filing.get_standardized_data()
logger.info(f"Found {filing_data.shape} for {filing.ticker}")
if filing_data.empty:
return
file_exists = Path(output_file_name).exists()
filing_data.reset_index()[columns].to_csv(
output_file_name,
index=False,
header=not file_exists,
mode="a" if file_exists else "w",
)
if __name__ == "__main__":
azure_service_bus_subscription = "andrew_test"
# talk to Calcbench to get a subscription
logger.info("Starting to handle filings")
cb.handle_filings(
handler=get_filing_standardized,
subscription_name=azure_service_bus_subscription,
)