Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.2.0 #25

Merged
merged 6 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.7
rev: v0.5.6
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ Find changes for the upcoming release in the project's [changelog.d directory](h

<!-- scriv-insert-here -->

<a id='changelog-0.2.0'></a>
## 0.2.0 (2024-08-06)

### Backwards-incompatible changes

-

### New features

Reorganize project structure to better support other APIs

### Bug fixes

-

### Other changes

-

<a id='changelog-0.1.0'></a>
## 0.1.0 (2024-08-01)

Expand Down
3 changes: 1 addition & 2 deletions docs/dev/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ Python API
.. toctree::
:titlesonly:

sasquatchbackpack.sasquatch
sasquatchbackpack.sources
sasquatchbackpack.sasquatch
5 changes: 0 additions & 5 deletions docs/dev/api/sasquatchbackpack.sources.rst

This file was deleted.

1,314 changes: 687 additions & 627 deletions requirements/dev.txt

Large diffs are not rendered by default.

756 changes: 385 additions & 371 deletions requirements/main.txt

Large diffs are not rendered by default.

79 changes: 40 additions & 39 deletions requirements/tox.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This file was autogenerated by uv via the following command:
# uv pip compile --generate-hashes --output-file requirements/tox.txt requirements/tox.in
cachetools==5.3.3 \
--hash=sha256:0abad1021d3f8325b2fc1d2e9c8b9c9d57b04c3932657a72465447332c24d945 \
--hash=sha256:ba29e2dfa0b8b556606f097407ed1aa62080ee108ab0dc5ec9d6a723a007d105
cachetools==5.4.0 \
--hash=sha256:3ae3b49a3d5e28a77a0be2b37dbcb89005058959cb2323858c2657c4a8cab474 \
--hash=sha256:b8adc2e7c07f105ced7bc56dbb6dfbe7c4a00acce20e2227b3f355be89bc6827
# via tox
chardet==5.2.0 \
--hash=sha256:1b3b6ff479a8c414bc3fa2c0852995695c4a026dcd6d0633b2dd092ca39c1cf7 \
Expand All @@ -18,16 +18,16 @@ distlib==0.3.8 \
# via
# -c requirements/dev.txt
# virtualenv
filelock==3.14.0 \
--hash=sha256:43339835842f110ca7ae60f1e1c160714c5a6afd15a2873419ab185334975c0f \
--hash=sha256:6ea72da3be9b8c82afd3edcf99f2fffbb5076335a5ae4d03248bb5b6c3eae78a
filelock==3.15.4 \
--hash=sha256:2207938cbc1844345cb01a5a95524dae30f0ce089eba5b00378295a17e3e90cb \
--hash=sha256:6ca1fffae96225dab4c6eaf1c4f4f28cd2568d3ec2a44e15a08520504de468e7
# via
# -c requirements/dev.txt
# tox
# virtualenv
packaging==24.0 \
--hash=sha256:2ddfb553fdf02fb784c234c7ba6ccc288296ceabec964ad2eae3777778130bc5 \
--hash=sha256:eb82c5e3e56209074766e6885bb04b8c38a0c015d0a30036ebe7ece34c9989e9
packaging==24.1 \
--hash=sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002 \
--hash=sha256:5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124
# via
# -c requirements/dev.txt
# -c requirements/main.txt
Expand All @@ -47,42 +47,43 @@ pluggy==1.5.0 \
# via
# -c requirements/dev.txt
# tox
pyproject-api==1.6.1 \
--hash=sha256:1817dc018adc0d1ff9ca1ed8c60e1623d5aaca40814b953af14a9cf9a5cae538 \
--hash=sha256:4c0116d60476b0786c88692cf4e325a9814965e2469c5998b830bba16b183675
pyproject-api==1.7.1 \
--hash=sha256:2dc1654062c2b27733d8fd4cdda672b22fe8741ef1dde8e3a998a9547b071eeb \
--hash=sha256:7ebc6cd10710f89f4cf2a2731710a98abce37ebff19427116ff2174c9236a827
# via tox
tox==4.15.0 \
--hash=sha256:300055f335d855b2ab1b12c5802de7f62a36d4fd53f30bd2835f6a201dda46ea \
--hash=sha256:7a0beeef166fbe566f54f795b4906c31b428eddafc0102ac00d20998dd1933f6
tox==4.17.1 \
--hash=sha256:2974597c0353577126ab014f52d1a399fb761049e165ff34427f84e8cfe6c990 \
--hash=sha256:2c41565a571e34480bd401d668a4899806169a4633e972ac296c54406d2ded8a
# via
# -r requirements/tox.in
# tox-uv
tox-uv==1.9.0 \
--hash=sha256:1a2e49ea5aac1c4e83513b863169fa47ce1479fdb0aaac2ab09d35e9a9635f84 \
--hash=sha256:ff2300be19acc14b15580a3a06806ef36cbb952e124c8a478c6f3d59f768b122
tox-uv==1.11.1 \
--hash=sha256:9e310020eaad3c7389770007d49cb2146e92383a47380086c065156c8aff0c56 \
--hash=sha256:e4962ad07541bd9da08e6d654edc5ce636665899e9c181a4ea4a3f4385da9158
# via -r requirements/tox.in
uv==0.2.5 \
--hash=sha256:041b1ee240fc36606dcea2a68369c7db29eb0ea75dc15d33f74ed6485a7d3aa2 \
--hash=sha256:14f5ca36f8873d272a715250b3d602815924742a5f184e1400826fb967fd371e \
--hash=sha256:1e0b790a2367c8ebdd1a3eb2aca87ae393c5536021fbc37f97c36e5454cb2875 \
--hash=sha256:1ec01d0505e2d56cebad02b7565db5b1e61ad97c4eeca751c4816bfe8261ea28 \
--hash=sha256:541c8ee1369232c7be8bde2165175b08ddfa1cae6d0d31ffca9993fa83b64634 \
--hash=sha256:5b2f56c0219c9ee37da702d824ae3bffd7d023184824e6fdaacac8b435624784 \
--hash=sha256:5ffb593256d69623071c248348e6fe101aae806944da68e3b597c377444e022f \
--hash=sha256:650f81439c4f65e86fdba84f2cbb6700a074b95d70c5cc3d38e8ce2b87e43a45 \
--hash=sha256:6b977b3d83b7bb48ccc0ef568f1be73f45ff0bc53ff9ba1e33b4c883027feec9 \
--hash=sha256:6cedb8bfabd59ab56e781297dc6c66a298cfa912da16a4da9439274681c39622 \
--hash=sha256:7a4e793419993967183633afb2cfd9c4a7c4c5134f01af8c8aa25bf9520ff1db \
--hash=sha256:7fb8c35694de30186140adddc8498222c8728b00edde25ddc7c93c3dee69644c \
--hash=sha256:a55c5b1bf948d439a40f4d959be853f7441923c6b324e4d423116fda2cb277da \
--hash=sha256:b64372e90c6e921efbcca82113bc6a8f86a5a6ba8695f8c1d2dd215b7989b2a3 \
--hash=sha256:d7f24e33253e0b60faf4dd76849f0e0e710f30229f205eaaa94660b8626d6636 \
--hash=sha256:d879d0c436ad9289ff1ad39112a0b53bf5b99ec69d3d300e55d18864b4ed3291 \
--hash=sha256:ff1c8fe7d54dd3051bab529f715e562994d19e038822ce99acd903cbbf8d0cd0
uv==0.2.34 \
--hash=sha256:0a6a9a15adde8ef1faa7ac1289fcf622c5ca630d74a5274281bb149e85205105 \
--hash=sha256:0c8e746b674cc854113077859cab794ec92ea75d572544b8e6c73298a86183b8 \
--hash=sha256:102c033cd23c89cbb42b18be376ce3cf66123b308cae48718a6197764d1c41b3 \
--hash=sha256:19f2ff55b467eea0c53c394108188ba4989d25e634eb0362115e8137d49e47a2 \
--hash=sha256:31623af3f21fd5faf9e9640d3f22c181218477af3c817198eef313ee6c33164d \
--hash=sha256:3b6354f1bb83a2db56c1f062206bb0e697d31244f4ff419a6ff6114016527e45 \
--hash=sha256:4ce15beeba44e4ea052d83c89eb4ea3586dfd68bab039c5cdf44b90fbfc5698d \
--hash=sha256:5a40d5365e2790537005903470d31bc4c0fcde08f3f3969a4eefcdcded7c7965 \
--hash=sha256:5ff72659a05f02f80180c85b9803c69cc6cc66da74478cf2b1516e929b9ac8a0 \
--hash=sha256:6e10be9666ba9572ad76e0dcf0cae41c821b4475be0e3963a0a5911838037a96 \
--hash=sha256:8f79f157e4eed3beff69b13bf4b0b3549b2f1b8a22c4559bb29ab2f3599fcd0b \
--hash=sha256:cdcf3f28748a252aee5308312a6d265b42dd1033079b6b49ea2c548e95bd3341 \
--hash=sha256:d3b74ccc24f25519507cb337cb8b4d5bfc6f0e6476ff0d30bb7c62c9a0c9dd10 \
--hash=sha256:da1ff6e1125e068794ef6dfbd9f209fad11c8882c01e47add6cd524e1772c292 \
--hash=sha256:f30194d3c50446003033ec5ce65ddcfe6961aadafacd8ff6b958a4bc4596003b \
--hash=sha256:f6bdae3db4deb200d1ca4607f51659747c335cce6678209969e0e196167b2760 \
--hash=sha256:fb62e0e338b6fae4b9ef7fdbc2a82235ecdee3797f82f6eecbfc61c998e41701 \
--hash=sha256:fbe5730caed03dc4aa8dd3aa9f2317df82396b0913a79b1a2793d7595e65478e
# via tox-uv
virtualenv==20.26.2 \
--hash=sha256:82bf0f4eebbb78d36ddaee0283d43fe5736b53880b8a8cdcd37390a07ac3741c \
--hash=sha256:a624db5e94f01ad993d476b9ee5346fdf7b9de43ccaee0e0197012dc838a0e9b
virtualenv==20.26.3 \
--hash=sha256:4c43a2a236279d9ea36a0d76f98d84bd6ca94ac4e0f4a3b9d46d05e10fea542a \
--hash=sha256:8cc4a31139e796e9a7de2cd5cf2489de1217193116a8fd42328f1bd65f434589
# via
# -c requirements/dev.txt
# tox
192 changes: 2 additions & 190 deletions src/sasquatchbackpack/cli.py
Original file line number Diff line number Diff line change
@@ -1,100 +1,8 @@
"""Backpack CLI."""

