Dockerized
This commit is contained in:
parent
bce614ac61
commit
55cf1d377c
@ -1,10 +1,10 @@
|
||||
FROM python:3-slim-bullseye
|
||||
WORKDIR /app
|
||||
COPY requirements.txt /app/requirements.txt
|
||||
COPY ./src/requirements.txt /app/requirements.txt
|
||||
RUN pip install --no-cache-dir --upgrade pip
|
||||
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
|
||||
VOLUME ["/app/notes.pickle"]
|
||||
COPY . /app
|
||||
VOLUME ["/app/data"]
|
||||
COPY ./src /app
|
||||
EXPOSE 8080
|
||||
ENV FLASK_APP=app
|
||||
CMD [ "python", "-m" , "flask", "run", "--host=0.0.0.0", "--port=8080" ]
|
20
docker-compose.yml
Normal file
20
docker-compose.yml
Normal file
@ -0,0 +1,20 @@
|
||||
version: '3'
|
||||
networks:
|
||||
traefik_traefik:
|
||||
external: true
|
||||
|
||||
services:
|
||||
sqnotes:
|
||||
build: .
|
||||
image: sqnotes
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
restart: always
|
||||
#ports:
|
||||
#- 8080:8080
|
||||
labels:
|
||||
- "traefik.http.routers.gitea.rule=Host(`notes.sq.lan`)"
|
||||
- "traefik.http.services.gitea.loadbalancer.server.port=8080"
|
||||
- "traefik.docker.network=traefik_traefik"
|
||||
networks:
|
||||
traefik_traefik:
|
BIN
src/__pycache__/app.cpython-39.pyc
Normal file
BIN
src/__pycache__/app.cpython-39.pyc
Normal file
Binary file not shown.
BIN
src/__pycache__/classes.cpython-39.pyc
Normal file
BIN
src/__pycache__/classes.cpython-39.pyc
Normal file
Binary file not shown.
BIN
src/__pycache__/funcs.cpython-39.pyc
Normal file
BIN
src/__pycache__/funcs.cpython-39.pyc
Normal file
Binary file not shown.
111
src/app.py
111
src/app.py
@ -1,122 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
#coding: utf-8
|
||||
from flask import Flask, render_template, Markup, request, redirect, url_for
|
||||
import markdown
|
||||
from classes import note
|
||||
from funcs import dumpnotes, getnotes, catnotes, delnote, findnote, addnote, mknotedir
|
||||
|
||||
#!---------- squiNotes.py ----------
|
||||
# My notes-taking app
|
||||
#-----------------------------!
|
||||
|
||||
#CLASS
|
||||
class note:
|
||||
def __init__(self, createtime: int, modtime: int, title: str, text: str):
|
||||
"""
|
||||
createtime, modtime : epoch time of note writing / modfying
|
||||
title and text are str
|
||||
"""
|
||||
self.modtime = modtime
|
||||
self.createtime = createtime
|
||||
self.title = title
|
||||
self.text = text
|
||||
|
||||
def rendertime(self, pretimestamp: int):
|
||||
"""
|
||||
Render the given timestamp as dd/mm/yyyy-hh:mm
|
||||
"""
|
||||
import datetime
|
||||
timestamp = datetime.datetime.fromtimestamp(pretimestamp)
|
||||
timestamp = timestamp.strftime("%d/%m/%Y-%H:%M:%S")
|
||||
return timestamp
|
||||
|
||||
def flaskrender(self):
|
||||
"""
|
||||
Render the note as html for flask, using flask.Markup
|
||||
"""
|
||||
rendered = f"""
|
||||
<hr>
|
||||
<div class="notetitle">{Markup.escape(self.title)}</div>
|
||||
<form action="." method="GET" name="{self.createtime}">
|
||||
<button type="submit" name="delete" value="{self.createtime}" class="delbutton">Delete</button>|<button type="submit" name="edit" value="{self.createtime}" class="editbutton">Edit</button>
|
||||
</form>
|
||||
<div class="notetime">Created : {self.rendertime(self.createtime)}
|
||||
<br>Modified : {self.rendertime(self.modtime)}</div><br>
|
||||
<div class="notetext">{markdown.markdown(self.text, extensions=['fenced_code', 'codehilite', 'nl2br', 'smarty'])}</div><br>
|
||||
"""
|
||||
return Markup(rendered)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
#FUNC
|
||||
def dumpnotes(notes):
|
||||
"""
|
||||
Get our notes list and save them as pickle to notes.pickle
|
||||
"""
|
||||
import pickle
|
||||
with open('notes.pickle', 'wb') as mpf:
|
||||
pickle.dump(notes, mpf)
|
||||
|
||||
return True
|
||||
|
||||
def getnotes():
|
||||
"""
|
||||
Get our notes from the file notes.pickle
|
||||
"""
|
||||
from os.path import exists
|
||||
import pickle
|
||||
|
||||
if exists("./notes.pickle"):
|
||||
with open('notes.pickle', 'rb') as mpf:
|
||||
notes = pickle.load(mpf)
|
||||
else:
|
||||
notes = []
|
||||
|
||||
return notes
|
||||
|
||||
def catnotes(notelist: list):
|
||||
"""
|
||||
Concatenate a list of notes into a str.
|
||||
"""
|
||||
final = ""
|
||||
for note in notelist:
|
||||
final += note.flaskrender()
|
||||
|
||||
return final
|
||||
|
||||
def delnote(timestamp: int):
|
||||
"""
|
||||
Delete note in our pickle file for which the createtime corresponds to timestamp
|
||||
"""
|
||||
notes = getnotes()
|
||||
for note in notes:
|
||||
if int(note.createtime) == int(timestamp):
|
||||
notes.remove(note)
|
||||
dumpnotes(notes)
|
||||
return True
|
||||
return False
|
||||
|
||||
def findnote(createtime: int):
|
||||
"""
|
||||
Find a note in our pickle file of notes by its createtime
|
||||
"""
|
||||
notes = getnotes()
|
||||
for note in notes:
|
||||
if note.createtime == createtime:
|
||||
return note
|
||||
|
||||
def addnote(mynote: note):
|
||||
"""
|
||||
Add a note to our notes pickle file (and sort it).
|
||||
"""
|
||||
notes = getnotes()
|
||||
notes.append(mynote)
|
||||
notes = sorted(notes, key=lambda note: note.modtime, reverse=True)
|
||||
dumpnotes(notes)
|
||||
|
||||
|
||||
|
||||
#----------! MAIN
|
||||
app = Flask(__name__)
|
||||
mknotedir()
|
||||
|
||||
@app.route('/', methods=['GET'])
|
||||
def render():
|
||||
|
49
src/classes.py
Normal file
49
src/classes.py
Normal file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
#coding: utf-8
|
||||
|
||||
#!---------- squiNotes.py ----------
|
||||
# My notes-taking app
|
||||
#-----------------------------!
|
||||
|
||||
#CLASS
|
||||
class note:
|
||||
def __init__(self, createtime: int, modtime: int, title: str, text: str):
|
||||
"""
|
||||
createtime, modtime : epoch time of note writing / modfying
|
||||
title and text are str
|
||||
"""
|
||||
self.modtime = modtime
|
||||
self.createtime = createtime
|
||||
self.title = title
|
||||
self.text = text
|
||||
|
||||
def rendertime(self, pretimestamp: int):
|
||||
"""
|
||||
Render the given timestamp as dd/mm/yyyy-hh:mm
|
||||
"""
|
||||
import datetime
|
||||
timestamp = datetime.datetime.fromtimestamp(pretimestamp)
|
||||
timestamp = timestamp.strftime("%d/%m/%Y-%H:%M:%S")
|
||||
return timestamp
|
||||
|
||||
def flaskrender(self):
|
||||
"""
|
||||
Render the note as html for flask, using flask.Markup
|
||||
"""
|
||||
import markdown
|
||||
from flask import Markup
|
||||
|
||||
rendered = f"""
|
||||
<hr>
|
||||
<div class="notetitle">{Markup.escape(self.title)}</div>
|
||||
<form action="." method="GET" name="{self.createtime}">
|
||||
<button type="submit" name="delete" value="{self.createtime}" class="delbutton">Delete</button>|<button type="submit" name="edit" value="{self.createtime}" class="editbutton">Edit</button>
|
||||
</form>
|
||||
<div class="notetime">Created : {self.rendertime(self.createtime)}
|
||||
<br>Modified : {self.rendertime(self.modtime)}</div><br>
|
||||
<div class="notetext">{markdown.markdown(self.text, extensions=['fenced_code', 'codehilite', 'nl2br', 'smarty'])}</div><br>
|
||||
"""
|
||||
return Markup(rendered)
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
78
src/funcs.py
Normal file
78
src/funcs.py
Normal file
@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python3
|
||||
#coding: utf-8
|
||||
from classes import note
|
||||
|
||||
def mknotedir():
|
||||
"""
|
||||
Create our data directory if does not exist.
|
||||
"""
|
||||
from os.path import exists
|
||||
from os import mkdir
|
||||
|
||||
if not exists("./data"):
|
||||
mkdir("./data")
|
||||
|
||||
def dumpnotes(notes):
|
||||
"""
|
||||
Get our notes list and save them as pickle to notes.pickle
|
||||
"""
|
||||
import pickle
|
||||
with open('./data/notes.pickle', 'wb') as mpf:
|
||||
pickle.dump(notes, mpf)
|
||||
|
||||
return True
|
||||
|
||||
def getnotes():
|
||||
"""
|
||||
Get our notes from the file notes.pickle
|
||||
"""
|
||||
from os.path import exists
|
||||
import pickle
|
||||
|
||||
if exists("./data/notes.pickle"):
|
||||
with open('./data/notes.pickle', 'rb') as mpf:
|
||||
notes = pickle.load(mpf)
|
||||
else:
|
||||
notes = []
|
||||
|
||||
return notes
|
||||
|
||||
def catnotes(notelist: list):
|
||||
"""
|
||||
Concatenate a list of notes into a str.
|
||||
"""
|
||||
final = ""
|
||||
for note in notelist:
|
||||
final += note.flaskrender()
|
||||
|
||||
return final
|
||||
|
||||
def delnote(timestamp: int):
|
||||
"""
|
||||
Delete note in our pickle file for which the createtime corresponds to timestamp
|
||||
"""
|
||||
notes = getnotes()
|
||||
for note in notes:
|
||||
if int(note.createtime) == int(timestamp):
|
||||
notes.remove(note)
|
||||
dumpnotes(notes)
|
||||
return True
|
||||
return False
|
||||
|
||||
def findnote(createtime: int):
|
||||
"""
|
||||
Find a note in our pickle file of notes by its createtime
|
||||
"""
|
||||
notes = getnotes()
|
||||
for note in notes:
|
||||
if note.createtime == createtime:
|
||||
return note
|
||||
|
||||
def addnote(mynote: note):
|
||||
"""
|
||||
Add a note to our notes pickle file (and sort it).
|
||||
"""
|
||||
notes = getnotes()
|
||||
notes.append(mynote)
|
||||
notes = sorted(notes, key=lambda note: note.modtime, reverse=True)
|
||||
dumpnotes(notes)
|
BIN
src/notes.pickle
BIN
src/notes.pickle
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user