From 5e2fc16cc39b50326ad423f1aeaa5fafab5682fa Mon Sep 17 00:00:00 2001 From: Djalim Simaila Date: Fri, 20 Oct 2023 16:46:28 +0200 Subject: [PATCH] initial commit --- .gitignore | 2 ++ README.md | 0 client.py | 0 notification.py | 7 ++----- serveur.py | 36 ++++++++++++++++++++---------------- 5 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 .gitignore mode change 100644 => 100755 README.md mode change 100644 => 100755 client.py mode change 100644 => 100755 notification.py mode change 100644 => 100755 serveur.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ee307ee --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*__pycache +.vscode diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/client.py b/client.py old mode 100644 new mode 100755 diff --git a/notification.py b/notification.py old mode 100644 new mode 100755 index 0509372..5c1b7e0 --- a/notification.py +++ b/notification.py @@ -34,11 +34,8 @@ class Notification: :param content str: This is a multi-line body of text. Each line is a paragraph, server implementations are free to word wrap them as they see fit. - The body mayfrom gi.repository import GLib -import dbus -from dbus.mainloop.glib import DBusGMainLoop - functionality may not be implemented by the notification - server, conforming clients should check if it is available before using + The body functionality may not be implemented by the notification + server, conforming clients should check if it is available before usings it (see the GetCapabilities message in Protocol). An implementation is free to ignore any requested by the client. As an example one possible rendering of actions would be as buttons in the notification popup. diff --git a/serveur.py b/serveur.py old mode 100644 new mode 100755 index aecb7bf..860fc21 --- a/serveur.py +++ b/serveur.py @@ -1,4 +1,5 @@ #!/bin/python +import hashlib import sqlite3 import secrets import time @@ -11,7 +12,6 @@ socketio = flask_socketio.SocketIO(app) ############################################################################### - def first_run(): """ create databases @@ -135,14 +135,14 @@ def get_notifications(): token = request.values.get("token") con = sqlite3.connect("database.db") cur = con.cursor() - notifications = cur.execute("SELECT title,content \ + notifications = cur.execute("SELECT * \ FROM NOTIFICATION \ WHERE token=?", (token, )).fetchall() data = {"status": "ok"} data["notifications"] = [] for notification in notifications: - data["notifications"].append({"title": notification[0],"content": notification[1]}) + data["notifications"].append() return data, 200 @@ -158,26 +158,31 @@ def get_notification_by_id(notifid): con = sqlite3.connect("database.db") cur = con.cursor() if notifid == -1: - notifications = cur.execute("SELECT title,content \ + notifications = cur.execute("SELECT * \ FROM NOTIFICATION \ WHERE token=?\ ORDER BY id DESC \ LIMIT 1", (token,)).fetchone() else: - notifications = cur.execute("SELECT title,content \ + notifications = cur.execute("SELECT * \ FROM NOTIFICATION \ WHERE token=? AND id=?", (token, notifid)).fetchone() return {"status": "ok", - "notifications": {"title": notifications[0], - "content": notifications[1] - } + "notifications": notifications }, 200 ############################################################################### +def clipFromArray(clip): + return {"id": clip[0], + "timestamp": clip[1], + "deviceName": clip[2], + "token": clip[3], + "content": clip[3]} + @app.route("/clipboard", methods=['PUT']) def add_clipboard(): @@ -217,11 +222,11 @@ def get_clipboard(): token = request.values.get("token") con = sqlite3.connect("database.db") cur = con.cursor() - clipboard = cur.execute("SELECT content \ + clipboard = cur.execute("SELECT * \ FROM CLIPBOARD \ - WHERE token=?", + WHERE token=?", (token, )).fetchall() - + clipboard = [clipFromArray(clip) for clip in clipboard] return {"status": "ok", "clipboard": clipboard}, 200 @@ -237,19 +242,18 @@ def get_clipboard_by_id(clipid): con = sqlite3.connect("database.db") cur = con.cursor() if clipid == -1: - clipboard = cur.execute("SELECT content \ + clipboard = cur.execute("SELECT * \ FROM CLIPBOARD \ WHERE token=? \ ORDER BY id DESC \ LIMIT 1", (token,)).fetchone() else: - clipboard = cur.execute("SELECT content \ + clipboard = cur.execute("SELECT * \ FROM CLIPBOARD \ - token=? AND id=?", + WHERE token=? AND id=?", (token, clipid)).fetchone() - - return {"status": "ok", "clipboard": clipboard[0]}, 200 + return {"status": "ok", "clipboard": clipFromArray(clipboard)}, 200 if __name__ == '__main__':