-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworking the project in a way to incorporate an interface "PostClient" which supports slack and twitter.
- Loading branch information
Showing
13 changed files
with
163 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
DUNE_API_KEY= | ||
|
||
# Slack Credentials | ||
SLACK_TOKEN= | ||
SLACK_ALERT_CHANNEL= | ||
|
||
DUNE_API_KEY= | ||
# Twitter Credentials | ||
CONSUMER_KEY= | ||
CONSUMER_SECRET= | ||
ACCESS_TOKEN= | ||
ACCESS_TOKEN_SECRET= |
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,37 @@ | ||
VENV = venv | ||
PYTHON = $(VENV)/bin/python3 | ||
PIP = $(VENV)/bin/pip | ||
PROJECT_ROOT = src | ||
|
||
|
||
$(VENV)/bin/activate: requirements/dev.txt | ||
python3 -m venv $(VENV) | ||
$(PIP) install --upgrade pip | ||
$(PIP) install -r requirements/dev.txt | ||
|
||
|
||
install: | ||
make $(VENV)/bin/activate | ||
|
||
clean: | ||
rm -rf __pycache__ | ||
|
||
fmt: | ||
black ./ | ||
|
||
lint: | ||
pylint ${PROJECT_ROOT}/ | ||
|
||
types: | ||
mypy ${PROJECT_ROOT}/ --strict | ||
|
||
check: | ||
make fmt | ||
make lint | ||
make types | ||
|
||
test-unit: | ||
python -m pytest tests/unit | ||
|
||
test-e2e: | ||
python -m pytest tests/e2e |
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
Empty file.
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,12 @@ | ||
"""Abstraction for posting alerts""" | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class PostClient(ABC): | ||
""" | ||
Basic Post Client with message post functionality | ||
""" | ||
|
||
@abstractmethod | ||
def post(self, message: str) -> None: | ||
"""Posts `message` to `self.channel` excluding link previews.""" |
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,24 @@ | ||
""" | ||
Twitter Alert Client | ||
""" | ||
import tweepy # type:ignore | ||
|
||
from src.post.base import PostClient | ||
|
||
|
||
class TwitterClient(PostClient): | ||
"""Forwards alerts to Twitter""" | ||
|
||
def __init__(self, credentials: dict[str, str]) -> None: | ||
auth = tweepy.OAuthHandler( | ||
consumer_key=credentials["consumer_key"], | ||
consumer_secret=credentials["consumer_secret"], | ||
) | ||
auth.set_access_token( | ||
key=credentials["access_token"], | ||
secret=credentials["access_token_secret"], | ||
) | ||
self.api = tweepy.API(auth) | ||
|
||
def post(self, message: str) -> None: | ||
self.api.update_status(status=message) |
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
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,26 @@ | ||
import os | ||
import unittest | ||
|
||
import dotenv | ||
import pytest | ||
|
||
from src.post.twitter import TwitterClient | ||
|
||
|
||
class TestTwitterPost(unittest.TestCase): | ||
@pytest.mark.skip(reason="Don't want to make a post all the time.") | ||
def test_twitter_post(self): | ||
dotenv.load_dotenv() | ||
client = TwitterClient( | ||
credentials={ | ||
"consumer_key": os.environ["CONSUMER_KEY"], | ||
"consumer_secret": os.environ["CONSUMER_SECRET"], | ||
"access_token": os.environ["ACCESS_TOKEN"], | ||
"access_token_secret": os.environ["ACCESS_TOKEN_SECRET"], | ||
} | ||
) | ||
client.post("Hi Mom!") | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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