Skip to content

Commit

Permalink
Parser from name; lambda args from CDK .env (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredliporace committed Mar 1, 2024
1 parent ecffe75 commit 22e263d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
16 changes: 2 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,7 @@
__pycache__
/build/
/cdk/cdk/
cdk/lambda/Babel-*.dist-info/
cdk/lambda/backports.zoneinfo-0.2.1.dist-info/
cdk/lambda/backports/
cdk/lambda/beautifulsoup4-*-info/
cdk/lambda/certifi-2022.12.7.dist-info/
cdk/lambda/charset_normalizer-*.dist-info/
cdk/lambda/icalendar-5.0.4.dist-info/
cdk/lambda/idna-3.4.dist-info/
cdk/lambda/pydantic-*.dist-info/
cdk/lambda/pytz-*.dist-info/
cdk/lambda/requests-2.28.2.dist-info/
cdk/lambda/soupsieve-*.dist-info/
cdk/lambda/typing_extensions-*.dist-info/
cdk/lambda/urllib3-*.dist-info/
.env



2 changes: 1 addition & 1 deletion cdk/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, application: App, idnt: str):
retcode = call("cp -u ./lambda/code.py ../cdk_build/lambda", shell=True)
assert retcode == 0
retcode = call(
"cd ../ && pip install . --upgrade -t ./cdk_build/lambda/ -c constraints.txt",
"cd ../ && pip install . -t ./cdk_build/lambda/ -c constraints.txt -q -q",
shell=True,
)
assert retcode == 0
Expand Down
16 changes: 11 additions & 5 deletions cdk/lambda/code.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Lambda code for footcal service."""
"""Template lambda code for footcal service."""

import json
import logging
import os
from typing import Any, Dict

from footcal.parsers import ESPNParser
from footcal.parsers import ESPNParser # pylint: disable=unused-import

logging.getLogger("botocore.credentials").disabled = True
LOGGER = logging.getLogger(__name__)
Expand All @@ -19,9 +20,14 @@ def handler(
LOGGER.info(os.environ["PARSER"])
LOGGER.info(os.environ["PARSER_CTOR_ARGS"])
LOGGER.info(os.environ["PARSER_GET_CALENDAR_ARGS"])
parser = ESPNParser(timezone_id="US/Eastern", locale="pt_BR")
parser_ctor = globals()[os.environ["PARSER"]]
# parser = ESPNParser(timezone_id="US/Eastern", locale="pt_BR")
parser = parser_ctor(**(json.loads(os.environ["PARSER_CTOR_ARGS"])))
# calendar = parser.get_calendar(
# url="https://www.espn.com.br/futebol/time/calendario/_/id/3445/fluminense",
# calendar_name="Calendar",
# )
calendar = parser.get_calendar(
url="https://www.espn.com.br/futebol/time/calendario/_/id/3445/fluminense",
calendar_name="Calendar",
**(json.loads(os.environ["PARSER_GET_CALENDAR_ARGS"]))
)
return {"statusCode": 200, "body": calendar.to_ical().decode("utf-8")}
13 changes: 13 additions & 0 deletions footcal/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,16 @@ def test_espn_parser() -> None:
calendar = espn.get_calendar(url=test_url, calendar_name="test")
assert not calendar.is_empty()
assert not calendar.is_broken


def test_parser_from_name() -> None:
"""test_parser_from_name."""
ctor = globals()["ESPNParser"]
inst = ctor(utc_offset=-4)
# Check last available format
with open("footcal/tests/fixtures/espn_flu.html", encoding="utf-8") as fin:
html_text = fin.read()
matches = inst.matches_from_str(html_text=html_text)
assert len(matches) > 0
with pytest.raises(KeyError):
ctor = globals()["UndefinedParser"]

0 comments on commit 22e263d

Please sign in to comment.