Alter 4 files
Update `.gitignore` Update `__main__.py` Add `db.py` Add `endpoints.py`
This commit is contained in:
parent
6b3ca4248f
commit
f75dde9ac7
4 changed files with 30 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
duckpond.db
|
||||
|
||||
### Python ###
|
||||
# Byte-compiled / optimized / DLL files
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
import flask
|
||||
|
||||
import db
|
||||
import endpoints
|
||||
|
||||
|
||||
__version__ = '0.1.0'
|
||||
|
||||
|
||||
def main():
|
||||
app = flask.Flask(__name__)
|
||||
app.add_url_rule("/", view_func=index)
|
||||
|
||||
database = db.DB("duckpond.db")
|
||||
_ = endpoints.Endpoints(app, database)
|
||||
|
||||
app.run(port=8080, debug=True, host="127.0.0.1")
|
||||
|
||||
|
||||
def index():
|
||||
return "<h2>Hello world!</h2>"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
8
backend/duckpond/db.py
Normal file
8
backend/duckpond/db.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
import sqlite3
|
||||
|
||||
class DB:
|
||||
conn: sqlite3.Connection
|
||||
|
||||
def __init__(self, filename: str):
|
||||
self.conn = sqlite3.connect(filename)
|
||||
|
14
backend/duckpond/endpoints.py
Normal file
14
backend/duckpond/endpoints.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
import flask
|
||||
|
||||
import db
|
||||
|
||||
class Endpoints:
|
||||
db: db.DB
|
||||
|
||||
def __init__(self, app: flask.Flask, database: db.DB):
|
||||
self.db = database
|
||||
|
||||
app.add_url_rule("/", view_func=self.index)
|
||||
|
||||
def index(self):
|
||||
return "<h2>Hello world</h2>"
|
Reference in a new issue