Skip to content

Commit

Permalink
feat: Add cross platform notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Dec 2, 2024
1 parent dab39ce commit d22bf9d
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 13 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: "AoC Notifier Builds"
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- os: ubuntu-latest
artifact-name: AoC-notifier-linux
file-separator: "/"
- os: windows-latest
artifact-name: AoC-notifier-windows
file-separator: "\\"
- os: macos-latest
artifact-name: AoC-notifier-macos
file-separator: "/"

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: "3.12"

- name: Install requirements
run: |
cd notifier
python -m pip install --upgrade pip
python -m pip install .
python -m pip install pyinstaller
- name: Build notifier (Windows)
if: runner.os == 'Windows'
run: |
cd notifier
pyinstaller -F -w -i "aoc.ico" --clean -n "AoC" --add-data "aoc.ico;." --add-data "aoc.png;." app.py
- name: Build notifier (macOS/Linux)
if: runner.os != 'Windows'
run: |
cd notifier
pyinstaller -F -w -i "aoc.ico" --clean -n "AoC" --add-data "aoc.ico:." --add-data "aoc.png:." app.py
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact-name }}
path: "notifier/dist/"
2 changes: 1 addition & 1 deletion notifier/AoC.spec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ a = Analysis(
['app.py'],
pathex=[],
binaries=[],
datas=[('aoc.png', '.')],
datas=[('aoc.ico', '.'), ('aoc.png', '.')],
hiddenimports=[],
hookspath=[],
hooksconfig={},
Expand Down
40 changes: 28 additions & 12 deletions notifier/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,43 @@
"""

import datetime
import platform
import time
from pathlib import Path

import pytz
from win11toast import toast

EST_TZ = pytz.timezone("US/Eastern")
if platform.system() == "Windows":
from win11toast import toast
else:
from plyer import notification

toast = notification.notify

EST_TZ = pytz.timezone("US/Eastern")
image = str(Path("aoc.png").absolute())


def notify(current_time_est: datetime.datetime):
toast(
"Time for Advent of Code 🎄!",
"Open day {} challenge".format(current_time_est.day),
icon=image,
on_click="https://adventofcode.com/{}/day/{}".format(
current_time_est.year, current_time_est.day
),
audio="ms-winsoundevent:Notification.Looping.Call7",
)
if platform.system() == "Windows":
toast(
"Time for Advent of Code 🎄!",
"Open day {} challenge".format(current_time_est.day),
icon=image,
on_click="https://adventofcode.com/{}/day/{}".format(
current_time_est.year, current_time_est.day
),
audio="ms-winsoundevent:Notification.Looping.Call7",
)
else:
toast(
title="Time for Advent of Code 🎄",
message="Day {} challenge is out now!".format(current_time_est.day),
app_name="AoC",
app_icon=str(Path("aoc.ico").absolute()),
timeout=10,
ticker="AoC",
)


def main():
Expand All @@ -50,4 +66,4 @@ def main():
main()


# pyinstaller -F -w -i "aoc.ico" --clean -n "AoC" --add-data "aoc.png;." app.py
# pyinstaller -F -w -i "aoc.ico" --clean -n "AoC" --add-data "aoc.ico;." --add-data "aoc.png;." app.py
17 changes: 17 additions & 0 deletions notifier/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
name = "aoc-notifier"
version = "0.1.0"
description = ""
authors = ["Billy <[email protected]>"]
license = "MIT"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
plyer = "^2.1.0"
win11toast = { version = "^0.35", platform = "win32" }
pytz = "^2024.2"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

0 comments on commit d22bf9d

Please sign in to comment.