~arcade/notification-center

7ca9e2f56cd073c80f77f03e4c1456fc79229fc3 — arcade 2 months ago 684776f
codeee
10 files changed, 63 insertions(+), 19 deletions(-)

M .gitignore
A README.md
A TODO
M macCapture/notif_upload.sh
A macCapture/runAll.sh
M main.py
R mastodon/{test.py => mast.py}
D reader/test.sh
M webend/main.py
M webend/views/index.html
M .gitignore => .gitignore +2 -1
@@ 1,2 1,3 @@
*.json
__pycache__
\ No newline at end of file
__pycache__
log.*

A README.md => README.md +12 -0
@@ 0,0 1,12 @@
# notification-center
Welcome to notification center! This is a system I use to store all of my notifications from multiple different sources.

## Anatomy:
- `macCapture/`: the tools for capturing on mac.
- `mastodon/`: grab the data from mastodon.
- `reader/`: reader in ANSI C.
- `webend/`: A web-based front-end in C.
- `main.py`: The main server that servers the notifications.

## run:
`poetry run python <name of file>`

A TODO => TODO +1 -0
@@ 0,0 1,1 @@
[ ] Change clear from delete to just a little tag on the entry, so that we can dedup for deletec
\ No newline at end of file

M macCapture/notif_upload.sh => macCapture/notif_upload.sh +3 -2
@@ 1,7 1,8 @@
#!/bin/bash
export PATH="/opt/homebrew/bin:/usr/sbin:$PATH"
DATABASE_PATH=$(lsof -p $(ps aux | grep -m1 usernoted | awk '{ print $2 }')| awk '{ print $NF }' | grep 'db2/db$' | xargs dirname)/db
API_URL="http://localhost:8080"
OUT_PATH="$(pwd)/data.json"
OUT_PATH="/Users/arc/projects/notification-center/macCapture/data.json"
AUTH_TOKEN="HIII"

python3 -c "import biplist"


@@ 17,7 18,7 @@ if [[ $? != 0 ]]; then
fi

rm $OUT_PATH
python3 capture.py $DATABASE_PATH $OUT_PATH > /dev/null 2>&1
python3 /Users/arc/projects/notification-center/macCapture/capture.py $DATABASE_PATH $OUT_PATH 

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


A macCapture/runAll.sh => macCapture/runAll.sh +10 -0
@@ 0,0 1,10 @@
#! /bin/bash

#add homebrew to path
export PATH="/opt/homebrew/bin:/usr/sbin:$PATH"

/Users/arc/projects/notification-center/macCapture/notif_upload.sh

sleep 5

cd /Users/arc/projects/notification-center/mastodon/ && poetry install &&poetry run python mast.py
\ No newline at end of file

M main.py => main.py +1 -1
@@ 41,4 41,4 @@ def clear_notificatin():
    return ""

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

R mastodon/test.py => mastodon/mast.py +14 -3
@@ 17,11 17,22 @@ latest = api.notifications()[0]

match latest['type']:
    case 'follow':
        print("someone followed you")
        tim = latest['created_at']
        notif = {
            "date": time.mktime(tim.timetuple()),
            "app": "mastodon",
            "notification": {
                "title": "@{} followed you.".format(latest['account']['acct']),
                "message": "Yay! Go say hi."
            }
        }
        # pprint(latest)
        requests.post(url, json=notif) 

    case 'favourite':
        tim = latest['status']['created_at']
        notif = {
            "date": str(tim),
            "date": time.mktime(tim.timetuple()),
            "app": "mastodon",
            "notification": {
                "title": "@{} favorited your toot.".format(latest['account']['acct']),


@@ 38,7 49,7 @@ match latest['type']:
        tim = latest['status']['created_at']
        # print("{} - @{}: \"{}\"".format(time.mktime(tim.timetuple()), , markdownify(latest['status']['content']).strip()))
        notif = {
            "date": str(tim),
            "date": time.mktime(tim.timetuple()),
            "app": "mastodon",
            "notification": {
                "title": "@{} mentioned you.".format(latest['account']['acct']),

D reader/test.sh => reader/test.sh +0 -6
@@ 1,6 0,0 @@
#!/bin/bash

NOTIFS=$(curl -s localhost:8080/notifications)
LATEST=$(echo $NOTIFS | jq .[-1])

echo "At: $(echo $LATEST | jq .date) $(echo $LATEST | jq .notification.message) from @$(echo $LATEST | jq .machine):$(echo $LATEST | jq .app)"
\ No newline at end of file

M webend/main.py => webend/main.py +11 -5
@@ 1,12 1,18 @@
from bottle import route, run, template
from bottle import route, run, template, redirect
from requests import get

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

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

@route("/clear")
def clear():
    get(URL + "clear")
    return redirect("/")

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

M webend/views/index.html => webend/views/index.html +9 -1
@@ 1,5 1,6 @@
<!DOCTYPE html>
<head>
    <meta http-equiv="refresh" content="5">
<style>
    .notif {
        border-color: black;


@@ 11,6 12,10 @@
    body {
        margin: 1rem;
    }
    right {
        align-self: right;
        float: right;
    }
</style>
</head>



@@ 18,11 23,14 @@
    <h1>Notifications</h1>
    % for notif in posts:
        <div class = "notif">
         <p>date: {{ notif['date'] }}</p>
         <p>date: {{ notif['date'] }} <right>from: {{ notif['app'] + "@" + notif['machine'] }} </right></p>
         <h2>{{ notif['notification']['title'] }}</h2>
         <p>
            {{ notif['notification']['message'] }}
         </p>
        </div>
    % end

    <br>
    <a href="/clear">Clear</a>
</body>
\ No newline at end of file