earningscall 0.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- earningscall/__init__.py +2 -0
- earningscall/api.py +67 -0
- earningscall/company.py +51 -0
- earningscall/errors.py +25 -0
- earningscall/event.py +28 -0
- earningscall/exports.py +17 -0
- earningscall/sectors.py +234 -0
- earningscall/symbols.py +226 -0
- earningscall/transcript.py +14 -0
- earningscall/utils.py +15 -0
- earningscall-0.0.4.dist-info/METADATA +101 -0
- earningscall-0.0.4.dist-info/RECORD +14 -0
- earningscall-0.0.4.dist-info/WHEEL +4 -0
- earningscall-0.0.4.dist-info/licenses/LICENSE +21 -0
earningscall/__init__.py
ADDED
earningscall/api.py
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
import logging
|
2
|
+
import os
|
3
|
+
from typing import Optional
|
4
|
+
|
5
|
+
import requests
|
6
|
+
|
7
|
+
|
8
|
+
log = logging.getLogger(__file__)
|
9
|
+
|
10
|
+
DOMAIN = os.environ.get("ECALL_DOMAIN", "earningscall.biz")
|
11
|
+
API_BASE = f"https://v2.api.{DOMAIN}"
|
12
|
+
api_key: Optional[str] = None
|
13
|
+
|
14
|
+
|
15
|
+
def get_api_key():
|
16
|
+
global api_key
|
17
|
+
if api_key is None:
|
18
|
+
return os.environ.get("ECALL_API_KEY", "demo")
|
19
|
+
return api_key
|
20
|
+
|
21
|
+
|
22
|
+
def get_events(exchange: str,
|
23
|
+
symbol: str):
|
24
|
+
|
25
|
+
log.debug(f"get_events exchange: {exchange} symbol: {symbol}")
|
26
|
+
params = {
|
27
|
+
"apikey": get_api_key(),
|
28
|
+
"exchange": exchange,
|
29
|
+
"symbol": symbol,
|
30
|
+
}
|
31
|
+
response = requests.get(f"{API_BASE}/events", params=params)
|
32
|
+
if response.status_code != 200:
|
33
|
+
return None
|
34
|
+
return response.json()
|
35
|
+
|
36
|
+
|
37
|
+
def get_transcript(exchange: str,
|
38
|
+
symbol: str,
|
39
|
+
year: int,
|
40
|
+
quarter: int) -> Optional[str]:
|
41
|
+
|
42
|
+
log.debug(f"get_transcript year: {year} quarter: {quarter}")
|
43
|
+
params = {
|
44
|
+
"apikey": "demo",
|
45
|
+
"exchange": exchange,
|
46
|
+
"symbol": symbol,
|
47
|
+
"year": str(year),
|
48
|
+
"quarter": str(quarter),
|
49
|
+
}
|
50
|
+
response = requests.get(f"{API_BASE}/transcript", params=params)
|
51
|
+
if response.status_code != 200:
|
52
|
+
return None
|
53
|
+
return response.json()
|
54
|
+
|
55
|
+
|
56
|
+
def get_symbols_v1():
|
57
|
+
response = requests.get(f"{API_BASE}/symbols.txt")
|
58
|
+
if response.status_code != 200:
|
59
|
+
return None
|
60
|
+
return response.text
|
61
|
+
|
62
|
+
|
63
|
+
def get_symbols_v2():
|
64
|
+
response = requests.get(f"{API_BASE}/symbols-v2.txt")
|
65
|
+
if response.status_code != 200:
|
66
|
+
return None
|
67
|
+
return response.text
|
earningscall/company.py
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
import logging
|
2
|
+
from typing import Optional
|
3
|
+
|
4
|
+
from earningscall import api
|
5
|
+
from earningscall.event import EarningsEvent
|
6
|
+
from earningscall.symbols import CompanyInfo
|
7
|
+
from earningscall.transcript import Transcript
|
8
|
+
|
9
|
+
log = logging.getLogger(__file__)
|
10
|
+
|
11
|
+
|
12
|
+
class Company:
|
13
|
+
|
14
|
+
company_info: CompanyInfo
|
15
|
+
name: str
|
16
|
+
_events: [EarningsEvent]
|
17
|
+
|
18
|
+
def __init__(self, company_info):
|
19
|
+
self.company_info = company_info
|
20
|
+
self.name = company_info.name
|
21
|
+
self._events = None
|
22
|
+
|
23
|
+
def __str__(self):
|
24
|
+
return str(self.name)
|
25
|
+
|
26
|
+
def name(self) -> str:
|
27
|
+
return self.company_info.name
|
28
|
+
|
29
|
+
def _get_events(self):
|
30
|
+
raw_response = api.get_events(self.company_info.exchange, self.company_info.symbol)
|
31
|
+
return [EarningsEvent.from_dict(event) for event in raw_response["events"]]
|
32
|
+
|
33
|
+
def events(self) -> [EarningsEvent]:
|
34
|
+
if not self._events:
|
35
|
+
self._events = self._get_events()
|
36
|
+
return self._events
|
37
|
+
|
38
|
+
def get_transcript(self,
|
39
|
+
year: Optional[int] = None,
|
40
|
+
quarter: Optional[int] = None,
|
41
|
+
event: Optional[EarningsEvent] = None) -> Optional[Transcript]:
|
42
|
+
|
43
|
+
if (not year or not quarter) and event:
|
44
|
+
year = event.year
|
45
|
+
quarter = event.quarter
|
46
|
+
elif (not year or not quarter) and not event:
|
47
|
+
raise ValueError("Must specify either event or year and quarter")
|
48
|
+
resp = api.get_transcript(self.company_info.exchange, self.company_info.symbol, year, quarter)
|
49
|
+
if not resp:
|
50
|
+
return None
|
51
|
+
return Transcript.from_dict(resp)
|
earningscall/errors.py
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
class BaseError(RuntimeError):
|
4
|
+
"""
|
5
|
+
Base error
|
6
|
+
"""
|
7
|
+
|
8
|
+
def __init__(self, msg=None):
|
9
|
+
self.msg = msg
|
10
|
+
|
11
|
+
def __str__(self):
|
12
|
+
if self.msg:
|
13
|
+
return str(self.msg)
|
14
|
+
return ""
|
15
|
+
|
16
|
+
|
17
|
+
class ClientError(BaseError):
|
18
|
+
"""
|
19
|
+
Used to return 4XX errors.
|
20
|
+
"""
|
21
|
+
status: int = 400 # https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400
|
22
|
+
|
23
|
+
|
24
|
+
class MissingApiKeyError(ClientError):
|
25
|
+
pass
|
earningscall/event.py
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
import logging
|
2
|
+
from dataclasses import dataclass, field
|
3
|
+
from datetime import datetime
|
4
|
+
from typing import Optional
|
5
|
+
|
6
|
+
from dataclasses_json import config
|
7
|
+
from dataclasses_json import dataclass_json
|
8
|
+
from marshmallow import fields
|
9
|
+
|
10
|
+
log = logging.getLogger(__file__)
|
11
|
+
|
12
|
+
|
13
|
+
@dataclass_json
|
14
|
+
@dataclass
|
15
|
+
class EarningsEvent:
|
16
|
+
"""
|
17
|
+
EarningsEvent
|
18
|
+
"""
|
19
|
+
year: int
|
20
|
+
quarter: int
|
21
|
+
conference_date: Optional[datetime] = field(
|
22
|
+
default=None,
|
23
|
+
metadata=config(
|
24
|
+
encoder=lambda date: date.isoformat() if date else None,
|
25
|
+
decoder=lambda date: datetime.fromisoformat(date) if date else None,
|
26
|
+
mm_field=fields.DateTime(format="iso")
|
27
|
+
)
|
28
|
+
)
|
earningscall/exports.py
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
from earningscall.symbols import get_symbols
|
2
|
+
|
3
|
+
from earningscall.company import Company
|
4
|
+
|
5
|
+
|
6
|
+
def get_company(symbol: str) -> Company:
|
7
|
+
return Company(company_info=get_symbols().lookup_company(symbol))
|
8
|
+
|
9
|
+
|
10
|
+
def get_all_companies() -> [Company]:
|
11
|
+
for company_info in get_symbols().get_all():
|
12
|
+
yield Company(company_info=company_info)
|
13
|
+
|
14
|
+
|
15
|
+
def get_sp500_companies() -> [Company]:
|
16
|
+
for company_info in get_symbols().get_all():
|
17
|
+
yield Company(company_info=company_info)
|
earningscall/sectors.py
ADDED
@@ -0,0 +1,234 @@
|
|
1
|
+
import json
|
2
|
+
import logging
|
3
|
+
|
4
|
+
|
5
|
+
log = logging.getLogger(__file__)
|
6
|
+
sectors_file_name = "sectors.json"
|
7
|
+
|
8
|
+
|
9
|
+
SECTORS_IN_ORDER = [
|
10
|
+
'Basic Materials',
|
11
|
+
'Communication Services',
|
12
|
+
'Consumer Cyclical',
|
13
|
+
'Consumer Defensive',
|
14
|
+
'Energy',
|
15
|
+
'Financial Services',
|
16
|
+
'Healthcare',
|
17
|
+
'Industrials',
|
18
|
+
'Real Estate',
|
19
|
+
'Technology',
|
20
|
+
'Utilities'
|
21
|
+
]
|
22
|
+
|
23
|
+
|
24
|
+
INDUSTRIES_IN_ORDER = [
|
25
|
+
'Advertising Agencies',
|
26
|
+
'Aerospace & Defense',
|
27
|
+
'Agricultural Inputs',
|
28
|
+
'Airlines',
|
29
|
+
'Airports & Air Services',
|
30
|
+
'Aluminum',
|
31
|
+
'Apparel Manufacturing',
|
32
|
+
'Apparel Retail',
|
33
|
+
'Asset Management',
|
34
|
+
'Auto & Truck Dealerships',
|
35
|
+
'Auto Manufacturers',
|
36
|
+
'Auto Parts',
|
37
|
+
'Banks - Diversified',
|
38
|
+
'Banks - Regional',
|
39
|
+
'Beverages - Brewers',
|
40
|
+
'Beverages - Non-Alcoholic',
|
41
|
+
'Beverages - Wineries & Distilleries',
|
42
|
+
'Biotechnology',
|
43
|
+
'Broadcasting',
|
44
|
+
'Building Materials',
|
45
|
+
'Building Products & Equipment',
|
46
|
+
'Business Equipment & Supplies',
|
47
|
+
'Capital Markets',
|
48
|
+
'Chemicals',
|
49
|
+
'Coking Coal',
|
50
|
+
'Communication Equipment',
|
51
|
+
'Computer Hardware',
|
52
|
+
'Confectioners',
|
53
|
+
'Conglomerates',
|
54
|
+
'Consulting Services',
|
55
|
+
'Consumer Electronics',
|
56
|
+
'Copper',
|
57
|
+
'Credit Services',
|
58
|
+
'Department Stores',
|
59
|
+
'Diagnostics & Research',
|
60
|
+
'Discount Stores',
|
61
|
+
'Drug Manufacturers - General',
|
62
|
+
'Drug Manufacturers - Specialty & Generic',
|
63
|
+
'Education & Training Services',
|
64
|
+
'Electrical Equipment & Parts',
|
65
|
+
'Electronic Components',
|
66
|
+
'Electronic Gaming & Multimedia',
|
67
|
+
'Electronics & Computer Distribution',
|
68
|
+
'Engineering & Construction',
|
69
|
+
'Entertainment',
|
70
|
+
'Farm & Heavy Construction Machinery',
|
71
|
+
'Farm Products',
|
72
|
+
'Financial Conglomerates',
|
73
|
+
'Financial Data & Stock Exchanges',
|
74
|
+
'Food Distribution',
|
75
|
+
'Footwear & Accessories',
|
76
|
+
'Furnishings, Fixtures & Appliances',
|
77
|
+
'Gambling',
|
78
|
+
'Gold',
|
79
|
+
'Grocery Stores',
|
80
|
+
'Health Information Services',
|
81
|
+
'Healthcare Plans',
|
82
|
+
'Home Improvement Retail',
|
83
|
+
'Household & Personal Products',
|
84
|
+
'Industrial Distribution',
|
85
|
+
'Information Technology Services',
|
86
|
+
'Infrastructure Operations',
|
87
|
+
'Insurance - Diversified',
|
88
|
+
'Insurance - Life',
|
89
|
+
'Insurance - Property & Casualty',
|
90
|
+
'Insurance - Reinsurance',
|
91
|
+
'Insurance - Specialty',
|
92
|
+
'Insurance Brokers',
|
93
|
+
'Integrated Freight & Logistics',
|
94
|
+
'Internet Content & Information',
|
95
|
+
'Internet Retail',
|
96
|
+
'Leisure',
|
97
|
+
'Lodging',
|
98
|
+
'Lumber & Wood Production',
|
99
|
+
'Luxury Goods',
|
100
|
+
'Marine Shipping',
|
101
|
+
'Medical Care Facilities',
|
102
|
+
'Medical Devices',
|
103
|
+
'Medical Distribution',
|
104
|
+
'Medical Instruments & Supplies',
|
105
|
+
'Metal Fabrication',
|
106
|
+
'Mortgage Finance',
|
107
|
+
'Oil & Gas Drilling',
|
108
|
+
'Oil & Gas E&P',
|
109
|
+
'Oil & Gas Equipment & Services',
|
110
|
+
'Oil & Gas Integrated',
|
111
|
+
'Oil & Gas Midstream',
|
112
|
+
'Oil & Gas Refining & Marketing',
|
113
|
+
'Other Industrial Metals & Mining',
|
114
|
+
'Other Precious Metals & Mining',
|
115
|
+
'Packaged Foods',
|
116
|
+
'Packaging & Containers',
|
117
|
+
'Paper & Paper Products',
|
118
|
+
'Personal Services',
|
119
|
+
'Pharmaceutical Retailers',
|
120
|
+
'Pollution & Treatment Controls',
|
121
|
+
'Publishing',
|
122
|
+
'REIT - Diversified',
|
123
|
+
'REIT - Healthcare Facilities',
|
124
|
+
'REIT - Hotel & Motel',
|
125
|
+
'REIT - Industrial',
|
126
|
+
'REIT - Mortgage',
|
127
|
+
'REIT - Office',
|
128
|
+
'REIT - Residential',
|
129
|
+
'REIT - Retail',
|
130
|
+
'REIT - Specialty',
|
131
|
+
'Railroads',
|
132
|
+
'Real Estate - Development',
|
133
|
+
'Real Estate - Diversified',
|
134
|
+
'Real Estate Services',
|
135
|
+
'Recreational Vehicles',
|
136
|
+
'Rental & Leasing Services',
|
137
|
+
'Residential Construction',
|
138
|
+
'Resorts & Casinos',
|
139
|
+
'Restaurants',
|
140
|
+
'Scientific & Technical Instruments',
|
141
|
+
'Security & Protection Services',
|
142
|
+
'Semiconductor Equipment & Materials',
|
143
|
+
'Semiconductors',
|
144
|
+
'Shell Companies',
|
145
|
+
'Silver',
|
146
|
+
'Software - Application',
|
147
|
+
'Software - Infrastructure',
|
148
|
+
'Solar',
|
149
|
+
'Specialty Business Services',
|
150
|
+
'Specialty Chemicals',
|
151
|
+
'Specialty Industrial Machinery',
|
152
|
+
'Specialty Retail',
|
153
|
+
'Staffing & Employment Services',
|
154
|
+
'Steel',
|
155
|
+
'Telecom Services',
|
156
|
+
'Textile Manufacturing',
|
157
|
+
'Thermal Coal',
|
158
|
+
'Tobacco',
|
159
|
+
'Tools & Accessories',
|
160
|
+
'Travel Services',
|
161
|
+
'Trucking',
|
162
|
+
'Uranium',
|
163
|
+
'Utilities - Diversified',
|
164
|
+
'Utilities - Independent Power Producers',
|
165
|
+
'Utilities - Regulated Electric',
|
166
|
+
'Utilities - Regulated Gas',
|
167
|
+
'Utilities - Regulated Water',
|
168
|
+
'Utilities - Renewable',
|
169
|
+
'Waste Management'
|
170
|
+
]
|
171
|
+
|
172
|
+
|
173
|
+
def sector_to_index(_sector: str) -> int:
|
174
|
+
try:
|
175
|
+
return SECTORS_IN_ORDER.index(_sector)
|
176
|
+
except ValueError:
|
177
|
+
return -1
|
178
|
+
|
179
|
+
|
180
|
+
def index_to_sector(_index: int) -> str:
|
181
|
+
if _index == -1:
|
182
|
+
return "UNKNOWN"
|
183
|
+
return SECTORS_IN_ORDER[_index]
|
184
|
+
|
185
|
+
|
186
|
+
def index_to_industry(_index: int) -> str:
|
187
|
+
if _index == -1:
|
188
|
+
return "UNKNOWN"
|
189
|
+
return INDUSTRIES_IN_ORDER[_index]
|
190
|
+
|
191
|
+
|
192
|
+
def industry_to_index(_industry: str) -> int:
|
193
|
+
try:
|
194
|
+
return INDUSTRIES_IN_ORDER.index(_industry)
|
195
|
+
except ValueError:
|
196
|
+
return -1
|
197
|
+
|
198
|
+
|
199
|
+
class Sectors:
|
200
|
+
|
201
|
+
def __init__(self,
|
202
|
+
sectors: set = None,
|
203
|
+
industries: set = None):
|
204
|
+
if sectors:
|
205
|
+
self.sectors = sectors
|
206
|
+
else:
|
207
|
+
self.sectors = set()
|
208
|
+
if industries:
|
209
|
+
self.industries = industries
|
210
|
+
else:
|
211
|
+
self.industries = set()
|
212
|
+
|
213
|
+
def add_sector(self, sector: str):
|
214
|
+
if sector is not None:
|
215
|
+
self.sectors.add(sector)
|
216
|
+
|
217
|
+
def add_industry(self, industry: str):
|
218
|
+
if industry is not None:
|
219
|
+
self.industries.add(industry)
|
220
|
+
|
221
|
+
def to_dicts(self) -> {}:
|
222
|
+
return {
|
223
|
+
"sectors": list(self.sectors),
|
224
|
+
"industries": list(self.industries),
|
225
|
+
}
|
226
|
+
|
227
|
+
def to_json(self) -> str:
|
228
|
+
return json.dumps(self.to_dicts())
|
229
|
+
|
230
|
+
@staticmethod
|
231
|
+
def from_json(json_str):
|
232
|
+
data = json.loads(json_str)
|
233
|
+
return Sectors(set(data["sectors"]), set(data["industries"]))
|
234
|
+
|
earningscall/symbols.py
ADDED
@@ -0,0 +1,226 @@
|
|
1
|
+
import json
|
2
|
+
import logging
|
3
|
+
import re
|
4
|
+
from collections import defaultdict
|
5
|
+
from typing import Optional
|
6
|
+
|
7
|
+
from earningscall.api import get_symbols_v2
|
8
|
+
from earningscall.sectors import sector_to_index, industry_to_index, index_to_sector, index_to_industry
|
9
|
+
|
10
|
+
# WARNING: Add new indexes to the *END* of this list
|
11
|
+
EXCHANGES_IN_ORDER = ["NYSE", "NASDAQ", "AMEX", "TSX", "TSXV", "OTC"]
|
12
|
+
|
13
|
+
log = logging.getLogger(__file__)
|
14
|
+
|
15
|
+
|
16
|
+
def exchange_to_index(_exchange: str) -> int:
|
17
|
+
try:
|
18
|
+
return EXCHANGES_IN_ORDER.index(_exchange)
|
19
|
+
except ValueError:
|
20
|
+
return -1
|
21
|
+
|
22
|
+
|
23
|
+
def index_to_exchange(_index: int) -> str:
|
24
|
+
if _index == -1:
|
25
|
+
return "UNKNOWN"
|
26
|
+
return EXCHANGES_IN_ORDER[_index]
|
27
|
+
|
28
|
+
|
29
|
+
security_type_pattern = {
|
30
|
+
"NASDAQ": r" - .*$",
|
31
|
+
"NYSE": r" (Common Stock|Warrants)$",
|
32
|
+
"AMEX": r" (Common Stock|Warrants)$",
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
class CompanyInfo:
|
37
|
+
|
38
|
+
exchange: Optional[str]
|
39
|
+
symbol: Optional[str]
|
40
|
+
name: Optional[str]
|
41
|
+
security_name: Optional[str]
|
42
|
+
sector: Optional[str]
|
43
|
+
industry: Optional[str]
|
44
|
+
|
45
|
+
def __init__(self, **kwargs):
|
46
|
+
self.exchange = None
|
47
|
+
self.name = None
|
48
|
+
self.security_name = None
|
49
|
+
self.sector = None
|
50
|
+
self.industry = None
|
51
|
+
for key, value in kwargs.items():
|
52
|
+
self.__setattr__(key, value)
|
53
|
+
# If name is not set upon initialization, we'll set it from the security name. Also, include
|
54
|
+
# sanitization (removing "Common Stock" from the security name for example)
|
55
|
+
if not self.name:
|
56
|
+
if self.exchange == "OTC":
|
57
|
+
self.security_name = self.security_name.title()
|
58
|
+
if self.exchange in security_type_pattern:
|
59
|
+
self.name = re.sub(security_type_pattern[self.exchange], "", self.security_name)
|
60
|
+
else:
|
61
|
+
self.name = self.security_name
|
62
|
+
|
63
|
+
def __str__(self):
|
64
|
+
return f"({self.exchange}: {self.symbol} - {self.name})"
|
65
|
+
|
66
|
+
def to_json(self):
|
67
|
+
return json.dumps(self.__dict__)
|
68
|
+
|
69
|
+
def to_txt_row(self):
|
70
|
+
return [
|
71
|
+
str(exchange_to_index(self.exchange)),
|
72
|
+
self.symbol,
|
73
|
+
self.name,
|
74
|
+
]
|
75
|
+
|
76
|
+
def to_txt_v2_row(self):
|
77
|
+
return [
|
78
|
+
str(exchange_to_index(self.exchange)),
|
79
|
+
self.symbol,
|
80
|
+
self.name,
|
81
|
+
str(sector_to_index(self.sector)),
|
82
|
+
str(industry_to_index(self.industry)),
|
83
|
+
]
|
84
|
+
|
85
|
+
def __eq__(self, other):
|
86
|
+
return self.__dict__ == other.__dict__
|
87
|
+
|
88
|
+
def __hash__(self):
|
89
|
+
k = self.__dict__.keys()
|
90
|
+
sorted(k)
|
91
|
+
return sum(map(lambda x: f"{x}-{self.__dict__[x]}".__hash__(), k))
|
92
|
+
|
93
|
+
def exchange_symbol(self):
|
94
|
+
return f"{self.exchange}_{self.symbol}"
|
95
|
+
|
96
|
+
|
97
|
+
class Symbols:
|
98
|
+
|
99
|
+
def __init__(self):
|
100
|
+
self.exchanges = set()
|
101
|
+
self.by_name = defaultdict(set)
|
102
|
+
self.by_exchange_and_sym = {}
|
103
|
+
|
104
|
+
def add(self, _sym: CompanyInfo):
|
105
|
+
size_before = len(self.by_exchange_and_sym)
|
106
|
+
self.exchanges.add(_sym.exchange)
|
107
|
+
self.by_name[_sym.name].add(_sym)
|
108
|
+
self.by_exchange_and_sym[f"{_sym.exchange}_{_sym.symbol}"] = _sym
|
109
|
+
if len(self.by_exchange_and_sym) == size_before:
|
110
|
+
log.debug(f"Duplicate: {_sym}")
|
111
|
+
|
112
|
+
def get_all(self) -> [CompanyInfo]:
|
113
|
+
for _exchange_symbol, _symbol in self.by_exchange_and_sym.items():
|
114
|
+
yield _symbol
|
115
|
+
|
116
|
+
def get(self, _exchange: str, _symbol: str) -> CompanyInfo:
|
117
|
+
return self.get_exchange_symbol(f"{_exchange}_{_symbol}")
|
118
|
+
|
119
|
+
def get_exchange_symbol(self, exchange_symbol: str) -> CompanyInfo:
|
120
|
+
return self.by_exchange_and_sym[exchange_symbol]
|
121
|
+
|
122
|
+
def lookup_company(self, symbol: str) -> Optional[CompanyInfo]:
|
123
|
+
for exchange in EXCHANGES_IN_ORDER:
|
124
|
+
try:
|
125
|
+
_symbol = self.get(exchange, symbol.upper())
|
126
|
+
if _symbol:
|
127
|
+
return _symbol
|
128
|
+
except KeyError:
|
129
|
+
pass
|
130
|
+
return None
|
131
|
+
|
132
|
+
def remove_exchange_symbol(self, exchange_symbol: str):
|
133
|
+
_symbol = self.by_exchange_and_sym[exchange_symbol]
|
134
|
+
del self.by_name[_symbol.name]
|
135
|
+
del self.by_exchange_and_sym[exchange_symbol]
|
136
|
+
|
137
|
+
@staticmethod
|
138
|
+
def remove_keys(symbol_as_dict: dict, keys_to_remove: set):
|
139
|
+
return {key: value for key, value in symbol_as_dict.items() if key not in keys_to_remove}
|
140
|
+
|
141
|
+
def without_security_names(self) -> [dict]:
|
142
|
+
return [self.remove_keys(symbol_as_dict, {"security_name", "sector", "industry"})
|
143
|
+
for symbol_as_dict in self.to_dicts()]
|
144
|
+
|
145
|
+
def to_dicts(self) -> [dict]:
|
146
|
+
return [__symbol.__dict__ for __symbol in self.get_all()]
|
147
|
+
|
148
|
+
def to_json(self, remove_security_names: bool = False) -> str:
|
149
|
+
if remove_security_names:
|
150
|
+
return json.dumps(self.without_security_names())
|
151
|
+
return json.dumps(self.to_dicts())
|
152
|
+
|
153
|
+
def to_json_v2(self) -> str:
|
154
|
+
return json.dumps([[exchange_to_index(__symbol.exchange), __symbol.company_info, __symbol.name]
|
155
|
+
for __symbol in self.get_all()])
|
156
|
+
|
157
|
+
def to_txt(self) -> str:
|
158
|
+
exchange_symbol_names = [__symbol.to_txt_row() for __symbol in self.get_all()]
|
159
|
+
sorted_rows = sorted(exchange_symbol_names, key=lambda row: row[1])
|
160
|
+
return "\n".join(["\t".join(row) for row in sorted_rows])
|
161
|
+
|
162
|
+
def to_txt_v2(self) -> str:
|
163
|
+
exchange_symbol_names = [__symbol.to_txt_v2_row() for __symbol in self.get_all()]
|
164
|
+
sorted_rows = sorted(exchange_symbol_names, key=lambda row: row[1])
|
165
|
+
return "\n".join(["\t".join(row) for row in sorted_rows])
|
166
|
+
|
167
|
+
@staticmethod
|
168
|
+
def from_json(json_str):
|
169
|
+
__symbols = Symbols()
|
170
|
+
for item in json.loads(json_str):
|
171
|
+
__symbols.add(CompanyInfo(**item))
|
172
|
+
return __symbols
|
173
|
+
|
174
|
+
@staticmethod
|
175
|
+
def from_json_v2(json_str):
|
176
|
+
__symbols = Symbols()
|
177
|
+
for [_exchange_index, _symbol, _name] in json.loads(json_str):
|
178
|
+
__symbols.add(CompanyInfo(exchange=index_to_exchange(_exchange_index), symbol=_symbol, name=_name))
|
179
|
+
return __symbols
|
180
|
+
|
181
|
+
@staticmethod
|
182
|
+
def from_txt(txt_str):
|
183
|
+
__symbols = Symbols()
|
184
|
+
for line in txt_str.split("\n"):
|
185
|
+
_exchange_index, _symbol, _name = line.split("\t")
|
186
|
+
__symbols.add(CompanyInfo(exchange=index_to_exchange(int(_exchange_index)), symbol=_symbol, name=_name))
|
187
|
+
return __symbols
|
188
|
+
|
189
|
+
@staticmethod
|
190
|
+
def from_txt_v2(txt_str):
|
191
|
+
__symbols = Symbols()
|
192
|
+
for line in txt_str.split("\n"):
|
193
|
+
_exchange_index, _symbol, _name, _sector_index, _industry_index = line.split("\t")
|
194
|
+
__symbols.add(CompanyInfo(
|
195
|
+
exchange=index_to_exchange(int(_exchange_index)),
|
196
|
+
symbol=_symbol,
|
197
|
+
name=_name,
|
198
|
+
sector=index_to_sector(int(_sector_index)),
|
199
|
+
industry=index_to_industry(int(_industry_index)),
|
200
|
+
))
|
201
|
+
return __symbols
|
202
|
+
|
203
|
+
@staticmethod
|
204
|
+
def load_txt_v2():
|
205
|
+
return Symbols.from_txt_v2(get_symbols_v2())
|
206
|
+
|
207
|
+
def __iter__(self):
|
208
|
+
for _exchange_symbol, _symbol in self.by_exchange_and_sym.items():
|
209
|
+
yield _symbol
|
210
|
+
|
211
|
+
def __len__(self):
|
212
|
+
return len(self.by_exchange_and_sym)
|
213
|
+
|
214
|
+
|
215
|
+
def load_symbols() -> Symbols:
|
216
|
+
return Symbols.load_txt_v2()
|
217
|
+
|
218
|
+
|
219
|
+
_symbols = None
|
220
|
+
|
221
|
+
|
222
|
+
def get_symbols() -> Symbols:
|
223
|
+
global _symbols
|
224
|
+
if not _symbols:
|
225
|
+
_symbols = load_symbols()
|
226
|
+
return _symbols
|
earningscall/utils.py
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
import os
|
2
|
+
import pathlib
|
3
|
+
|
4
|
+
import earningscall
|
5
|
+
|
6
|
+
|
7
|
+
def project_file_path(base_dir, file_name):
|
8
|
+
result = os.path.join(pathlib.Path(earningscall.__file__).resolve().parent.parent, base_dir)
|
9
|
+
if file_name is None:
|
10
|
+
return result
|
11
|
+
return os.path.join(result, file_name)
|
12
|
+
|
13
|
+
|
14
|
+
def data_path(file_name=None):
|
15
|
+
return project_file_path("tests/data", file_name)
|
@@ -0,0 +1,101 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: earningscall
|
3
|
+
Version: 0.0.4
|
4
|
+
Summary: The EarningsCall Python library.
|
5
|
+
Project-URL: Documentation, https://github.com/EarningsCall/earningscall-python
|
6
|
+
Project-URL: Issues, https://github.com/EarningsCall/earningscall-python/issues
|
7
|
+
Project-URL: Source, https://github.com/EarningsCall/earningscall-python
|
8
|
+
Author-email: EarningsCall <dev@earningscall.biz>
|
9
|
+
License-File: LICENSE
|
10
|
+
Requires-Python: >=3.8
|
11
|
+
Requires-Dist: dataclasses-json>=0.6.4
|
12
|
+
Requires-Dist: dataclasses>=0.6
|
13
|
+
Requires-Dist: more-itertools>=10.0.0
|
14
|
+
Requires-Dist: requests>=2.30.0
|
15
|
+
Description-Content-Type: text/markdown
|
16
|
+
|
17
|
+
# EarningsCall Python Library
|
18
|
+
|
19
|
+
The EarningsCall Python library provides convenient access to the EarningsCall API from
|
20
|
+
applications written in the Python language. It includes a pre-defined set of
|
21
|
+
classes for API resources that initialize themselves dynamically from API
|
22
|
+
responses.
|
23
|
+
|
24
|
+
# Installation
|
25
|
+
|
26
|
+
You don't need this source code unless you want to modify the package. If you just want to use the package, just run:
|
27
|
+
|
28
|
+
```sh
|
29
|
+
pip install --upgrade earningscall
|
30
|
+
```
|
31
|
+
|
32
|
+
# Requirements
|
33
|
+
|
34
|
+
* Python 3.8+ (PyPI supported)
|
35
|
+
|
36
|
+
|
37
|
+
## Get Transcript for a Single Quarter
|
38
|
+
|
39
|
+
```python
|
40
|
+
from earningscall import get_company
|
41
|
+
|
42
|
+
|
43
|
+
company = get_company("aapl") # Lookup Apple, Inc by its ticker symbol, "AAPL"
|
44
|
+
|
45
|
+
transcript = company.get_transcript(year=2021, quarter=3)
|
46
|
+
print(f"{company} Q3 2021 Transcript Text: \"{transcript.text[:100]}...\"")
|
47
|
+
```
|
48
|
+
|
49
|
+
Output
|
50
|
+
|
51
|
+
```text
|
52
|
+
Apple Inc. Q3 2021 Transcript Text: "Good day, and welcome to the Apple Q3 FY 2021 Earnings Conference Call. Today's call is being record..."
|
53
|
+
```
|
54
|
+
|
55
|
+
|
56
|
+
## Get All Transcripts for a company
|
57
|
+
|
58
|
+
|
59
|
+
```python
|
60
|
+
from earningscall import get_company
|
61
|
+
|
62
|
+
|
63
|
+
company = get_company("aapl") # Lookup Apple, Inc by its ticker symbol, "AAPL"
|
64
|
+
|
65
|
+
print(f"Getting all transcripts for: {company}..")
|
66
|
+
# Retrieve all earnings conference call events for a company, and iterate through each one
|
67
|
+
for event in company.events():
|
68
|
+
transcript = company.get_transcript(event) # Fetch the earnings call transcript for this event
|
69
|
+
print(f"* Q{event.quarter} {event.year}")
|
70
|
+
if transcript:
|
71
|
+
print(f" Transcript Text: \"{transcript.text[:100]}...\"")
|
72
|
+
else:
|
73
|
+
print(f" No transcript found.")
|
74
|
+
|
75
|
+
```
|
76
|
+
|
77
|
+
Output
|
78
|
+
|
79
|
+
```text
|
80
|
+
Getting all transcripts for: Apple Inc...
|
81
|
+
* Q4 2023
|
82
|
+
Transcript Text: "Good day and welcome to the Apple Q4 Fiscal Year 2023 earnings conference call. Today's call is bein..."
|
83
|
+
* Q3 2023
|
84
|
+
Transcript Text: "Good day and welcome to the Apple Q3 Fiscal Year 2023 earnings conference call. Today's call is bein..."
|
85
|
+
* Q2 2023
|
86
|
+
Transcript Text: "At this time for opening remarks and introductions, I would like to turn the call over to Suhasini T..."
|
87
|
+
* Q1 2023
|
88
|
+
|
89
|
+
...
|
90
|
+
```
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
## List All Companies
|
95
|
+
|
96
|
+
```python
|
97
|
+
from earningscall import get_all_companies
|
98
|
+
|
99
|
+
for company in get_all_companies():
|
100
|
+
print(f"{company.company_info} -- {company.company_info.sector} -- {company.company_info.industry}")
|
101
|
+
```
|
@@ -0,0 +1,14 @@
|
|
1
|
+
earningscall/__init__.py,sha256=Hfh2BCnihAqfWV9niZrlfHmTNuL5tEKTW37bAXGLrF0,119
|
2
|
+
earningscall/api.py,sha256=lBUzBUjq_WNt4DH1usszG6OYJtBQbGYOy6KY0ags8ZI,1613
|
3
|
+
earningscall/company.py,sha256=fGbfh4S1m1K0rgkzpToYOrkPOZSJQieen6RJlSIvCjY,1610
|
4
|
+
earningscall/errors.py,sha256=Y5LVdvOMz_FgCXu4gXnyHceGvQwWmjHbkbRU2dsgdtA,433
|
5
|
+
earningscall/event.py,sha256=a5mcyfuCqPCopcKQUZ1HJyqHfAf-RNKnux_o68DIUHM,689
|
6
|
+
earningscall/exports.py,sha256=bG2ehoILyGTUrgRleuub4tXkiVGUdUZgsmoJ6giQgj4,478
|
7
|
+
earningscall/sectors.py,sha256=9aw14krRzdLJSTFC72Nwk3MQaXAIgkTBk5S-KTiki3U,5946
|
8
|
+
earningscall/symbols.py,sha256=mYWVO3YcUEr6JDxoH238_lsz67QHJGhk-o6jN1ot7R4,7372
|
9
|
+
earningscall/transcript.py,sha256=gV0Pqc9iilg4QQc89-ADEIcFQkQhFSnsJo8rvF7zKp0,192
|
10
|
+
earningscall/utils.py,sha256=g0MI9apoAQ2L7Ccj91mOHUWAE7zFbAvWqHPMjMJesFk,367
|
11
|
+
earningscall-0.0.4.dist-info/METADATA,sha256=1U9i621evx8KJEcdpm9iOgVV8Vrkeyr19APTa-DqTek,2935
|
12
|
+
earningscall-0.0.4.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
|
13
|
+
earningscall-0.0.4.dist-info/licenses/LICENSE,sha256=ktEB_UcRMg2cQlX9wiDs544xWncWizwS9mEZuGsCLrM,1069
|
14
|
+
earningscall-0.0.4.dist-info/RECORD,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 EarningsCall
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|