from datetime import timedelta

import click

from sasquatchbackpack import sasquatch, sources
from sasquatchbackpack.scripts import usgs

DEFAULT_RADIUS = 400

DEFAULT_COORDS = (-30.22573200864174, -70.73932987127506)

DEFAULT_MAGNITUDE_BOUNDS = (2, 10)


def check_duration(
ctx: click.Context, param: dict, value: tuple[int, int]
) -> tuple[int, int]:
"""Validate duration inputs."""
days, hours = value
total_duration = timedelta(days=days, hours=hours)

if total_duration > timedelta(days=10000):
raise click.BadParameter(
f"""Your provided duration ({total_duration!s}) is
too large. The maximum is 10000 days."""
)
if total_duration < timedelta(hours=1):
raise click.BadParameter(
f"""Your provided duration ({total_duration!s}) is
too small. The minimum is 1 hour."""
)

return value


def check_radius(ctx: click.Context, param: dict, value: int) -> int:
"""Validate radius inputs."""
if value > 5000:
raise click.BadParameter(
f"""Your provided radius ({value}) is too large.
The maximum is 5000."""
)
if value <= 0:
raise click.BadParameter(
f"""Your provided radius ({value}) is too small.
The minimum is 0.1."""
)

return value


def check_coords(
ctx: click.Context, param: dict, value: tuple[float, float]
) -> tuple[float, float]:
"""Validate coords inputs."""
latitude, longitude = value
if latitude < -90.0 or latitude > 90.0:
raise click.BadParameter(
f"Your provided latitude ({latitude}) is out of bounds."
"The range is -90 to 90."
)

