Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
EarningsCall committed May 27, 2024
1 parent 672059c commit 65f64c7
Show file tree
Hide file tree
Showing 9 changed files with 798 additions and 9 deletions.
3 changes: 3 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

TODO: Add rye installation instructions.

This project uses Rye: https://rye.astral.sh/


### Saving Server-Side Responses for a Mocked Unit test

You can use the following test code to save responses from the server as a .YAML file:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pip install --upgrade earningscall

# Requirements

* Python 3.7+ (PyPI supported)
* Python 3.8+ (PyPI supported)


## Get Transcript for a Single Quarter
Expand Down
14 changes: 11 additions & 3 deletions earningscall/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@

DOMAIN = os.environ.get("ECALL_DOMAIN", "earningscall.biz")
API_BASE = f"https://v2.api.{DOMAIN}"
api_key: Optional[str] = None


def get_api_key():
global api_key
if api_key is None:
return os.environ.get("ECALL_API_KEY", "demo")
return api_key


def get_events(exchange: str,
symbol: str):

log.debug(f"get_events exchange: {exchange} symbol: {symbol}")
params = {
"apikey": "demo",
"apikey": get_api_key(),
"exchange": exchange,
"symbol": symbol,
}
Expand Down Expand Up @@ -46,14 +54,14 @@ def get_transcript(exchange: str,


def get_symbols_v1():
response = requests.get(f"https://{DOMAIN}/symbols.txt")
response = requests.get(f"{API_BASE}/symbols.txt")
if response.status_code != 200:
return None
return response.text


def get_symbols_v2():
response = requests.get(f"https://{DOMAIN}/symbols-v2.txt")
response = requests.get(f"{API_BASE}/symbols-v2.txt")
if response.status_code != 200:
return None
return response.text
25 changes: 25 additions & 0 deletions earningscall/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


class BaseError(RuntimeError):
"""
Base error
"""

def __init__(self, msg=None):
self.msg = msg

def __str__(self):
if self.msg:
return str(self.msg)
return ""


class ClientError(BaseError):
"""
Used to return 4XX errors.
"""
status: int = 400 # https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400


class MissingApiKeyError(ClientError):
pass
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "earningscall"
version = "0.0.3"
version = "0.0.4"
description = "The EarningsCall Python library."
readme = "README.md"
authors = [
Expand Down
715 changes: 715 additions & 0 deletions tests/data/msft-transcript-response.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/data/symbols-v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3076,4 +3076,4 @@ responses:
content_type: text/plain
method: GET
status: 200
url: https://earningscall.biz/symbols-v2.txt
url: https://v2.api.earningscall.biz/symbols-v2.txt
38 changes: 38 additions & 0 deletions tests/test_get_transcript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import responses

from earningscall import get_company
from earningscall.utils import data_path


# Uncomment following code to generate msft-transcript-response.yaml file
#
# from responses import _recorder
# @_recorder.record(file_path="msft-transcript-response.yaml")
# def test_save_symbols_v1():
# requests.get("https://v2.api.earningscall.biz/transcript?apikey=demo&exchange=NASDAQ&symbol=MSFT&year=2023&quarter=1")


@responses.activate
def test_get_demo_company():
##
responses._add_from_file(file_path=data_path("symbols-v2.yaml"))
responses._add_from_file(file_path=data_path("msft-transcript-response.yaml"))
##
company = get_company("msft")
##
transcript = company.get_transcript(year=2023, quarter=1)
assert transcript.text[:100] == ('Greetings, and welcome to the Microsoft Fiscal Year 2023 First Quarter Earnings '
'Conference Call. At ')


# @responses.activate
# def test_get_non_demo_company():
# ##
# responses._add_from_file(file_path=data_path("symbols-v2.yaml"))
# # responses._add_from_file(file_path=data_path("msft-transcript-response.yaml"))
# ##
# company = get_company("nvda")
# ##
# transcript = company.get_transcript(year=2023, quarter=1)
# assert transcript.text[:100] == ('Greetings, and welcome to the Microsoft Fiscal Year 2023 First Quarter Earnings '
# 'Conference Call. At ')
6 changes: 3 additions & 3 deletions tests/test_symbols.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import responses
from earningscall.api import DOMAIN

from earningscall.api import API_BASE
from earningscall.symbols import Symbols, CompanyInfo
from earningscall.utils import data_path


@responses.activate
def test_load_symbols_txt_v2():
##
responses.patch(f"https://{DOMAIN}")
responses.patch(API_BASE)
print("symbols path")
print(data_path("symbols-v2.yaml"))
responses._add_from_file(file_path=data_path("symbols-v2.yaml"))
Expand All @@ -22,7 +22,7 @@ def test_load_symbols_txt_v2():
assert _symbol.sector == "Technology"
assert _symbol.industry == "Consumer Electronics"
assert len(responses.calls) == 1
assert responses.calls[0].request.url == "https://earningscall.biz/symbols-v2.txt"
assert responses.calls[0].request.url == "https://v2.api.earningscall.biz/symbols-v2.txt"


def test_symbols_serialization_to_text_v2():
Expand Down

0 comments on commit 65f64c7

Please sign in to comment.