~arcade/notification-center

684776fd7c11d38a64b4d9c18ae7ea92bc9db93c — arcade 2 months ago 9103820
whole lotta stuff
M .gitignore => .gitignore +2 -1
@@ 1,1 1,2 @@
*.json
\ No newline at end of file
*.json
__pycache__
\ No newline at end of file

A dedupMiddleware.py => dedupMiddleware.py +32 -0
@@ 0,0 1,32 @@
# this is a tinydb middleware that will de duplicate a database

from tinydb.middlewares import Middleware

class DeDupMiddleware(Middleware):
    def __init__(self, storage_cls):
        # Any middleware *has* to call the super constructor
        # with storage_cls
        super().__init__(storage_cls)  # (1)

    def read(self):
        data = self.storage.read()

        return data

    def write(self, data):
        for table_name in data:
            table_data = data[table_name]

            res = {}

            for key, value in table_data.items():
                if value not in res.values():
                    res[key] = value
            
            data[table_name] = res
            print(res)

        self.storage.write(data)

    def close(self):
        self.storage.close()

M macCapture/notif_upload.sh => macCapture/notif_upload.sh +2 -0
@@ 21,4 21,6 @@ python3 capture.py $DATABASE_PATH $OUT_PATH > /dev/null 2>&1

latest_notification=$( cat $OUT_PATH | tail -n 2 | head -n 1 )

# echo $latest_notification

curl -s -XPOST -H "Authorization: Bearer $AUTH_TOKEN" -d "$latest_notification" "$API_URL/machine/mac/" | jq .
\ No newline at end of file

M main.py => main.py +4 -1
@@ 1,10 1,13 @@
from bottle import request, run, post, get
from tinydb import TinyDB, Query
from tinydb.storages import JSONStorage
from json import load, dumps
from datetime import datetime
from time import mktime
from dedupMiddleware import DeDupMiddleware

db = TinyDB("notifications.json")

db = TinyDB("notifications.json", storage=DeDupMiddleware(JSONStorage))
Notification = Query()

mutedApps = [

A mastodon/.gitignore => mastodon/.gitignore +1 -0
@@ 0,0 1,1 @@
*.secret
\ No newline at end of file

A mastodon/poetry.lock => mastodon/poetry.lock +235 -0
@@ 0,0 1,235 @@
[[package]]
name = "beautifulsoup4"
version = "4.11.1"
description = "Screen-scraping library"
category = "main"
optional = false
python-versions = ">=3.6.0"

[package.dependencies]
soupsieve = ">1.2"

[package.extras]
html5lib = ["html5lib"]
lxml = ["lxml"]

[[package]]
name = "blurhash"
version = "1.1.4"
description = "Pure-Python implementation of the blurhash algorithm."
category = "main"
optional = false
python-versions = "*"

[package.extras]
test = ["pillow", "numpy", "pytest"]

[[package]]
name = "certifi"
version = "2021.10.8"
description = "Python package for providing Mozilla's CA Bundle."
category = "main"
optional = false
python-versions = "*"

[[package]]
name = "charset-normalizer"
version = "2.0.12"
description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet."
category = "main"
optional = false
python-versions = ">=3.5.0"

[package.extras]
unicode_backport = ["unicodedata2"]

[[package]]
name = "decorator"
version = "5.1.1"
description = "Decorators for Humans"
category = "main"
optional = false
python-versions = ">=3.5"

[[package]]
name = "idna"
version = "3.3"
description = "Internationalized Domain Names in Applications (IDNA)"
category = "main"
optional = false
python-versions = ">=3.5"

[[package]]
name = "markdownify"
version = "0.11.2"
description = "Convert HTML to markdown."
category = "main"
optional = false
python-versions = "*"

[package.dependencies]
beautifulsoup4 = ">=4.9,<5"
six = ">=1.15,<2"

[[package]]
name = "mastodon.py"
version = "1.5.1"
description = "Python wrapper for the Mastodon API"
category = "main"
optional = false
python-versions = "*"

[package.dependencies]
blurhash = ">=1.1.4"
decorator = ">=4.0.0"
python-dateutil = "*"
python-magic = "*"
pytz = "*"
requests = ">=2.4.2"
six = "*"

[package.extras]
blurhash = ["blurhash (>=1.1.4)"]
test = ["blurhash (>=1.1.4)", "cryptography (>=1.6.0)", "http-ece (>=1.0.5)", "pytest", "pytest-cov", "pytest-mock", "pytest-runner", "pytest-vcr", "requests-mock", "vcrpy"]
webpush = ["cryptography (>=1.6.0)", "http-ece (>=1.0.5)"]

[[package]]
name = "python-dateutil"
version = "2.8.2"
description = "Extensions to the standard Python datetime module"
category = "main"
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7"

[package.dependencies]
six = ">=1.5"

[[package]]
name = "python-magic"
version = "0.4.25"
description = "File type identification using libmagic"
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"

[[package]]
name = "pytz"
version = "2022.1"
description = "World timezone definitions, modern and historical"
category = "main"
optional = false
python-versions = "*"

[[package]]
name = "requests"
version = "2.27.1"
description = "Python HTTP for Humans."
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*"

[package.dependencies]
certifi = ">=2017.4.17"
charset-normalizer = {version = ">=2.0.0,<2.1.0", markers = "python_version >= \"3\""}
idna = {version = ">=2.5,<4", markers = "python_version >= \"3\""}
urllib3 = ">=1.21.1,<1.27"

[package.extras]
socks = ["PySocks (>=1.5.6,!=1.5.7)", "win-inet-pton"]
use_chardet_on_py3 = ["chardet (>=3.0.2,<5)"]

[[package]]
name = "six"
version = "1.16.0"
description = "Python 2 and 3 compatibility utilities"
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"

[[package]]
name = "soupsieve"
version = "2.3.2.post1"
description = "A modern CSS selector implementation for Beautiful Soup."
category = "main"
optional = false
python-versions = ">=3.6"

[[package]]
name = "urllib3"
version = "1.26.9"
description = "HTTP library with thread-safe connection pooling, file post, and more."
category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4"

[package.extras]
brotli = ["brotlicffi (>=0.8.0)", "brotli (>=1.0.9)", "brotlipy (>=0.6.0)"]
secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "ipaddress"]
socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"]