if longitude < -180.0 or longitude > 180.0:
raise click.BadParameter(
f"Your provided longitude ({longitude}) is out of bounds."
"The range is -180 to 180."
)

return value


def check_magnitude_bounds(
ctx: click.Context, param: dict, value: tuple[int, int]
) -> tuple[int, int]:
"""Validate magnitude bounds."""
lower, upper = value
if lower < 0 or lower > 10:
raise click.BadParameter(
f"Your provided minimum magnitude ({lower}) is "
"out of bounds. The range is 0 to 10."
)

if upper > 10 or upper < 0:
raise click.BadParameter(
f"Your provided maximum magnitude ({upper}) is "
"out of bounds. The range is 0 to 10."
)

if lower > upper:
raise click.BadParameter(
f"""Your provided minimum magnitude ({lower})
cannot excede your provided maximum magnitude ({upper})."""
)

return value
from sasquatchbackpack.commands import usgs


@click.group(context_settings={"help_option_names": ["-h", "--help"]})
Expand All @@ -103,100 +11,4 @@ def main() -> None:
"""Command-line interface for sasquatchbackpack."""


@main.command()
@click.option(
"-d",
"--duration",
help="How far back from the present should be searched (days, hours)",
required=True,
type=(int, int),
callback=check_duration,
)
@click.option(
"-r",
"--radius",
help="radius of search from central coordinates in km.",
default=DEFAULT_RADIUS,
type=int,
show_default=True,
callback=check_radius,
)
@click.option(
"-c",
"--coords",
help="latitude and longitude of the central coordinates "
"(latitude, longitude). Defaults to the coordinates of Cerro Pachon.",
default=DEFAULT_COORDS,
type=(float, float),
show_default=True,
callback=check_coords,
)
@click.option(
"-m",
"--magnitude-bounds",
help="upper and lower bounds (lower, upper)",
default=DEFAULT_MAGNITUDE_BOUNDS,
type=(int, int),
show_default=True,
callback=check_magnitude_bounds,
)
@click.option(
"--dry-run",
is_flag=True,
default=False,
help="Perform a trial run with no data being sent to Kafka.",
)
def usgs_earthquake_data(
duration: tuple[int, int],
radius: int,
coords: tuple[float, float],
magnitude_bounds: tuple[int, int],
dry_run: bool, # noqa: FBT001
) -> None:
"""Seaches USGS databases for relevant earthquake data and prints it
to console. Optionally, also allows the user to post the
queried data to kafka.
"""
days, hours = duration
total_duration = timedelta(days=days, hours=hours)

results = usgs.search_api(
total_duration,
radius,
coords,
magnitude_bounds,
)

if len(results) > 0:
click.secho("SUCCESS!", fg="green")
click.echo("------")
for result in results:
click.echo(result)
click.echo("------")
else:
click.secho("SUCCESS! (kinda)", fg="yellow")
click.echo("------")
click.echo("No results found for the provided criteria :(")
click.echo("------")
return

if dry_run:
click.echo("Dry run mode: No data will be sent to Kafka.")
return

click.echo("Sending data...")

config = sources.USGSConfig(
total_duration, radius, coords, magnitude_bounds
)
source = sources.USGSSource(config)

backpack_dispatcher = sasquatch.BackpackDispatcher(
source, sasquatch.DispatcherConfig()
)
result = backpack_dispatcher.post()

if "Error" in result:
click.secho(result, fg="red")
else:
click.secho("Data successfully sent!", fg="green")
main.add_command(usgs.usgs_earthquake_data)
Fireye04 marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions src/sasquatchbackpack/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""CLI commands for various libraries."""
Loading