Skip to content

Commit

Permalink
adding notiboy support
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev committed Jul 15, 2023
1 parent 6bb767a commit 7b26d4a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 41 deletions.
81 changes: 42 additions & 39 deletions .github/workflows/analytics.yaml
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
name: Execute AlgoPing Analytics

on:
schedule:
- cron: "5 0 * * *"
schedule:
- cron: "5 0 * * *"

workflow_dispatch:
workflow_dispatch:

jobs:
run-algoping-analytics:
env:
BEARER_TOKEN: ${{ secrets.BEARER_TOKEN }}
CONSUMER_KEY: ${{ secrets.CONSUMER_KEY }}
CONSUMER_SECRET: ${{ secrets.CONSUMER_SECRET }}
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }}
BITQUERY_API_KEY: ${{ secrets.BITQUERY_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

name: Run AlgoPing
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.10.8

- name: Set up Poetry
uses: abatilo/actions-poetry@v2.1.6
with:
poetry-version: 1.4.2

- name: Install python dependencies
run: poetry install

- uses: pre-commit/action@v3.0.0
name: "Linters and formatters check"
with:
extra_args: --all-files --show-diff-on-failure

- name: Run AlgoPing Analytics
run: PYTHONPATH="." poetry run python src/analytics.py
run-algoping-analytics:
env:
BEARER_TOKEN: ${{ secrets.BEARER_TOKEN }}
CONSUMER_KEY: ${{ secrets.CONSUMER_KEY }}
CONSUMER_SECRET: ${{ secrets.CONSUMER_SECRET }}
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }}
BITQUERY_API_KEY: ${{ secrets.BITQUERY_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NOTIBOY_API_KEY: ${{ secrets.NOTIBOY_API_KEY }}
NOTIBOY_USER_ADDRESS: ${{ secrets.NOTIBOY_USER_ADDRESS }}
NOTIBOY_APP_ID: ${{ secrets.NOTIBOY_APP_ID }}

name: Run AlgoPing
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.10.8

- name: Set up Poetry
uses: abatilo/actions-poetry@v2.1.6
with:
poetry-version: 1.4.2

- name: Install python dependencies
run: poetry install

- uses: pre-commit/action@v3.0.0
name: "Linters and formatters check"
with:
extra_args: --all-files --show-diff-on-failure

- name: Run AlgoPing Analytics
run: PYTHONPATH="." poetry run python src/analytics.py
2 changes: 2 additions & 0 deletions poetry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[virtualenvs]
in-project = true
32 changes: 30 additions & 2 deletions src/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,38 @@ def to_pretty_date(date_string: str) -> str:
"min": to_pretty_value(min(all_proposer_balances)) + " ALGO",
}

tweet = f"🕰 On {to_pretty_date(start_date)} #Algorand has had {results['total_blocks']} blocks proposed and {results['total_txns']} transactions. The following address {results['biggest_proposer']} proposed the most blocks. Average of balances of all proposers is {results['average']}, the smallest proposer had {results['min']} and the biggest proposer had {results['max']}"
tweet = f"🕰 {to_pretty_date(start_date)}: #Algorand had {results['total_blocks']} blocks, {results['total_txns']} txns. Top proposer: {results['biggest_proposer']}. Avg proposer balance: {results['average']}. Smallest: {results['min']}, largest: {results['max']}" # noqa: E501"

if len(tweet) > 280:
tweet = tweet[:280] + "..."

print(tweet)
tweepy_client.create_tweet(text=str(tweet))
try:
tweepy_client.create_tweet(text=str(tweet))
except Exception as e:
print("Error tweeting: ", e)

## Send notiboy notification to algoping channel

algoping_app_id = environ.get("NOTIBOY_APP_ID")

url = f"https://app.notiboy.com/api/v1/chains/algorand/channels/{algoping_app_id}/notifications/private"

payload = {
"receivers": [],
"message": tweet,
"link": "https://twitter.com/AlgoPing",
"type": "public",
}

headers = {
"X-USER-ADDRESS": environ.get("NOTIBOY_USER_ADDRESS"),
"Authorization": f"Bearer {environ.get('NOTIBOY_API_KEY')}",
}

try:
requests.request(
"POST", url, headers=headers, data=json.dumps(payload, indent=4), verify=False
)
except Exception as e:
print("Error sending notiboy notification: ", e)

0 comments on commit 7b26d4a

Please sign in to comment.