Skip to content

Commit

Permalink
Merge pull request #33 from Casvt/Development
Browse files Browse the repository at this point in the history
V1.1.0
  • Loading branch information
Casvt authored Jan 28, 2023
2 parents d1d39a9 + 22c22a3 commit 8d29433
Show file tree
Hide file tree
Showing 15 changed files with 517 additions and 67 deletions.
153 changes: 153 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Database
*.db

# VS code
*.code-workspace
.vscode/

# Docker
Dockerfile
.dockerignore
docker-compose.yml

# Git(hub)
.gitignore
.git/
.github/

# Various files
*.md
LICENSE

# Tests
tests/
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,3 @@ dmypy.json

# VS code
*.code-workspace

# Docker
Dockerfile
.dockerignore
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# syntax=docker/dockerfile:1

FROM python:3.8-slim-buster

WORKDIR /app

COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt

COPY . .

CMD [ "python3", "/app/Noted.py" ]
18 changes: 16 additions & 2 deletions backend/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from flask import g

__DATABASE_VERSION__ = 2
__DATABASE_VERSION__ = 3

class Singleton(type):
_instances = {}
Expand Down Expand Up @@ -79,7 +79,17 @@ def migrate_db(current_db_version: int) -> None:
for reminder in reminders:
new_reminders_append([round((datetime.fromtimestamp(reminder[0]) - utc_offset).timestamp()), reminder[1]])
cursor.executemany("UPDATE reminders SET time = ? WHERE id = ?;", new_reminders)
__DATABASE_VERSION__ = 2
current_db_version = 2

if current_db_version == 2:
# V2 -> V3
cursor.executescript("""
ALTER TABLE reminders
ADD color VARCHAR(7);
ALTER TABLE templates
ADD color VARCHAR(7);
""")
current_db_version = 3

return

