-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.py
43 lines (32 loc) · 1.03 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os.path
from urllib.request import Request
from tortoise.contrib.sanic import register_tortoise
from sanic import Sanic, response
import env_util
from api import scrape, settings
from models.models import Task
app = Sanic("MyHelloWorldApp")
app.update_config({
'KEEP_ALIVE': False,
'CORS_ORIGINS': ["*"],
})
register_tortoise(
app, db_url=f"sqlite://{os.path.join(env_util.config_path, 'scrapelib.db')}", modules={"models": ["models.models"]},
generate_schemas=False
)
app.static("/static", "./static")
app.add_route(settings.settings_list, "/settings", methods=["GET"])
app.add_route(settings.save_settings, "/settings", methods=["POST"])
# app.add_route(get_tasks, "/gettasks", methods=["GET"])
#
@app.before_server_stop
async def on_close(*_):
print("111111")
scrape.map_router(app)
@app.get("/")
async def handler(request: Request):
return {"title": "1111111"}
@app.route("/list")
async def list_all(request):
tasks = await Task.all()
return response.json({"tasks": [str(tasks) for user in tasks]})