-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notifications): Add support for transaction filter and notificat…
…ions via Discord.
- Loading branch information
1 parent
3d36198
commit 0cb3393
Showing
13 changed files
with
179 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import click | ||
from discord_webhook import DiscordEmbed, DiscordWebhook | ||
|
||
from leggen.utils.text import info | ||
|
||
|
||
def send_message(ctx: click.Context, transactions: list): | ||
info(f"Got {len(transactions)} new transactions, sending message to Discord") | ||
webhook = DiscordWebhook(url=ctx.obj["notifications"]["discord"]["webhook"]) | ||
|
||
embed = DiscordEmbed( | ||
title="", | ||
description=f"{len(transactions)} new transaction matches", | ||
color="03b2f8", | ||
) | ||
embed.set_author( | ||
name="Leggen", | ||
url="https://github.com/elisiariocouto/leggen", | ||
) | ||
embed.set_footer(text="Case-insensitive filters") | ||
embed.set_timestamp() | ||
for transaction in transactions: | ||
embed.add_embed_field( | ||
name=transaction["name"], | ||
value=f"{transaction['value']}{transaction['currency']} ({transaction['date']})", | ||
) | ||
|
||
webhook.add_embed(embed) | ||
response = webhook.execute() | ||
response.raise_for_status() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,18 @@ | ||
import json | ||
import sys | ||
from pathlib import Path | ||
|
||
import click | ||
import tomllib | ||
|
||
from leggen.utils.text import error, info | ||
from leggen.utils.text import error | ||
|
||
|
||
def save_config(d: dict): | ||
Path.mkdir(Path(click.get_app_dir("leggen")), exist_ok=True) | ||
config_file = click.get_app_dir("leggen") / Path("config.json") | ||
|
||
with click.open_file(str(config_file), "w") as f: | ||
json.dump(d, f) | ||
info(f"Wrote configuration file at '{config_file}'") | ||
|
||
|
||
def load_config() -> dict: | ||
config_file = click.get_app_dir("leggen") / Path("config.json") | ||
def load_config(ctx: click.Context, _, filename): | ||
try: | ||
with click.open_file(str(config_file), "r") as f: | ||
config = json.load(f) | ||
return config | ||
with click.open_file(str(filename), "rb") as f: | ||
# TODO: Implement configuration file validation (use pydantic?) | ||
ctx.obj = tomllib.load(f) | ||
except FileNotFoundError: | ||
error( | ||
"Configuration file not found. Run `leggen init` to configure your account." | ||
"Configuration file not found. Provide a valid configuration file path with leggen --config <path> or LEGGEN_CONFIG=<path> environment variable." | ||
) | ||
sys.exit(1) |
Oops, something went wrong.