Expand Down Expand Up @@ -115,6 +125,8 @@ def setup_db() -> None:
repeat_interval INTEGER,
original_time INTEGER,
color VARCHAR(7),
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (notification_service) REFERENCES notification_services(id)
);
Expand All @@ -125,6 +137,8 @@ def setup_db() -> None:
text TEXT,
notification_service INTEGER NOT NULL,
color VARCHAR(7),
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (notification_service) REFERENCES notification_services(id)
);
Expand Down
64 changes: 49 additions & 15 deletions backend/reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ def get(self) -> dict:
r.notification_service,
ns.title AS notification_service_title,
r.repeat_quantity,
r.repeat_interval
r.repeat_interval,
r.color
FROM
reminders r
INNER JOIN notification_services ns
Expand All @@ -176,7 +177,8 @@ def update(
notification_service: int = None,
text: str = None,
repeat_quantity: Literal["year", "month", "week", "day", "hours", "minutes"] = None,
repeat_interval: int = None
repeat_interval: int = None,
color: str = None
) -> dict:
"""Edit the reminder
Expand All @@ -185,6 +187,9 @@ def update(
time (int): The new UTC epoch timestamp the the reminder should be send. Defaults to None.
notification_service (int): The new id of the notification service to use to send the reminder. Defaults to None.
text (str, optional): The new body of the reminder. Defaults to None.
repeat_quantity (Literal["year", "month", "week", "day", "hours", "minutes"], optional): The new quantity of the repeat specified for the reminder. Defaults to None.
repeat_interval (int, optional): The new amount of repeat_quantity, like "5" (hours). Defaults to None.
color (str, optional): The new hex code of the color of the reminder, which is shown in the web-ui. Defaults to None.
Returns:
dict: The new reminder info
Expand Down Expand Up @@ -212,10 +217,11 @@ def update(
'notification_service': notification_service,
'text': text,
'repeat_quantity': repeat_quantity,
'repeat_interval': repeat_interval
'repeat_interval': repeat_interval,
'color': color
}
for k, v in new_values.items():
if k in ('repeat_quantity', 'repeat_interval') or v is not None:
if k in ('repeat_quantity', 'repeat_interval', 'color') or v is not None:
data[k] = v

# Update database
Expand All @@ -224,7 +230,7 @@ def update(
next_time = data["time"]
cursor.execute("""
UPDATE reminders
SET title=?, text=?, time=?, notification_service=?, repeat_quantity=?, repeat_interval=?
SET title=?, text=?, time=?, notification_service=?, repeat_quantity=?, repeat_interval=?, color=?
WHERE id = ?;
""", (
data["title"],
Expand All @@ -233,13 +239,14 @@ def update(
data["notification_service"],
data["repeat_quantity"],
data["repeat_interval"],
data["color"],
self.id
))
else:
next_time = _find_next_time(data["time"], data["repeat_quantity"], data["repeat_interval"])
cursor.execute("""
UPDATE reminders
SET title=?, text=?, time=?, notification_service=?, repeat_quantity=?, repeat_interval=?, original_time=?
SET title=?, text=?, time=?, notification_service=?, repeat_quantity=?, repeat_interval=?, original_time=?, color=?
WHERE id = ?;
""", (
data["title"],
Expand All @@ -249,6 +256,7 @@ def update(
data["repeat_quantity"],
data["repeat_interval"],
data["time"],
data["color"],
self.id
))
except IntegrityError:
Expand Down Expand Up @@ -284,7 +292,7 @@ def fetchall(self, sort_by: Literal["time", "time_reversed", "title", "title_rev
sort_by (Literal["time", "time_reversed", "title", "title_reversed"], optional): How to sort the result. Defaults to "time".
Returns:
List[dict]: The id, title, text, time, notification_service and notification_service_title of each reminder
List[dict]: The id, title, text, time, notification_service, notification_service_title and color of each reminder
"""
sort_function = self.sort_functions.get(
sort_by,
Expand All @@ -300,7 +308,8 @@ def fetchall(self, sort_by: Literal["time", "time_reversed", "title", "title_rev
r.notification_service,
ns.title AS notification_service_title,
r.repeat_quantity,
r.repeat_interval
r.repeat_interval,
r.color
FROM
reminders r
INNER JOIN notification_services ns
Expand Down Expand Up @@ -350,7 +359,8 @@ def add(
notification_service: int,
text: str = '',
repeat_quantity: Literal["year", "month", "week", "day", "hours", "minutes"] = None,
repeat_interval: int = None
repeat_interval: int = None,
color: str = None
) -> Reminder:
"""Add a reminder
Expand All @@ -361,6 +371,7 @@ def add(
text (str, optional): The body of the reminder. Defaults to ''.
repeat_quantity (Literal["year", "month", "week", "day", "hours", "minutes"], optional): The quantity of the repeat specified for the reminder. Defaults to None.
repeat_interval (int, optional): The amount of repeat_quantity, like "5" (hours). Defaults to None.
color (str, optional): The hex code of the color of the reminder, which is shown in the web-ui. Defaults to None.
Returns:
dict: The info about the reminder
Expand All @@ -377,19 +388,42 @@ def add(
try:
if repeat_quantity is None and repeat_interval is None:
id = get_db().execute("""
INSERT INTO reminders(user_id, title, text, time, notification_service)
VALUES (?,?,?,?,?);
""", (self.user_id, title, text, time, notification_service)
INSERT INTO reminders(user_id, title, text, time, notification_service, color)
VALUES (?,?,?,?,?, ?);
""", (self.user_id, title, text, time, notification_service, color)
).lastrowid
else:
id = get_db().execute("""
INSERT INTO reminders(user_id, title, text, time, notification_service, repeat_quantity, repeat_interval, original_time)
VALUES (?, ?, ?, ?, ?, ?, ?, ?);
""", (self.user_id, title, text, time, notification_service, repeat_quantity, repeat_interval, time)
INSERT INTO reminders(user_id, title, text, time, notification_service, repeat_quantity, repeat_interval, original_time, color)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);
""", (self.user_id, title, text, time, notification_service, repeat_quantity, repeat_interval, time, color)
).lastrowid
except IntegrityError:
raise NotificationServiceNotFound
reminder_handler.submit_next_reminder(time)

# Return info
return self.fetchone(id)

def test_reminder(
title: str,
notification_service: int,
text: str = ''
) -> None:
"""Test send a reminder draft
Args:
title (str): Title title of the entry
notification_service (int): The id of the notification service to use to send the reminder
text (str, optional): The body of the reminder. Defaults to ''.
"""
a = Apprise()
url = get_db(dict).execute(
"SELECT url FROM notification_services WHERE id = ?",
(notification_service,)
).fetchone()
if not url:
raise NotificationServiceNotFound
a.add(url[0])
a.notify(title=title, body=text)
return
Loading

0 comments on commit 8d29433

Please sign in to comment.