[metadata]
lock-version = "1.1"
python-versions = "^3.10"
content-hash = "c6eff4154744634d08a6d27761ac9f010acc637ab063000170beeaa8765101fa"

[metadata.files]
beautifulsoup4 = [
    {file = "beautifulsoup4-4.11.1-py3-none-any.whl", hash = "sha256:58d5c3d29f5a36ffeb94f02f0d786cd53014cf9b3b3951d42e0080d8a9498d30"},
    {file = "beautifulsoup4-4.11.1.tar.gz", hash = "sha256:ad9aa55b65ef2808eb405f46cf74df7fcb7044d5cbc26487f96eb2ef2e436693"},
]
blurhash = [
    {file = "blurhash-1.1.4-py2.py3-none-any.whl", hash = "sha256:7611c1bc41383d2349b6129208587b5d61e8792ce953893cb49c38beeb400d1d"},
    {file = "blurhash-1.1.4.tar.gz", hash = "sha256:da56b163e5a816e4ad07172f5639287698e09d7f3dc38d18d9726d9c1dbc4cee"},
]
certifi = [
    {file = "certifi-2021.10.8-py2.py3-none-any.whl", hash = "sha256:d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569"},
    {file = "certifi-2021.10.8.tar.gz", hash = "sha256:78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872"},
]
charset-normalizer = [
    {file = "charset-normalizer-2.0.12.tar.gz", hash = "sha256:2857e29ff0d34db842cd7ca3230549d1a697f96ee6d3fb071cfa6c7393832597"},
    {file = "charset_normalizer-2.0.12-py3-none-any.whl", hash = "sha256:6881edbebdb17b39b4eaaa821b438bf6eddffb4468cf344f09f89def34a8b1df"},
]
decorator = [
    {file = "decorator-5.1.1-py3-none-any.whl", hash = "sha256:b8c3f85900b9dc423225913c5aace94729fe1fa9763b38939a95226f02d37186"},
    {file = "decorator-5.1.1.tar.gz", hash = "sha256:637996211036b6385ef91435e4fae22989472f9d571faba8927ba8253acbc330"},
]
idna = [
    {file = "idna-3.3-py3-none-any.whl", hash = "sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff"},
    {file = "idna-3.3.tar.gz", hash = "sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"},
]
markdownify = [
    {file = "markdownify-0.11.2-py3-none-any.whl", hash = "sha256:ef396bb8d0ffb3efacc08b86ab4aa6d36b234e782aea9f6b7f980798eaa64e33"},
    {file = "markdownify-0.11.2.tar.gz", hash = "sha256:d613f95b2649d8b83c4c4cb2e6c24cea8c7df4e07d418f92fa25ad0ddbb045e0"},
]
"mastodon.py" = [
    {file = "Mastodon.py-1.5.1-py2.py3-none-any.whl", hash = "sha256:cc454cac0ed1ae4f105f7399ea53f5b31a1be5075d1882f47162d2e78a9e4064"},
    {file = "Mastodon.py-1.5.1.tar.gz", hash = "sha256:2afddbad8b5d7326fcc8a8f8c62bfe956e34627f516b06c6694fc8c8fedc33ee"},
]
python-dateutil = [
    {file = "python-dateutil-2.8.2.tar.gz", hash = "sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86"},
    {file = "python_dateutil-2.8.2-py2.py3-none-any.whl", hash = "sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9"},
]
python-magic = [
    {file = "python-magic-0.4.25.tar.gz", hash = "sha256:21f5f542aa0330f5c8a64442528542f6215c8e18d2466b399b0d9d39356d83fc"},
    {file = "python_magic-0.4.25-py2.py3-none-any.whl", hash = "sha256:1a2c81e8f395c744536369790bd75094665e9644110a6623bcc3bbea30f03973"},
]
pytz = [
    {file = "pytz-2022.1-py2.py3-none-any.whl", hash = "sha256:e68985985296d9a66a881eb3193b0906246245294a881e7c8afe623866ac6a5c"},
    {file = "pytz-2022.1.tar.gz", hash = "sha256:1e760e2fe6a8163bc0b3d9a19c4f84342afa0a2affebfaa84b01b978a02ecaa7"},
]
requests = [
    {file = "requests-2.27.1-py2.py3-none-any.whl", hash = "sha256:f22fa1e554c9ddfd16e6e41ac79759e17be9e492b3587efa038054674760e72d"},
    {file = "requests-2.27.1.tar.gz", hash = "sha256:68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61"},
]
six = [
    {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"},
    {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"},
]
soupsieve = [
    {file = "soupsieve-2.3.2.post1-py3-none-any.whl", hash = "sha256:3b2503d3c7084a42b1ebd08116e5f81aadfaea95863628c80a3b774a11b7c759"},
    {file = "soupsieve-2.3.2.post1.tar.gz", hash = "sha256:fc53893b3da2c33de295667a0e19f078c14bf86544af307354de5fcf12a3f30d"},
]
urllib3 = [
    {file = "urllib3-1.26.9-py2.py3-none-any.whl", hash = "sha256:44ece4d53fb1706f667c9bd1c648f5469a2ec925fcf3a776667042d645472c14"},
    {file = "urllib3-1.26.9.tar.gz", hash = "sha256:aabaf16477806a5e1dd19aa41f8c2b7950dd3c746362d7e3223dbe6de6ac448e"},
]

A mastodon/pyproject.toml => mastodon/pyproject.toml +17 -0
@@ 0,0 1,17 @@
[tool.poetry]
name = "mastodon"
version = "0.1.0"
description = ""
authors = ["arcade <l3gacy.b3ta@disroot.org>"]
license = "UNLICENSE"

[tool.poetry.dependencies]
python = "^3.10"
"Mastodon.py" = "^1.5.1"
markdownify = "^0.11.2"

[tool.poetry.dev-dependencies]

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

A mastodon/test.py => mastodon/test.py +71 -0
@@ 0,0 1,71 @@
from mastodon import Mastodon
import time
from markdownify import markdownify
from pprint import pprint
import requests
from json import dumps

api = Mastodon(
    access_token = 'pytooter_usercred.secret',
    api_base_url = 'https://catcatnya.com'
)

url = "http://localhost:8080/machine/catcatnya/"

latest = api.notifications()[0]
# account = latest['account']

match latest['type']:
    case 'follow':
        print("someone followed you")
    case 'favourite':
        tim = latest['status']['created_at']
        notif = {
            "date": str(tim),
            "app": "mastodon",
            "notification": {
                "title": "@{} favorited your toot.".format(latest['account']['acct']),
                "message": markdownify(latest['status']['content']).strip()
            }
        }

        # pprint(latest)
        pprint(notif)

        requests.post(url, json=notif)
    case 'mention':
        # pprint(latest)
        tim = latest['status']['created_at']
        # print("{} - @{}: \"{}\"".format(time.mktime(tim.timetuple()), , markdownify(latest['status']['content']).strip()))
        notif = {
            "date": str(tim),
            "app": "mastodon",
            "notification": {
                "title": "@{} mentioned you.".format(latest['account']['acct']),
                "message": dumps(markdownify(latest['status']['content']).strip())
            }
        }

        requests.post(url, data=dumps(notif))

        
    case _:
        print(latest["type"])


# test = {
#     "date":"2022-04-25 20:00:11.347923",
#     "app":"_web_center_:web.catcatnya.com",
#     "notification": {
#         "uuid":"", 
#         "title":"schratze mentioned you", 
#         "subtitle": "from catcatnya.com", 
#         "message": "@arcade have fun! :trebuchet: "
#         }
#     }

# text = latest['status']['content']
# typ = latest['type']

# print("\"{}\" at {} of {}".format(markdownify(text).strip(), time.mktime(tim.timetuple()), typ))
# pprint(latest)
\ No newline at end of file

A webend/main.py => webend/main.py +12 -0
@@ 0,0 1,12 @@
from bottle import route, run, template
from requests import get

URL = "http://localhost:8080/notifications"

@route("/")
def main():
    data  = get(URL)
    return template('index', posts=data.json())

if __name__ == "__main__":
    run(host='localhost', port=3000)
\ No newline at end of file

A webend/views/index.html => webend/views/index.html +28 -0
@@ 0,0 1,28 @@
<!DOCTYPE html>
<head>
<style>
    .notif {
        border-color: black;
        border-width: 1px;
        border-style: solid;
        margin: 1em;
        padding: 1em;
    }
    body {
        margin: 1rem;
    }
</style>
</head>

<body>
    <h1>Notifications</h1>
    % for notif in posts:
        <div class = "notif">
         <p>date: {{ notif['date'] }}</p>
         <h2>{{ notif['notification']['title'] }}</h2>
         <p>
            {{ notif['notification']['message'] }}
         </p>
        </div>
    % end
</body>
\ No newline at end of file